Jump to content


Photo

Edit Database through PHP


  • Please log in to reply
5 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 10 August 2006 - 10:57 AM

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
"Whats wrong with the cat?" - Mrs Schrödinger

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 10 August 2006 - 11:07 AM

I just copied that code and pasted DW
Commented out the MySQL Queries ect

Saved
No problems, no errors no nothing
Tell me the problem, I will try tell you the solution

#3 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 10 August 2006 - 11:16 AM

I'm sorry... I don't understand.... ???

Could you repost the code and show me how you got no errors.
"Whats wrong with the cat?" - Mrs Schrödinger

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 August 2006 - 11:20 AM

all i see no while loop?

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

<?}?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 Silverado_NL

Silverado_NL
  • Members
  • PipPipPip
  • Advanced Member
  • 105 posts
  • LocationZaandam (Netherlands)

Posted 10 August 2006 - 11:24 AM

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
The Force is like ductape, it has a light side, it has a dark side, and it combines the universe together!

#6 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 10 August 2006 - 11:30 AM

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.
"Whats wrong with the cat?" - Mrs Schrödinger




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users