Forum Moderators: coopster
edit.php
<?php
include("security.php");
include("config.php");
$result=mysql_query("select * from members");
while($row=mysql_fetch_assoc($result)){
echo "ID : $row[userid] ";
echo "Name : $row[lastname] ";
echo "Email : $row[email] ";
echo "Tel : $row[phone] ";
echo '<a href="update.php?userid='.$row[userid].'">Update</a><hr>';
}
mysql_close();
?>
----
update.php
<?php
include("security.php");
include("config.php");
if($_POST['Submit']){
$userid=$_POST['userid'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$phone=$_POST['phone'];
mysql_query("update members set lastname='$lastname', email='$email', phone='$phone', where userid='$userid'");
header("location:edit.php");
exit;
}
$userid=$_GET[userid];
$result=mysql_query("select * from members where userid='$userid'");
$row=mysql_fetch_assoc($result);
mysql_close();
?>
<html>
<body>
<form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF;?>">
<input type="text" name="userid" id="userid" value="<?php echo $row['userid'] ;?>"/>
<p>Name :
<input name="name" type="text" id="lastname" value="<?php echo $row['lastname'];?>"/>
<br />
Email :
<input name="email" type="text" id="email" value="<?php echo $row['email'];?>"/>
<br />
Tel :
<input name="tel" type="text" id="phone" value="<?php echo $row['phone'];?>"/>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
you have one comma there which you do not need to start with:
//mysql_query("update members set lastname='$lastname', email='$email', phone='$phone' where userid='$userid'");
And this is how I could have done it:
mysql_query("UPDATE members SET lastname='". $lastname ."', email='". $email ."', phone='". $phone ."' WHERE userid='". $userid ."'");
Habtom
Thanks for responding.
When I removed the extra comma, the update would leave the fields of lastname and phone completely blank.
Next, I tried your code. The same thing happened. I then realized I was able to update the email field, which again showed me there was something wrong with the lastname and phone fields. I then changed the input names in the form to lastname and phone (instead of name and tel) and everything now works.
Thank you so much for helping me!