Bill Sullivan
asked on
Update query not working properly
I have a problem updating a mysql table entry. I copied and pasted the format I've used for years to update tables, but for some reason it is not working here.
My query reads, $queryUpdate1=mysql_query( "UPDATE material SET _3Quan = '$_3Quan' WHERE file='$file'") or die('Query failed1: '.mysql_error());
The variable $_3Quan has a value of 100, but when the material table is updated, it returns a value of 0 to the _3Quan field. Prior to update the value was 95.
Can you help me figure out what I'm doing wrong here?
My query reads, $queryUpdate1=mysql_query(
The variable $_3Quan has a value of 100, but when the material table is updated, it returns a value of 0 to the _3Quan field. Prior to update the value was 95.
Can you help me figure out what I'm doing wrong here?
The extension you're using was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0, you may need to use MySQL Improved Extension "mysqli" instead, it's simple and it will give you the exact error happened in your query like :
Else you could always use mysql_error() to see what happen exactly :
$con = mysqli_connect("my_host","my_user","my_password","my_db");
// Perform a query, check for error
if (!mysqli_query($con, "UPDATE material SET _3Quan = '$_3Quan' WHERE file='$file'"))
{
echo("Error description: " . mysqli_error($con));
}
Else you could always use mysql_error() to see what happen exactly :
$queryUpdate1 = mysql_query("UPDATE material SET _3Quan = '$_3Quan' WHERE file='$file'");
if (!$queryUpdate1) {
trigger_error('Invalid query: ' . mysql_error());
}
Hi,
When a query fails I usually check PHP log file and I try to run the query manually in PHPmyAdmin to help me find the problem.
Make sure you enable error reporting from PHP http://php.net/manual/en/function.error-reporting.php
If you can use https://xdebug.org/ it is a fantastic tool (this is bundle with wampserver)
When a query fails I usually check PHP log file and I try to run the query manually in PHPmyAdmin to help me find the problem.
Make sure you enable error reporting from PHP http://php.net/manual/en/function.error-reporting.php
If you can use https://xdebug.org/ it is a fantastic tool (this is bundle with wampserver)
i'd assume you enabled strict mode or upgraded to a version that uses strict mode. so '100' is actually text and it's numeric value is not 100.
also note that your code is wide open to sql injections.
for both issues, you may wish to use var_export instead of '$whatever' . other ways to deal with this include using mysql_real_escape_string or prepared queries.
also note that your code is wide open to sql injections.
for both issues, you may wish to use var_export instead of '$whatever' . other ways to deal with this include using mysql_real_escape_string or prepared queries.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window
if the sql generated looks good, then the decrepancy is most likely causing by other issues.