The syntax for inserting data is the same as selecting data, however for INSERT, UPDATE and DELETE commands we want to make sure the command executed.
We can do this by checking the result type and whether it return true. Like this:
$sql = "INSERT INTO myTable (field1, field2) VALUES ('value1', 'value2')"; $rs = mysql_query($sql, $linkID); if(gettype($rs)=="boolean" && $rs==TRUE) { print "Good insert"; } else { print "Bad Insert"; }
We may also want to know how many rows were affected by the last query. An insert command should always affect exactly 1 row.
To do this, we use the mysql_affected_rows($rs) command.
$sql = "INSERT INTO myTable (field1, field2) VALUES ('value1', 'value2')"; $rs = mysql_query($sql, $linkID); if(gettype($rs)=="boolean" && $rs==TRUE && mysql_affected_rows($rs)==1) { print "Good insert"; } else { print "Bad Insert"; }INDEX