Jump to content


Photo

Forms and editing mysql data


  • Please log in to reply
4 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 04 August 2006 - 11:17 AM

Hello guys,
Can someone take a look at my code and point me in the right direction? I'm reading through various tutorials on the web and trying to make my own pages to edit data in a MySQL database. The page before this one brings up a list of names and when the user clicks on one it opens the page below with a variable called "id" specifying which record to show.


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

?>



When I run this page I get the following error:

Parse error: parse error, unexpected '<' in D:\Intranet v3\php_Telephone_List\Edit_SpecificPerson.php on line 16

line 16 is the line beginnning "<form action=......."

Any help with this would be greatly appreciated as I'm just stuck at the moment!
Cheers.
"Whats wrong with the cat?" - Mrs Schrödinger

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 04 August 2006 - 11:35 AM

You 'closed' the php section in the wrong place. Try this:

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

Legend has it that reading the manual never killed anyone.
My site

#3 onlyican

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

Posted 04 August 2006 - 11:52 AM

also, $id needs to be in single quotes
$result = mysql_query("SELECT * FROM tbl_telephonenumbers WHERE id = '".$id."'");

(Dont need the link identifier if its the only connection)
(Just makes the code look cleaner escaping out of the string for vars, nothing more)
Tell me the problem, I will try tell you the solution

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 August 2006 - 01:18 PM

The variable $id only needs to be in quotes if it is not defined as a number in the DB.

Ken

#5 onlyican

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

Posted 04 August 2006 - 01:57 PM

who the F told you that

I have a table, called prods
and a column called name

If I run a query in MySQL-Front
SELECT * FROM prods WHERE name = Product;
Then I get error
Unknown Column Product in WHere Clause

If I Run Query
SELECT * FROM prods WHERE name = 'Product';
I get the result

Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users