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?
Bill SullivanCEOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongSoftware Team LeadCommented:
try check what you getting there...

$sql = "UPDATE material SET _3Quan = '$_3Quan' WHERE file='$file'";

Open in new window

if the sql generated looks good, then the decrepancy is most likely causing by other issues.
Zakaria AcharkiAnalyst DeveloperCommented:
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 :

$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));

Open in new window

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());

Open in new window


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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.