Jump to content

[SOLVED] help needed please


trilbyfish

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
      }
    }
  }

?>

Link to comment
Share on other sites

$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 ;D!

 

I shall be returning here in the future with various other problems im sure:D

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.