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
https://forums.phpfreaks.com/topic/93784-solved-help-needed-please/
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.

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

?>

$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

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.