Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have a query that is not giving the expected result or receiving an error, and the problem isn't obvious, you should generally take a look at the final query just before it's run. Try using this right before running the query:</p> <pre><code>echo $sql; exit; </code></pre> <p>Viewing the actual query often makes it obvious what the problem is, especially when the query includes variables. If the problem still isn't obvious, you can paste the query as is into a query browser to get feedback directly from the database engine.</p> <p>Interestingly, using parametrized queries, you won't get to see the parameter values, as the parameters get replaced by MySQL, not PHP, however, you'll still get to see the entire prepared query.</p> <p>Also, you can see the number of affected rows from your <code>UPDATE</code> statement with the <code>mysql_affected_rows()</code> function. You could put this immediately after the query is run:</p> <pre><code>echo ("Updated records:", mysql_affected_rows()); </code></pre> <p>Spaces are often forgotten when concatenating queries.</p> <pre><code>$sql = "SELECT * FROM ducks"; $sql .= "WHERE duck = 'goose'"; </code></pre> <p>When echoing the above query, we see:</p> <pre><code>SELECT * FROM ducksWHERE duck &lt;&gt; 'goose' </code></pre> <p>I'm guessing that the <code>WHERE</code> clause in your <code>UPDATE</code> statement isn't matching an "<code>id = '$id'</code>".</p> <p>Also, is the id column really a string? You've put single quotes around the value. MySQL will cast the string to an integer if needed, but if it's an integer, save the database some work and remove the single quotes.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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