Jump to content

Archived

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

Fearpig

Edit Database through PHP

Recommended Posts

Hi Guys,
Can anyone help me with the following?

I'm trying to set up a PHP page where you can edit data stored in an SQL table. Here's my code...

<?php
$db = mysql_connect("localhost", "root", "password");
$id = $_GET['id'];
mysql_select_db("Telephonelist",$db);
$result = mysql_query("SELECT * FROM tbl_telephonenumbers WHERE ID='$id'",$db);
?>

<form action="Submit_SpecificPerson.php" method="post">
<INPUT TYPE="HIDDEN" NAME="ID" VALUE="<?php echo $myrow["ID"] ?>"><br> 
<INPUT TYPE="TEXT" NAME="First_Name" VALUE="<?php echo $myrow["First_Name"] ?>" SIZE=30><br>
<INPUT TYPE="TEXT" NAME="Last_Name" VALUE="<?php echo $myrow["Last_Name"] ?>" SIZE=30><br>
<INPUT TYPE="TEXT" NAME="Role" VALUE="<?php echo $myrow["Role"] ?>" SIZE=30><br>
<input type="Submit" value="Update">
</form>

The page before passes through the 'id' variable and this page should populate three text boxes with the values stored in the database. The problem is that when I get to this page the textboxes only have the following error message:

<br /><b>Notice</b>:  Undefined variable: myrow in <b>D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php</b> on line <b>17</b><br />

With a different line in each textbox (lines 15, 16 and 17). If anyone can spot where I'm going wrong I'd be very grateful.

Cheers
Tom

Share this post


Link to post
Share on other sites
I just copied that code and pasted DW
Commented out the MySQL Queries ect

Saved
No problems, no errors no nothing

Share this post


Link to post
Share on other sites
I'm sorry... I don't understand.... ???

Could you repost the code and show me how you got no errors.

Share this post


Link to post
Share on other sites
all i see no while loop?

[code]
<?php
$db = mysql_connect("localhost", "root", "password");
$id = $_GET['id'];
mysql_select_db("Telephonelist",$db);
$result = mysql_query("SELECT * FROM tbl_telephonenumbers WHERE ID='$id'",$db);
while($myrow=mysql_fetch_assoc($result)){
?>

<form action="Submit_SpecificPerson.php" method="post">
<INPUT TYPE="HIDDEN" NAME="ID" VALUE="<?php echo $myrow["ID"] ?>">
 
<INPUT TYPE="TEXT" NAME="First_Name" VALUE="<?php echo $myrow["First_Name"] ?>" SIZE=30>

<INPUT TYPE="TEXT" NAME="Last_Name" VALUE="<?php echo $myrow["Last_Name"] ?>" SIZE=30>

<INPUT TYPE="TEXT" NAME="Role" VALUE="<?php echo $myrow["Role"] ?>" SIZE=30>

<input type="Submit" value="Update">
</form>

<?}?>

[/code]

Share this post


Link to post
Share on other sites
i think you should declare the $my_row variable first.
and intead of putting the database info in the $result variable you could put it in the $my_row variable

Share this post


Link to post
Share on other sites
Doh!

Thank you guys I think the process of writing it out again unblocked something and I managed to work it out. It was that I was just missing the line:

$myrow = mysql_fetch_array($result)

Which should be at the start where I declare my variables.

Cheers for your help.

Share this post


Link to post
Share on other sites

×

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.