Dear,

I am new to PHP and MySQL.
I have a simple order form on my site: 1 column with "member" and one with "comment".
I am able to Insert rows when a user submits the form.
But when a user wants to modify that data, the form inserts another row - no good.

I want the returning user, to be able to their UPDATED record - not INSERTED again.
I can detect if they have previously submitted an record to the MySQL:

if(mysql_num_rows($replacing) !== 0);
	{
           echo "You have already submitted an order, you may modify this.";

I am stuck now, please help.

Thanks in advance,

Leech

Could really do with seeing the rest of your code (especially what you are doing before the piece of code you have already posted). However, as a start, you don't need 2 equals signs and you have put a semi-colon in your if statement which is incorrect, so should be

if (mysql_num_rows($replacing)!=0) { echo........; }

or you could use greater than:

if (mysql_num_rows($replacing)>0) { echo........; }

Thanks for your reply.
I managed to get it all working now! Not sure if it is the best way:

$sql = "UPDATE table SET col1 = '$var1', col2 = '$var2' WHERE `user` ='username1' " or die("We have encountered an error:" . mysql_error());

The variables are the $_POST that are sent from a form to the database.

I had a look at this site, but did not make any sense to me: (might be helpful for others)
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

Also this is very helpful to my solution:
http://phpeasystep.com/mysql/9.html

Thanks to all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.