Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I see a few issues. Some will cause more issues than others. </p> <p>(1) You are missing the <code>name</code> attribute in your checkboxes. (2) You are missing the closing <code>&lt;/form&gt;</code> tag. (3) Your Query is probably failing as you have <code>VALUES(name, $total)</code>, and I assume <code>name</code> is a string so it needs to be in quotes <code>VALUES('name', $total)</code>, or more likely <code>VALUES('$name', $total)</code></p> <p>Also, I don't see why you are connecting to your database on the initial page load. I would move that inside your <code>isset($_POST['submit'])</code>. </p> <p>Try this -</p> <pre><code>&lt;?php $perms = array( 'writePost' =&gt; 1, 'readPost' =&gt; 2, 'deletePost' =&gt; 4, 'addUser' =&gt; 8, 'deleteUser' =&gt; 16, ); echo "&lt;form method='post' action='v3.php'&gt;"; foreach($perms as $key =&gt; $value) { echo "&lt;input type='checkbox' name='checkboxes[]' value='".$value."'&gt;\n"; echo "&lt;label for='".$key."'&gt;".ucfirst($key)."&lt;/label&gt;&lt;br&gt;\n"; } echo "&lt;input type='text' name='name'&gt;"; echo "&lt;input type='submit' name='submit'&gt;"; echo "&lt;/form&gt;"; if(isset($_POST['submit'])) { mysql_connect( 'localhost', 'root', '')or die("cannot connect"); mysql_select_db('webgame')or die("cannot select DB"); $total = 0; $name = mysql_real_escape_string($_POST['name']); foreach ($_POST['checkboxes'] as $keys=&gt;$vals) { $total += $vals; } mysql_query("INSERT INTO perms (name, rights) VALUES('$name', $total)") or die(mysql_error()); } ?&gt; </code></pre> <p>Also, the <code>mysql_*</code> extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the <a href="http://php.net/manual/en/book.mysqli.php" rel="nofollow">MySQLi</a> or <a href="http://php.net/manual/en/ref.pdo-mysql.php" rel="nofollow">PDO_MySQL</a> extension should be used. See also <a href="http://php.net/manual/en/mysqlinfo.api.choosing.php" rel="nofollow">MySQL: choosing an API guide</a> and <a href="http://php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated" rel="nofollow">related FAQ</a> for more information. </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