Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL error, I can't see what's wrong
    text
    copied!<p>I am using this code to enter update user permissions on a web app:</p> <pre><code>$updaters = array(); for ($i = 1; $i &lt;= 24; $i++){ if (isset($_POST['permsA['.$i.']'])) $updaters[] = '`'.$i.'` = \''.mysqli_real_escape_string($db, $_POST['permsA['.$i.']']).'\''; } $insert = mysqli_query($db,'UPDATE `tbl_perms` SET '.implode(',', $updaters). 'WHERE `userid` = '.$id)or die(mysqli_error($db)); </code></pre> <p>The error I get is from the SQL:</p> <pre>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `userid` = 1' at line 1</pre> <p>I can't seem to be able to rewrite the code to remove the error :(</p> <p>this is the code to generate permsA</p> <pre><code>&lt;? while($i = mysqli_fetch_array($get_perms)){ $pname = $i[pname]; $id = $i[id]; ?&gt; &lt;div&gt;&lt;input type="checkbox" tabindex="1" name="permsA[&lt;? echo $id;?&gt;]" value="1" &lt;? if($permissionid[$id] == '1') {echo ' checked="checked" ';}?&gt; /&gt;&lt;?echo htmlspecialchars($pname);?&gt;&lt;/div&gt; &lt;? } ?&gt; </code></pre> <p>Here is the exact query that produces the error:</p> <pre><code>$insert = mysqli_query($db,'UPDATE `tbl_perms` '.$updaters.' WHERE `userid` = '.$id) or die(mysqli_error($db)); </code></pre> <p>Here is what this sql generates:</p> <pre><code>UPDATE `tbl_perms` SET WHERE `userid` = 1 </code></pre> <p>And here's a variable dump from the variables after POST <code>var_dump($_POST['permsA'])</code>:</p> <p><code>array(22) { [1]=&gt; string(1) "1" [2]=&gt; string(1) "1" [3]=&gt; string(1) "1" [4]=&gt; string(1) "1" [5]=&gt; string(1) "1" [6]=&gt; string(1) "1" [8]=&gt; string(1) "1" [9]=&gt; string(1) "1" [10]=&gt; string(1) "1" [11]=&gt; string(1) "1" [12]=&gt; string(1) "1" [13]=&gt; string(1) "1" [14]=&gt; string(1) "1" [15]=&gt; string(1) "1" [16]=&gt; string(1) "1" [17]=&gt; string(1) "1" [18]=&gt; string(1) "1" [19]=&gt; string(1) "1" [20]=&gt; string(1) "1" [21]=&gt; string(1) "1" [22]=&gt; string(1) "1" [23]=&gt; string(1) "1" }</code></p>
 

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