earth2ocean Posted November 1, 2008 Share Posted November 1, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/130992-solved-explanation-needed/ Share on other sites More sharing options...
Flames Posted November 1, 2008 Share Posted November 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/130992-solved-explanation-needed/#findComment-680021 Share on other sites More sharing options...
Mchl Posted November 1, 2008 Share Posted November 1, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/130992-solved-explanation-needed/#findComment-680023 Share on other sites More sharing options...
earth2ocean Posted November 1, 2008 Author Share Posted November 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/130992-solved-explanation-needed/#findComment-680027 Share on other sites More sharing options...
earth2ocean Posted November 1, 2008 Author Share Posted November 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/130992-solved-explanation-needed/#findComment-680029 Share on other sites More sharing options...
Mchl Posted November 1, 2008 Share Posted November 1, 2008 Flames' example would work as well, if he didn't escape all 's... Quote Link to comment https://forums.phpfreaks.com/topic/130992-solved-explanation-needed/#findComment-680030 Share on other sites More sharing options...
Flames Posted November 1, 2008 Share Posted November 1, 2008 thats what i guessed when i looked back, i thought you needed to escape ' in echo statements using " Quote Link to comment https://forums.phpfreaks.com/topic/130992-solved-explanation-needed/#findComment-680033 Share on other sites More sharing options...
earth2ocean Posted November 1, 2008 Author Share Posted November 1, 2008 Excellent, I can see the differences in the codes. I've learned something else about this stuff! Thanks heaps, guys. Much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/130992-solved-explanation-needed/#findComment-680034 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.