Jump to content

Recommended Posts

Can anyone tell me why my returned message is that the database hasn't been updated, when it has??? This has happened in a couple of places and I can't figure out why. Of course, I could just take out the bit that tells me anything and then the user would never know... but it's sort of bugging me to know why it happens. Here's the code:

mysql_query(" UPDATE equipment SET equip_customer_hire='$customer_hire_ID', equip_outdate='$equip_outdate', equip_returndate='$equip_returndate', equip_availability=1 WHERE equip_ID='$equip_ID'");
$result=mysql_query($query);
if(!$result){
echo " Unable to update this record";
}else{
echo "Record updated successfully";
}

 

Also... I'm wondering if it's possible to have the initial link to update.php open in a small popup window rather than a new page. Can't seem to get javascript and php to work together. Anyone know a good way to do this?

Link to comment
https://forums.phpfreaks.com/topic/130992-solved-explanation-needed/
Share on other sites

because (and im guessing what your doing), the first mysql_query isn't given the variable $query so $result is failing because its not running anything but the table is being updated because your running the query earlier on. try doing this.

$query = "UPDATE equipment SET equip_customer_hire=\'$customer_hire_ID\', equip_outdate=\'$equip_outdate\', equip_returndate=\'$equip_returndate\', equip_availability=1 WHERE equip_ID=\'$equip_ID\'";
$result=mysql_query($query);
if(!$result){
echo " Unable to update this record";
}else{
echo "Record updated successfully";
}

 

It might work but it might give you errors with trying to escape the wrath of the ' symbols ;)

How about this?

 

$query = " UPDATE equipment SET equip_customer_hire='$customer_hire_ID', equip_outdate='$equip_outdate', equip_returndate='$equip_returndate', equip_availability=1 WHERE equip_ID='$equip_ID'";
if(!mysql_query($query)){
echo " Unable to update this record";
}else{
echo "Record updated successfully";
}

 

As far as I know, update queries don't return rows, so the $result will not be set.

 

There's no reason why JavaScript and PHP wouldn't work together... except for mixing them up.

 

[edit]

 

Just checked. For UPDATE, mysql_query() returns true or false, so it would work.

$query = " UPDATE equipment SET equip_customer_hire='$customer_hire_ID', equip_outdate='$equip_outdate', equip_returndate='$equip_returndate', equip_availability=1 WHERE equip_ID='$equip_ID'";
$result = mysql_query($query);
if(!$result){
echo " Unable to update this record";
}else{
echo "Record updated successfully";
}

 

Of course it would.... silly me...

because (and im guessing what your doing), the first mysql_query isn't given the variable $query so $result is failing because its not running anything but the table is being updated because your running the query earlier on. try doing this.

 

No, strangely it didn't update the database with that code. Thanks anyway.

How about this?

 

$query = " UPDATE equipment SET equip_customer_hire='$customer_hire_ID', equip_outdate='$equip_outdate', equip_returndate='$equip_returndate', equip_availability=1 WHERE equip_ID='$equip_ID'";
if(!mysql_query($query)){
echo " Unable to update this record";
}else{
echo "Record updated successfully";
}

 

 

That worked. I don't know enough to know why, but it made a difference. I'll read up and see if I can work out why. Thanks for that.  :)

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.