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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.