Jump to content

A 2 part query error!


will_1990

Recommended Posts

Hi, I manged to sort a query error earlier and using the advice i was given earlier i used this method to perform a select then edit query however it does not work. Is there a way to combine the two queries or make them work togeather.

 

I want to select a row and then edit the date destoryed here is the code:

 

//connect to the database
   //database information
     $host      = "stocks"; // Host name
     $username  = "njpeddle"; // Mysql username
     $password  = "mysql5"; // Mysql password
     $db_name   = "njpeddle"; // Database name
 $db_table = "Staff"; //connecting to the staff table


  mysql_connect("$host", "$username", "$password")or die("cannot connect");
      mysql_select_db("$db_name")or die("cannot select DB");  


//query
$q1 = ("SELECT BcId, BtId from BookCopy WHERE BcId = $bcid and BtId =$btid");
$res1 = mysql_query($q1) or die (mysql_error());

if ($res1){

$q2 = ("INSERT INTO BookCopy (DateDestroyed) 
VALUES ('$dd')");

$res2 = mysql_query($q2) or die (mysql_error());
}
if ($res2) { //If it ran ok.

// Print message below: 

echo '<h4> Confirmation that the book been removed from the library Database.</h4>';

 

there is more but i dont think its needed!

 

great thanks alot for any advice pointing me in the right direction! 

Link to comment
Share on other sites

$q1 = ("SELECT BcId, BtId from BookCopy WHERE BcId = $bcid and BtId =$btid");

 

You should quote the values for mysql

 

$q1 = ("SELECT BcId, BtId from BookCopy WHERE BcId = '$bcid' AND BtId = '$btid'");

 

also, the way you set up the query, if it fails it will die, therefore there is no need for the if statement, thats just a point out.

 

secondly, you can't INSERT a change, you do UPDATE

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.