trilbyfish Posted March 1, 2008 Share Posted March 1, 2008 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: $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 $query = "SELECT * FROM bookingtable WHERE id =' . $row['id'] . '"; , but this gives the error 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. Quote Link to comment Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 $id = mysql_real_escape_string($_POST['id']); // <-- if your user is using a from, the id will be in the post array. $query = "SELECT * FROM bookingtable WHERE id = $id"; Quote Link to comment Share on other sites More sharing options...
trilbyfish Posted March 1, 2008 Author Share Posted March 1, 2008 Thanks for the help, but i get the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Query: SELECT * FROM bookingtable WHERE id = which is strange, when there isnt anything on line 1, apart from <?php edit: maybe its because on the previous page the user clicks on a link, which has the id on the end. Quote Link to comment Share on other sites More sharing options...
Ads Posted March 1, 2008 Share Posted March 1, 2008 $id = $_GET['id']; Try that instead of $_POST['id] Quote Link to comment Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 If the value is comming from a link it will be within the $_GET array, not post. Also, you should be checking this value exists well before it gets to your query, your leaving your app wide open otherwise. The syntax should be something like.... <?php if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM bookingtable WHERE id = $id"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // do what you like with the result. } } } ?> Quote Link to comment Share on other sites More sharing options...
trilbyfish Posted March 1, 2008 Author Share Posted March 1, 2008 $id = $_GET['id']; Try that instead of $_POST['id] If the value is comming from a link it will be within the $_GET array, not post. Also, you should be checking this value exists well before it gets to your query, your leaving your app wide open otherwise. The syntax should be something like.... <?php if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM bookingtable WHERE id = $id"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // do what you like with the result. } } } ?> BRILLIANT Thank You ;D! I shall be returning here in the future with various other problems im sure:D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.