Hi Everyone, I have a real noob question please,
I am trying to update a mysql database using the code below, I know the invoice number variable is correct, But for some reason the database is not updating,

Can someone point me in the right direction please,
I have tried using quotes arounf the var, but still the database is not updating -

mysqli_query("update mch_orders set mch_wsp='yes' where mch_rand=$invoice");

Thanks in advance DaniWebbers

Recommended Answers

All 7 Replies

If you manually run the query, does it works? If, for example: you are using InnoDB, autocommit is disabled, then there could be a deadlock.

A part from that, use var_dump against $invoice, to be sure the value is really received by the script.

Also, if you are running ext/mysqli in procedural mode, then the first argument must be the connection to the database and the second the query:

mysqli_query($conn, 'YOUR QUERY HERE');

If it still does not help provide more info, show more code, it could be something else.

Hi, Thanks for your input,

I have been trying to get the database to update using the following code - I am completely lost as to why the database is not updating

            $servername = "sn";
            $username = "un";
            $password = "pw";
            $dbname = "db";

            // Create connection
            $conn = mysqli_connect($servername, $username, $password, $dbname);
            // Check connection
            if (!$conn) {
                die("Connection failed: " . mysqli_connect_error());
            }

            $sql = "UPDATE mch_orders SET mch_wsp='1' WHERE mch_rand='".$invoice."'";

but still not updating

I am using php - The update has worked in the command line yes, with me removing the ( ' ) before and after 1

I will test now with a live update and let you know, thanks

Hi, Just updating and saying thanks -
The following sql update now works with the ammended code -

$sql = "UPDATE mch_orders SET mch_wsp=1 WHERE mch_rand=".$invoice." ";

Good you fixed it. Next time add the PHP tag to save a step. Also the issue and change you made would have us know your database schema.

So I hope my advice about using the command line helped you find this one.

You are defining your SQL statement in line 13 however you're not executing it. It would be mysql_query ($sql);
Consult your version of php for the exact syntax as some intrinsic functions are depreciated with certain versions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.