title: SQL Database - Update Record via PHP Form. No Errors, but no update.
body: <p>Hoping this is the right area to be putting this. At current I'm working on a little project for fun and at the same time attempting to teach myself some PHP. I've created a little 'Audit' page that's associated with my website that allows me to Input new data to a pre-existing SQL Database, Search on that Data and Update that Data. Now, the Adding and Search works without a Hitch. The only problem is the 'Update' function does not... It does not Error (in fact it states it is successful) and it all works how it should, except that it does not 'actually' update the information within the table. </p>
  
  <p>I've spent the past 2-3 days reading through StackOverflow, Tutorial Guides, Forums and just playing with parts of the code myself, none of which has provided even a 'remote' answer. </p>
  
  <p>I have 2 pages that are relevant, the 'update.php' page and the 'update_ac.php' page that runs the script after hitting 'submit' on the Form, the code is as below: </p>
  
  <p>update.php</p>
  
  <pre><code>&lt;?php
  $host="localhost"; // Host name 
  $username="member2"; // Mysql username 
  $password="********"; // Mysql password 
  $db_name="audits"; // Database name 
  $tbl_name="data"; // Table name
  
  // Connect to server and select database.
  mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  mysql_select_db("$db_name")or die("cannot select DB");
  
  // get value of id that sent from address bar
  $id=$_GET['id'];
  
  // Retrieve data from database 
  $sql="SELECT * FROM $tbl_name WHERE id='$id'";
  $result=mysql_query($sql);
  
  $rows=mysql_fetch_array($result);
  ?&gt;
  
  &lt;table width="400" border="0" cellspacing="1" cellpadding="0"&gt;
  &lt;tr&gt;
  &lt;form name="form1" method="post" action="update_ac.php"&gt;
  &lt;td&gt;
  &lt;table width="100%" border="0" cellspacing="1" cellpadding="0"&gt;
  &lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td colspan="3"&gt;&lt;strong&gt;Update data in mysql&lt;/strong&gt; &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Barcode&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Product&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Category&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Assigned&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Notes&lt;/strong&gt;&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td align="center"&gt;
  &lt;input name="barcode" type="text" id="barcode" value="&lt;? echo $rows['barcode']; ?&gt;"&gt;
  &lt;/td&gt;
  &lt;td align="center"&gt;
  &lt;input name="product" type="text" id="product" value="&lt;? echo $rows['product']; ?&gt;" size="15"&gt;
  &lt;/td&gt;
  &lt;td align="center"&gt;
  &lt;select name="category" id="category" value="&lt;? echo $rows['category']; ?&gt;"&gt;
  &lt;option value="Hardware"&gt;Hardware&lt;/option&gt;
  &lt;option value="Software"&gt;Software&lt;/option&gt;
  &lt;option value="Furniture"&gt;Furniture&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;  
  &lt;td align="center"&gt;
  &lt;select name="assigned" id="assigned" value="&lt;? echo $rows['assigned']; ?&gt;"&gt;
  &lt;option value="name1"&gt;Name 1&lt;/option&gt;
  &lt;option value="name1"&gt;Name 2&lt;/option&gt;
  &lt;option value="name1"&gt;Name 3&lt;/option&gt;
  &lt;option value="name1"&gt;Name 4&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;td align="center"&gt;
  &lt;input name="notes" type="text" id="notes" value="&lt;? echo $rows['notes']; ?&gt;" size="15"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;
  &lt;input name="id" type="hidden" id="id" value="&lt;? echo $rows['id']; ?&gt;"&gt;
  &lt;/td&gt;
  &lt;td align="center"&gt;
  &lt;input type="submit" name="Submit" value="Submit"&gt;
  &lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/form&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;?php
  // close connection 
  mysql_close();
  ?&gt;
  </code></pre>
  
  <p>update_ac.php</p>
  
  <pre><code>&lt;?php
  $host="localhost"; // Host name 
  $username="member2"; // Mysql username 
  $password="********"; // Mysql password 
  $db_name="audits"; // Database name 
  $tbl_name="data"; // Table name 
  
  // Connect to server and select database.
  mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  mysql_select_db("$db_name")or die("cannot select DB");
  
  // update data in mysql database 
  $sql="UPDATE $tbl_name SET barcode='$barcode', product='$product', category='$category', assigned='$assigned', notes='$notes' WHERE id='$id'";
  $result=mysql_query($sql);
  
  // if successfully updated. 
  if($result){
  echo "Successful";
  echo "&lt;BR&gt;";
  echo "&lt;a href='assets.php'&gt;View Changes&lt;/a&gt;";
  echo "&lt;BR&gt;";
  echo "&lt;a href='login-home.php'&gt;Home&lt;/a&gt;";
  }
  
  else {
  echo "ERROR";
  }
  
  ?&gt; 
  </code></pre>
  
  <p>Now, I did pull this from an <a href="http://www.phpeasystep.com/mysql/9.html" rel="nofollow">older site</a> and kind of 'changed' to suit my own needs to no avail. I even did a complete copy/paste of their Tutorial (inclusive of their Database) and even that did not work, which seems to indicate something is wrong with the code somewhere. Thanks in advance.</p>