Jump to content

3 part query not failing!


will_1990

Recommended Posts

I have a three queries that are running but the 2nd one is not updating a dateback fie;d but the next part which inserts a new row in the same table. can anyone see what the problem could be?

 

thanks!

 

//query
$q1 = ("SELECT BcId, BorId, DateOut from Loan WHERE BcId = '$bcid' AND BorId ='$bid' AND DateOut ='$do'");
$res1 = mysql_query($q1) or die (mysql_error());

if ($res1){
[b]	
$q2 = ("UPDATE Loan SET DateBack = CURDATE() WHERE BcId = '$bcid' AND BorId = '$bid' AND DateOut ='$do'"); 
$res2 = mysql_query($q2) or die (mysql_error());

}[/b]
if ($res2) { //If it ran ok.

$q3 = "INSERT INTO Loan

(BorId, BcId, DateOut, DateDue, DateBack)

VALUES ('$bid', '$bcid', CURDATE() , ADDDATE(CURDATE(), INTERVAL 2 MONTH), NULL)";

$res3 = mysql_query($q3) or die (mysql_error());}
// Print message below: 

if ($res3) {

 

$q2 = ("UPDATE Loan SET DateBack = CURDATE() WHERE BcId = '$bcid' AND BorId = '$bid' AND DateOut ='$do'"); 
$res2 = mysql_query($q2) or die (mysql_error());

}
if ($res2) { //If it ran ok.

- this is the one not updating correctly!

 

thanks!

Link to comment
Share on other sites

declare those functions as variables then insert the variables into the database also you  are stating that you want to insert 5 feilds of data then you declare 6 feilds of data in the values, the number declared to be inserted must equal the number of feilds in the values.

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.