Jump to content


Photo

Help with database update


  • Please log in to reply
1 reply to this topic

#1 cjacks

cjacks
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 May 2006 - 12:57 PM

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>
<?

}

?>

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 03:44 PM

you expect help when:

a) you didn't bother to be clear as to what your script is doing , versus what you want it to be doing.

b) you didn't bother to list any errors.

c) you didn't bother to post your code in the code tags, specifying what parts of that are what files etc...


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users