Jump to content

Help with database update


cjacks

Recommended Posts

I am having trouble getting this script to work.

I need it to retrieve a mysql record in to a form to allow users to update thier information. The update would be based on email and password entered on a diffrerent form, query sent to database, current results retrieved in to form that the user sees and can update from there. Any help on this greatly appreciated. I am sure it is basic for most of you, but I am not good with php at all. Thanks!

<?php

include("include/dbconnect.php");
$email = $_POST['email'];
$pword = $_POST['pword'] ;

if ( $email && $pword ) {
$result = mysql_query("SELECT * FROM $table WHERE email=$email",$db);
$myrow = mysql_fetch_array($result);

?>
<form method="post" action="update.php">

<table width="380" border="0" cellspacing="1" cellpadding="1">
<tr>
<td>
<input type="hidden" name="email" value="<?php echo $myrow["email"]?>">
Firstname:</td>
<td>
<input type="Text" name="firstname" size="35" value="<?php echo $myrow["firstname"]?>">
</td>
</tr>
<tr>
<td>Lastname:</td>
<td>
<input type="Text" name="lastname" size="35" value="<?php echo $myrow["lastname"]?>">
</td>
</tr>
<tr>
<td>Street:</td>
<td>
<input name="street" type="text" value="<?php echo $myrow["street"]?>" size="35">
</td>
</tr>
<tr>
<td>City:</td>
<td>
<input name="city" type="Text" id="city" value="<?php echo $myrow["city"]?>">
</td>
</tr>
<tr>
<td>State:</td>
<td>
<input name="state" type="Text" id="state" value="<?php echo $myrow["state"]?>">
</td>
</tr>
<tr>
<td>Zip:</td>
<td>
<input name="zip" type="Text" id="zip" value="<?php echo $myrow["zip"]?>">
</td>
</tr>
<tr>
<td>Telephone:</td>
<td><input name="home" type="text" id="home" value="<?php echo $myrow["home"]?>"></td>
</tr>
<tr>
<td>Email:</td>
<td>
<input type="Text" name="email" size="35" value="<?php echo $myrow["email"]?>">
</td>
</tr>
<tr>
<td>Password</td>
<td>
<input type="Text" name="pword" size="35" value="<?php echo $myrow["pword"]?>">
</td>
</tr>
<tr>
<td>Birthday (Day/Month/Year)</td>
<td>
<input name="bday" type="text" id="bday" value="<?php echo $myrow["bday"]?>" size="2" maxlength="2">
/
<input name="bmonth" type="text" id="bmonth" value="<?php echo $myrow["bmonth"]?>" size="2" maxlength="2">
/
<input name="byear" type="text" id="byear" value="<?php echo $myrow["byear"]?>" size="4" maxlength="4">
</td>
</tr>
</table>
<input type="Submit" name="update" value="Update information">
</form>

<?

$sql = "UPDATE $table SET firstname='$firstname',lastname='$lastname',street='$street',city='$city',state='$state',zip='$zip',email='$email',home='$home',bday='$bday',bmonth='$bmonth',byear='$byear',pword='$pword' WHERE email=$email";
$result = mysql_query($sql);
echo "<br><br>Address book updated.\n";

} elseif ($update); {

?>

<form method="post" action="<?php echo $PHP_SELF?>">

<table width="380" border="0" cellspacing="1" cellpadding="1">
<tr>
<td>

Email:</td>
<td>
<input name="email" type="Text" id="email" size="35">
</td>
</tr>
<tr>
<td>Passsword:</td>
<td>
<input name="pword" type="Text" id="pword" size="35">
</td>
</tr>
</table>
<input type="Submit" name="submit" value="Enter information">
</form>
<?

}

?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.