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
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]
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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