title: Update MySQL using HTML Form and PHP
body: <p>I've been looking through dozens of threads on here about this but have yet to find a solution.</p>
  
  <p>I've created a form that is supposed to show database table contents in input boxes, and when the content of the input boxes are changed and submitted the database is supposed to update.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;?php
  
  $dbhost = '****';
  $dbuser = '****';
  $dbpass = '****';
  $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  if(! $conn )
  {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db('****');
  
  $query = "SELECT * FROM anstalld";
  $result = mysql_query($query) or die(mysql_error());
  
  ?&gt;
  
  
  &lt;form method="post" action="&lt;?php $_PHP_SELF ?&gt;"&gt;
  &lt;table width="400" border="0" cellspacing="1" cellpadding="2"&gt;
  &lt;tr&gt;
  
  &lt;?php 
  
  while($row = mysql_fetch_array($result))
              {
  
  $namn = $row['namn'];
  $mandag = $row['mandag'];
  $tisdag = $row['tisdag'];
  $onsdag = $row['onsdag'];
  $torsdag = $row['torsdag'];
  $fredag = $row['fredag'];
  ?&gt;
  
  
  &lt;td width="100"&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?=$namn?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="100"&gt;Mandag&lt;/td&gt;
  &lt;td&gt;&lt;input name="mandagid" type="text" value="&lt;?=$mandag?&gt;"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="100"&gt;Tisdag&lt;/td&gt;
  &lt;td&gt;&lt;input name="tisdagid" type="text" value="&lt;?=$tisdag?&gt;"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="100"&gt;Onsdag&lt;/td&gt;
  &lt;td&gt;&lt;input name="onsdagid" type="text" value="&lt;?=$onsdag?&gt;"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="100"&gt;Torsdag&lt;/td&gt;
  &lt;td&gt;&lt;input name="torsdagid" type="text" value="&lt;?=$torsdag?&gt;"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="100"&gt;Fredag&lt;/td&gt;
  &lt;td&gt;&lt;input name="fredagid" type="text" value="&lt;?=$fredag?&gt;"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php } ?&gt;
  &lt;tr&gt;
  &lt;td width="100"&gt; &lt;/td&gt;
  &lt;td&gt; &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="100"&gt; &lt;/td&gt;
  &lt;td&gt;
  &lt;input name="update" type="submit" id="update" value="Update"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  
  
  
  &lt;?php
  
  if(isset($_POST['update']))
  {
  
  $namn = $_POST['namnid'];
  $mandag = $_POST['mandagid'];
  $tisdag = $_POST['tisdagid'];
  $onsdag = $_POST['onsdagid'];
  $torsdag = $_POST['torsdagid'];
  $fredag = $_POST['fredagid'];
  
  $sql = mysql_query("UPDATE anstalld SET mandag = '$mandag', tisdag = '$tisdag', onsdag = '$onsdag', torsdag = '$torsdag', fredag = '$fredag' WHERE namn = '$namn'");
  
  $retval = mysql_query( $sql, $conn );
  if(! $retval )
  {
    die('Could not update data: ' . mysql_error());
  }
  echo "Updated data successfully\n";
  
  }
  
  
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The forms show the content of the database fine, but upon updating I get this message:</p>
  
  <blockquote>
    <p>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 '1' at line 1</p>
  </blockquote>
  
  <p>I appreciate any help I can get on this. </p>