Error in SQL Syntax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mary Meer
    New Member
    • Feb 2011
    • 5

    Error in SQL Syntax

    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 'FROM student WHERE name LIKE 'a%'' at line 1

    Could you help here is the query cannot figure out where the problem is
    Code:
    if(isset($_GET['n'])){
       $s=$_GET['n'];
    
    	$query="SELECT FROM student WHERE name LIKE '$s%'  ";
    	$result=mysql_query($query,$db) or die (mysql_error() );
    	echo $result;
    	$string='';
    	while($row = mysql_fetch_assoc($result)){
    	     $string.= $row['name'];
        }
          echo $string;
      }else{
         echo 'wrong GET keywoord';
    
    }//ifisset
    Last edited by Dormilich; Jun 9 '11, 02:48 PM. Reason: please use [CODE] [/CODE] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you forgot to define, what to select. e.g. SELECT `id` FROM `student`

    Comment

    • irfanmodan
      New Member
      • Jan 2011
      • 20

      #3
      you forgot to define column name, e.g. SELECT `name` FROM `student`

      Comment

      • Rekha Kumaran
        New Member
        • Jan 2011
        • 30

        #4
        U missed the column name in the select statement.
        SELECT * FROM student WHERE name LIKE '$s%' "

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          I think after the 2nd repetition the OP knows the solution now.

          Comment

          Working...