Jump to content

Forms and editing mysql data


Fearpig

Recommended Posts

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.


[b]<?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>

?>[/b]


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

[b]line 16 is the line beginnning "<form action=......."[/b]

Any help with this would be greatly appreciated as I'm just stuck at the moment!
Cheers.
Link to comment
https://forums.phpfreaks.com/topic/16534-forms-and-editing-mysql-data/
Share on other sites

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

[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"] ?>"> 
<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]
also, $id needs to be in single quotes
[code=php:0]
$result = mysql_query("SELECT * FROM tbl_telephonenumbers WHERE id = '".$id."'");
[/code]

(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)
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

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.