By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

PHP newb needing help.

P: 1
I need help here, I am trying to learn PHP and MySQL and have run into some trouble. I have written this page to update records in my database, and cannot get the page to load. It just comes up a blank page. All the other paged I have written come up fine. I have fixed all the errors in my error.log, so what am I doing wrong here? The code is:

[PHP]
<html>
<head>
</head>
<body>
<?php

$id='$_GET[id]';
$username="******";
$password="******";
$database="******";

mysql_connect('localhost',$username,$password);

$query="select * from contacts where id='$id'";

$result="mysql_query($query)";
$num="mysql_numrows($result)";
$i=0;
while($i < $num){
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");

mysql_close();

?>


<form action="update.php" method="post">
<input type="hidden" name="ud_id" value="<?php echo $id; ?>">
First Name: <input type="text" name="ud_first" value="<?php echo $first; ?>"><br>
Last Name: <input type="text" name="ud_last" value="<?php echo $last; ?>"><br>
Phone Number: <input type="text" name="ud_phone" value="<?php echo $phone; ?>"><br>
Mobile Number: <input type="text" name="ud_mobile" value="<?php echo $mobile; ?>"><br>
Fax Number: <input type="text" name="ud_fax" value="<?php echo $fax; ?>"><br>
E-mail Address: <input type="text" name="ud_email" value="<?php echo $email; ?>"><br>
Web Address: <input type="text" name="ud_web" value="<?php echo $web; ?>"><br>
<input type="Submit" value="Update">

<?php
++$i;
}
?>
</body>
</html>
[/PHP]

Don't laugh too hard, its just thrown together because I am trying to learn. :)
Thanks for any help in advance!
May 6 '07 #1
Share this Question
Share on Google+
1 Reply


pbmods
Expert 5K+
P: 5,821
This line:

[PHP]
mysql_close();
[/PHP]
gets executed before the loop finishes. Try removing that line or moving it to the end of the file.
May 7 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.