Jump to content

[SOLVED] My code isn't updating the database


adamjones

Recommended Posts

Hi. I'm making a settings page where users can update their info, however, when submitting the form, it's just overwriting the old details with nothing...

 

This is my code;

<?php
$host="localhost";
$username="designby_x";
$password="password";
$db_name="designby_x";
$tbl_name="members";

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$name=$_GET['myusername'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
	  <form name='form1' method='send' action='update_ac.php' id='formular' class='formular' rel='facebox'>
  <fieldset> 				<legend>Account Info</legend> 				
  <label>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="52%"><div align="left"><b>Your Password</b>:</div></td>
      <td width="48%"><div align="left">
        <label>
        <input name="pass" type="password" id="pass" value="<? echo $rows['password']; ?>" />
        </label>
</div></td>
    </tr>
  </table>
  </fieldset></label> 			 			
  <fieldset> 				<legend>Personal Info</legend> 				
  <label>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="52%"><div align="left"><b>Name</b>:</div></td>
      <td width="48%"><div align="left">
        <label>
        <input name="name" type="text" id="name" value="<? echo $rows['name']; ?>" />
        </label>
      </div></td>
    </tr>
    <tr>
      <td><div align="left"><b>E-Mail address:</b></div></td>
      <td><div align="left">
        <label>
        <input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" />
        </label>
      </div></td>
    </tr>
  </table>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="22%"><label>
        <input type="submit" name="submit" id="submit" value="Update" />
      </label></td>
      <td width="78%"><label>
        <input type="reset" name="Reset" id="Reset" value="Reset" />
      </label></td>
      </tr>
  </table>
  <p>
    <label></label>
  (If you are having troubles clicking in the boxes, please use the 'tab' button, on your keyboard)</p>
  </fieldset>
  </form>

 

This is update_Ac.php;

<? 
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
?>
<?php
$host="localhost"; 
$username="designby_x";
$password="password";
$db_name="designby_x"; 
$tbl_name="members";

$name=$_POST['name'];
$pass=$_POST['pass'];
$email=$_POST['email'];

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="UPDATE $tbl_name SET name='$name', password='$pass', email='$email' WHERE username='$myusername'";
$result=mysql_query($sql);

if($result){
header("location:updated.php");
}

else {
header("location:editadminerror.php");
}

?>

 

Can anyone see the problem?

 

Cheers, Adam.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.