Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQLi Update is not working properly
    primarykey
    data
    text
    <p>I am trying to update one of my row with PHP using MySQLi and if I refresh PHPMyAdmin less than 1 second after update it's sucessfull but if I only check the data 2 seconds+ after the update it doesn't update.</p> <p>For exemple:</p> <pre><code>'UPDATE orders SET MachineID = '.$id.' WHERE OrderID = '.$OrderID. 'AND ProductID = '.$ProductID </code></pre> <p>Does not work unless I refresh quickly but...</p> <pre><code>'UPDATE orders SET MachineID = 2 WHERE OrderID = 4 AND ProductID = 12' </code></pre> <p>Will work no matter how long after I refresh. <em>(Those are the data I normaly use to test.)</em></p> <p>So I though it would be my variables, but I'm using them almost 10 times before this part of the code in other queries and it works perfectly.</p> <ul> <li>I tried to trim() the variable and it did not help.</li> <li>I also tried to use mysqli_real_escape_string() with no success.</li> <li>mysqli_error() is not giving me anything.</li> <li>mysqli_affected_rows() is giving me "1" which is what it is suppose to be.</li> <li>And the weird part is if I execute 'SELECT MachineID FROM orders WHERE OrderID = 4 AND ProductID = 12', it gives me the updated answer even if phpMyAdmin does not update the data.</li> </ul> <p>There is no other code after this, so nothing that could "reverse" the update.</p> <p>A normal "test" ouput looks like this:</p> <p><strong>Edit:</strong> This it what the browser outputs.</p> <pre><code>ID: "2" //$id OrderID: "4" //$OrderID ProductID: "12" //$ProductID UPDATE orders SET MachineID = 2 WHERE OrderID = 4 AND ProductID = 12 //Query boolean true //Result var_dump 1 //Number of rows affected 2 //Machine ID </code></pre> <p>Note: The quotes are not part of the variables.</p> <p><strong>Edit:</strong> This is the PHP code</p> <pre><code>$query = 'UPDATE orders SET MachineID = '.$id.' WHERE OrderID = '.$OrderID.' AND ProductID = '.$ProductID; echo 'ID: "'.$id.'"&lt;br/&gt; OrderID: "'.$OrderID.'"&lt;br/&gt; ProductID: "'.$ProductID.'"&lt;br/&gt;'.$query.'&lt;br/&gt;'; $res = $db-&gt;query($query); var_dump($res); echo mysqli_affected_rows ($db).'&lt;br/&gt;'; $result = $db-&gt;query('SELECT MachineID FROM orders WHERE OrderID = 4 AND ProductID = 12'); $result = $result-&gt;fetch_array(); echo $result[0]; </code></pre> <p>I really don't understand why it would work in the file and after a quick refresh but not if it takes to long to retreive the data. It's like it would reset after a certain amount of time if it's not fetch.</p> <p>I've been working on this for almost 2 days now I have no idea why it's not working. This is some pretty simple SQL query.</p> <p><strong>Edit:</strong> I've look into MySQL binary logs and it seems that I'm updating it back to 1 every time. The only way this could be happening is if the file would run twice, but if it runs twice why would the output be there only once ?</p> <p><strong>Edit:</strong> Ok, so it seems like the problem comes from Google Chrome. I've tested it on IE and it works. For some reason Chrome would be running the file twice.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload