php - mysql help

Discussion in 'PHP' started by egjeff4, Apr 3, 2008.

  1. #1
    Hello,

    I am trying to right a select function in php to call from a mysql database:

    $sql= "SELECT * FROM `table` WHERE 'row' = '$name' " ;
    $result=mysql_query($sql) or die(mysql_error());


    I keep getting the 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 2

    i have tried removing the single quotes...changing which values has quotes, where the quote appears, but nothing works....

    any help would be greatly appreciated....

    Thanks in advance
     
    egjeff4, Apr 3, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Try changing ' to ` at the row part. Either use backticks for table and column names or use nothing.

    $sql= "SELECT * FROM `table` WHERE `row` = '$name' " ;

    or

    $sql= "SELECT * FROM table WHERE row = '$name' " ;
     
    jestep, Apr 3, 2008 IP
  3. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Try:

    
    $sql= "SELECT * FROM `table` WHERE `row` = '$name' ";
    
    PHP:
    As your $sql query line.

    Jay
     
    jayshah, Apr 3, 2008 IP
  4. egjeff4

    egjeff4 Active Member

    Messages:
    299
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #4
    thank you jestep......it worked...i appreciate the help...

    jayshah, i didnt try your code, since it worked i don't want to mess it up......but thank you as well...
     
    egjeff4, Apr 3, 2008 IP