Jump to content

Edit Database through PHP


Fearpig

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
Link to comment
https://forums.phpfreaks.com/topic/17116-edit-database-through-php/
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]
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.

Archived

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

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