title: Update data present in database by php
body: <p>Created a table "test_mysql" in database "test"
  I have 3 files
  1. list_records.php
  2. update.php
  3. update_ac.php</p>
  
  <p>Databse code</p>
  
  <p>Create database and table using phpMyAdmin</p>
  
  <pre><code>CREATE TABLE `test_mysql` (
  `id` int(4) NOT NULL auto_increment,
  `name` varchar(65) NOT NULL default '',
  `lastname` varchar(65) NOT NULL default '',
  `email` varchar(65) NOT NULL default '',
  PRIMARY KEY (`id`)
  ) TYPE=MyISAM AUTO_INCREMENT=7 ;
  -- 
  -- Dumping data for table `test_mysql`
  --
  INSERT INTO `test_mysql` VALUES (1, 'Billly', 'Blueton', 'bb5@phpeasystep.com');
  INSERT INTO `test_mysql` VALUES (2, 'Jame', 'Campbell', 'jame@somewhere.com');
  INSERT INTO `test_mysql` VALUES (3, 'Mark', 'Jackson', 'mark@phpeasystep.com');
  INSERT INTO `test_mysql` VALUES (4, 'Linda', 'Travor', 'lin65@phpeasystep.com');
  INSERT INTO `test_mysql` VALUES (5, 'Joey', 'Ford', 'fordloi@somewhere.com');
  INSERT INTO `test_mysql` VALUES (6, 'Sidney', 'Gibson', 'gibson@phpeasystep.com');
  </code></pre>
  
  <hr>
  
  <p>list_records.php</p>
  
  <pre><code>&lt;?php
  $host="localhost"; // Host name 
  $username=""; // Mysql username 
  $password=""; // Mysql password 
  $db_name="test"; // Database name 
  $tbl_name="test_mysql"; // 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");
  
  $sql="SELECT * FROM $tbl_name";
  $result=mysql_query($sql);
  ?&gt;
  
  &lt;table width="400" border="0" cellspacing="1" cellpadding="0"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;table width="400" border="1" cellspacing="0" cellpadding="3"&gt;
  &lt;tr&gt;
  &lt;td colspan="4"&gt;&lt;strong&gt;List data from mysql &lt;/strong&gt; &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Lastname&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Email&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;?php
  while($rows=mysql_fetch_array($result)){
  ?&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;?php echo $rows['name']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $rows['lastname']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $rows['email']; ?&gt;&lt;/td&gt;
  
  // link to update.php and send value of id 
  &lt;td align="center"&gt;&lt;a href="update.php?id=&lt;?php echo $rows['id']; ?&gt;"&gt;update&lt;/a&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;?php
  }
  ?&gt;
  
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;?php
  mysql_close();
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p>update.php</p>
  
  <pre><code>&lt;?php
  $host="localhost"; // Host name 
  $username=""; // Mysql username 
  $password=""; // Mysql password 
  $db_name="test"; // Database name 
  $tbl_name="test_mysql"; // 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;/tr&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Lastname&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center"&gt;&lt;strong&gt;Email&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="name" type="text" id="name" value="&lt;?php echo $rows['name']; ?&gt;"&gt;
  &lt;/td&gt;
  &lt;td align="center"&gt;
  &lt;input name="lastname" type="text" id="lastname" value="&lt;?php echo $rows['lastname']; ?&gt;" size="15"&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;input name="email" type="text" id="email" value="&lt;?php echo $rows['email']; ?&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;?php 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>
  
  <hr>
  
  <p>update_ac.php</p>
  
  <pre><code>&lt;?php
  $host="localhost"; // Host name 
  $username=""; // Mysql username 
  $password=""; // Mysql password 
  $db_name="test"; // Database name 
  $tbl_name="test_mysql"; // Table name 
  $id='id';
  $name="name";
  $lastname="lastname";
  $email="email";
  
  // 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 name='$name', lastname='$lastname', email='$email' WHERE id='$id'";
  $result=mysql_query($sql);
  
  // if successfully updated. 
  if($result){
  echo "Successful";
  echo "&lt;BR&gt;";
  echo "&lt;a href='list_records.php'&gt;View result&lt;/a&gt;";
  }
  
  else {
  echo "ERROR";
  }
  
  ?&gt;
  </code></pre>
  
  <p>Now the problem is after applying all this code I am still unable to update any row..PLS HELP ME OUT :( it shows updates succesfully but it doesnot update anything.</p>