title: PHP/MySQL allowing current user to edit their account information
body: <p>I have created 2 pages</p>
  
  <pre><code>update.php
  edit.php
  </code></pre>
  
  <p>We start on edit.php so here is edit.php's script</p>
  
  <pre><code>&lt;?php
  session_start();
  $id = $_SESSION["id"];
  $username = $_POST["username"];
  $fname = $_POST["fname"];
  $password = $_POST["password"];
  $email = $_POST["email"];
  
  mysql_connect('mysql13.000webhost.com', 'a2670376_Users', 'Password') or     die(mysql_error());
  echo "MySQL Connection Established! &lt;br&gt;";
  
  mysql_select_db("a2670376_Pass") or die(mysql_error());
  echo "Database Found! &lt;br&gt;";
  
  $query = "UPDATE members SET username = '$username', fname = '$fname', 
  password = '$password' WHERE id = '$id'";
  
  $res = mysql_query($query);
  
  if ($res)
  echo "&lt;p&gt;Record Updated&lt;p&gt;";
  else
  echo "Problem updating record. MySQL Error: " . mysql_error();
  ?&gt;
  
  &lt;form action="update.php" method="post"&gt;
  &lt;input type="hidden" name="id" value="&lt;?=$id;?&gt;"&gt;
  ScreenName:&lt;br&gt; &lt;input type='text' name='username' id='username' maxlength='25'   style='width:247px' name="username" value="&lt;?=$username;?&gt;"/&gt;&lt;br&gt;
  FullName:&lt;br&gt; &lt;input type='text' name='fname' id='fname' maxlength='20' style='width:248px'     name="ud_img" value="&lt;?=$fname;?&gt;"/&gt;&lt;br&gt;
  Email:&lt;br&gt; &lt;input type='text' name='email' id='email' maxlength='50' style='width:250px'    name="ud_img" value="&lt;?=$email;?&gt;"/&gt;&lt;br&gt;
  Password:&lt;br&gt; &lt;input type='text' name='password' id='password' maxlength='25'     style='width:251px' value="&lt;?=$password;?&gt;"/&gt;&lt;br&gt;
  &lt;input type="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Now here is the update.php page where I am having the major problem</p>
  
  <pre><code>&lt;?php
  session_start();
  mysql_connect('mysql13.000webhost.com', 'a2670376_Users', 'Password') or   die(mysql_error());
  mysql_select_db("a2670376_Pass") or die(mysql_error());
  
  $id = (int)$_SESSION["id"];
  
  $username = mysql_real_escape_string($_POST["username"]);
  $fname = mysql_real_escape_string($_POST["fname"]);
  $email = mysql_real_escape_string($_POST["email"]);
  $password = mysql_real_escape_string($_POST["password"]);
  
  
  $query="UPDATE members
  SET username = '$username', fname = '$fname', email = '$email', password = '$password'
  WHERE id='$id'";
  
  
  mysql_query($query)or die(mysql_error());
  if(mysql_affected_rows()&gt;=1){
  echo "&lt;p&gt;($id) Record Updated&lt;p&gt;";
  }else{
  echo "&lt;p&gt;($id) Not Updated&lt;p&gt;";
  }
  ?&gt; 
  </code></pre>
  
  <p>Now on edit.php I fill out the form to edit the account "test" while I am logged into it now once the form if filled out I click on Submit button
  and it takes me to update.php and it returns this</p>
  
  <pre><code>(0) Not Updated  
  
  (0) &lt;= id of user logged in
  
  Not Updated &lt;= MySql Error from  
  
  
  mysql_query($query)or die(mysql_error());
  if(mysql_affected_rows()&gt;=1){
  </code></pre>
  
  <p>I want it to update the user logged in and if I am not mistaken in this script it says </p>
  
  <pre><code>  $id = (int)$_SESSION["id"];
  </code></pre>
  
  <p>which updates the user with the id of the person who is logged in</p>
  
  <p>but it isn't updating, its saying that no tables were effected </p>
  
  <p>if it helps here's my MySQL Database picture
  just click here  <a href="http://i50.tinypic.com/21juqfq.png" rel="nofollow">http://i50.tinypic.com/21juqfq.png</a></p>
  
  <p>if this could possibly be any help to find the solution I have 2 more files delete.php and delete_ac.php they have can remove users from my sql database and they show the user id and it works  there are no bugs in this script at all PLEASE DO NOT MAKE SUGGESTIONS FOR THE SCRIPTS BELOW 
  delete.php first</p>
  
  <pre><code>    &lt;?php
  
  $host="mysql13.000webhost.com"; // Host name 
  $username="a2670376_Users"; // Mysql username 
  $password="PASSWORD"; // Mysql password 
  $db_name="a2670376_Pass"; // Database name 
  $tbl_name="members"; // 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");
  
  // select record from mysql 
  $sql="SELECT * FROM $tbl_name";
  $result=mysql_query($sql);
  ?&gt;
  
  &lt;table border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"&gt;
  &lt;tr&gt;
  &lt;td colspan="8" style="bgcolor: #FFFFFF"&gt;&lt;strong&gt;&lt;img src="http://i47.tinypic.com/u6ihk.png" height="30" widht="30"&gt;Delete data in mysql&lt;/strong&gt; &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Id&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;UserName&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;FullName&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Password&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Email&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Date&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center" bgcolor="#FFFFFF"&gt;&lt;strong&gt;Ip&lt;/strong&gt;&lt;/td&gt;
  &lt;td align="center" bgcolor="#FFFFFF"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;?php
  while($rows=mysql_fetch_array($result)){
  ?&gt;
  
  &lt;tr&gt;
  &lt;td bgcolor="#FFFFFF"&gt;&lt;? echo $rows['id']; ?&gt;&lt;/td&gt;
  &lt;td bgcolor="#FFFFFF"&gt;&lt;? echo $rows['username']; ?&gt;&lt;/td&gt;
  &lt;td bgcolor="#FFFFFF"&gt;&lt;? echo $rows['fname']; ?&gt;&lt;/td&gt;
  &lt;td bgcolor="#FFFFFF"&gt;&lt;? echo $rows['password']; ?&gt;&lt;/td&gt;
  &lt;td bgcolor="#FFFFFF"&gt;&lt;? echo $rows['email']; ?&gt;&lt;/td&gt;
  &lt;td bgcolor="#FFFFFF"&gt;&lt;? echo $rows['date']; ?&gt;&lt;/td&gt;
  &lt;td bgcolor="#FFFFFF"&gt;&lt;? echo $rows['ip']; ?&gt;&lt;/td&gt;
  &lt;td bgcolor="#FFFFFF"&gt;&lt;a href="delete_ac.php?id=&lt;? echo $rows['id']; ?&gt;"&gt;delete&lt;/a&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;?php
  // close while loop 
  }
  ?&gt;
  
  &lt;/table&gt;
  
  &lt;?php
  // close connection; 
  sql_close();
  ?&gt;
  </code></pre>
  
  <p></p>
  
  <p>and now delete_ac.php</p>
  
  <pre><code>&lt;table width="500" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"&gt;
  &lt;tr&gt;
  &lt;td colspan="8" bgcolor="#FFFFFF"&gt;&lt;strong&gt;&lt;img src="http://t2.gstatic.com/images?           q=tbn:ANd9GcS_kwpNSSt3UuBHxq5zhkJQAlPnaXyePaw07R652f4StmvIQAAf6g" height="30"     widht="30"&gt;Removal Of Account&lt;/strong&gt; &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="center" bgcolor="#FFFFFF"&gt;
  &lt;?php
  
  $host="mysql13.000webhost.com"; // Host name 
  $username="a2670376_Users"; // Mysql username 
  $password="javascript00"; // Mysql password 
  $db_name="a2670376_Pass"; // Database name 
  $tbl_name="members"; // Table name 
  
  // Connect to server and select databse.
  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'];
  
  // Delete data in mysql from row that has this id 
  $sql="DELETE FROM $tbl_name WHERE id='$id'";
  $result=mysql_query($sql);
  
  // if successfully deleted
  if($result){
  echo "Deleted Successfully";
  echo "&lt;BR&gt;";
  echo "&lt;a href='delete.php'&gt;Back to main page&lt;/a&gt;";
  }
  
  else {
  echo "ERROR";
  }
  ?&gt; 
  
  &lt;?php
  // close connection 
  mysql_close();
  ?&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>