Page 1 of 1

Newbie-Prob2

Posted: Thu Jul 04, 2002 9:24 am
by Thanatos
My second prob is that I have to check whether a set already exists or not, and then do an update or an insert.

How can I realize this?

Greets
Thanatos

Posted: Thu Jul 04, 2002 12:22 pm
by volka
use mysql_affected_rows to see wether data has been altered or not.

Code: Select all

mysql_query($sqlUpdate, $conn) or die(mysql_error());
if (mysql_affected_rows($conn)==0)
   // *)
   mysql_query($sqlInsert, $conn) or die(mysql_error());
*) mysql_affected_rows also returns 0 if the data is exactly the same as before. If these kinds of updates are possible you must do a 'select...' in the if-clause to check wether there are such records or not