severndigital Posted July 30, 2007 Share Posted July 30, 2007 ok i know this is a newbie question, but i can't seem to find anything about it. maybe i am searching the wrong keywords. i want to test a statement before executing it. something like this. $sql "UPDATE workers SET workerStatus = '0' WHERE workerId = '$empno'"; //I want to test this statement here. $mysqltestcommand = mysql_query($sql); //I don't know the command for this part. $check = mysql_affected_rows(); //run the check here and if it equals 1 than actually run the query. if($check != 1){ echo 'There is an error processing your request'; } else { $runquery = mysql_query($sql); echo 'Your command has been processed.'; } does that make sense?? or should i be doing this a different way?? thanks in advance, chris Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted July 31, 2007 Share Posted July 31, 2007 You can put your statement in a transaction if you are using Innodb, although this shouldn't be necessary...if you execute the command and it fails, nothing will be affected in the database anyway, then you can alert the user... $sql = "UPDATE workers SET workerStatus = '0' WHERE workerId = '$empno'"; if (mysql_query($sql)) { echo "Success"; } else { mysql_error(); } Quote Link to comment Share on other sites More sharing options...
severndigital Posted July 31, 2007 Author Share Posted July 31, 2007 understood. my concern was more that i wanted to automatically internally confirm the code before processing it. I eliminated the need for this by adding a javascript cofirm window for the user prior to running the query. another case of me wanting to make things more complicated that they need to be thanks again, chris Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.