help needed please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
trilbyfish
Forum Newbie
Posts: 2
Joined: Fri Feb 29, 2008 5:44 pm

help needed please

Post by trilbyfish »

i am doing a booking system, and currently trying to code a page where the user clicks on a row to edit, and the relevent row comes up on another page so that it can be edited.

at the moment i am trying to do the sql which selects the relevent row from the mysql database.

this code:

Code: Select all

$query = "SELECT * FROM bookingtable WHERE id = 1";
works but only selects the first row where the id is 1, but i want it so that it selects the id of the row that was clicked on in the previous page.

the page this is on allready is http://*******.com/********/**********/editbay.php?id=9, so the page knows which id link was clicked on in the previous page.

the code i am thinking of is something along the lines of

Code: Select all

$query = "SELECT * FROM bookingtable WHERE id =' . $row['id'] . '";
, but this gives the error

Code: Select all

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
Please help me, i know this might be a bit incoherent but i would be very greatful if someone could help me to get this working, and then i could move on to the next thing.

Thanks in advance.
User avatar
Sekka
Forum Commoner
Posts: 91
Joined: Mon Feb 18, 2008 10:25 am
Location: Huddersfield, West Yorkshire, UK

Re: help needed please

Post by Sekka »

Firstly, are you wanting to pass the ID on the end of the URL into the query? If so, you need to use the $_GET array. Secondly, you need to escape variables in the MySQL string for security. I will do both below for you.

Now, on to your problem. Try the following,

Code: Select all

$query = "SELECT * FROM bookingtable WHERE id = " . mysql_real_escape_string ($_GET['id']);
Post Reply