Jump to content

[SOLVED] dumb noobie question .. i know .. test mysql statement


severndigital

Recommended Posts

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

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();
}

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.