Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi
I have error in my project
this error comes
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


when
I make a list in aa.php
then get sID in advisor.php

inside 2 files
first: aa.php
PHP
        $db_name="coop";
        $tbl_name="students";
        mysql_connect("localhost", "root", "");
        mysql_select_db("$db_name");
        session_start();
$tID=$_SESSION['tID'];
        $sql=mysql_query("SELECT * FROM $tbl_name WHERE advisor=$tID") or die(mysql_error());
        while($mysqlf =mysql_fetch_array($sql))
        {
            $student=$mysqlf['sname'];
            //echo "$student &nbsp&nbsp&nbsp";
            $sid=$mysqlf['sID'];
            //echo"$sid<br>";
            echo "<center></font><a href='advisor.php?students=$student'>".$mysqlf['sname']."</a>&nbsp;&nbsp;&nbsp;&nbsp;".$mysqlf['sID']."</label>";
        }?>


second: advisor.php
PHP
    $sID = $_GET['students'];
    $db_name="coop";
        $tbl_name="students";
        mysql_connect("localhost", "root", "");
        mysql_select_db("$db_name");
        $sql=mysql_query("SELECT sID FROM ".$tbl_name." WHERE sID=.$sID.") or die(mysql_error());
        $mysqlf =mysql_fetch_array($sql);
            $sID=$mysqlf['sID'];
            echo "$sID<br>";;
?>


how can I solve this problem?

thanks for all
Posted
Updated 25-May-11 17:03pm
v3
Comments
Orcun Iyigun 25-May-11 20:15pm    
There are two reasons for this:

1-The command that you are trying to execute doesn't have a valid syntax.

2-There is a mismatched data that query that you have. Like an inter value on string value or vice-a-versa.

also try deactivating your bulletins.
ZeeroC00l 25-May-11 22:30pm    
-- edited pre tag

1 solution

Either $tbl_name, $tID $sID is empty and have no value or the value is not valid for SQL statement.

The line
PHP
$sql=mysql_query("SELECT sID FROM ".$tbl_name." WHERE sID=.$sID.") or die(mysql_error());


Has to be changed to
PHP
$sql=mysql_query("SELECT sID FROM ".$tbl_name." WHERE sID=".$sID) or die(mysql_error());
 
Share this answer
 
Comments
malemar 26-May-11 4:56am    
when I change this line
$sql=mysql_query("SELECT sID FROM ".$tbl_name." WHERE sID=.$sID.") or die(mysql_error());
to this
$sql=mysql_query("SELECT sID FROM ".$tbl_name." WHERE sID=".$sID) or die(mysql_error());
appear this line an page
Unknown column 'Abrar_Saad_Al' in 'where clause'
and also
this name "Abrar_Saad_Al" inside the data base is like this "Abrar_Saad_Al-Rifaes"
Kim Togo 26-May-11 5:06am    
I think the error "Unknown column", has nothing to do with the change in SQL statement. There is not reference to "Abrar_Saad_Al" column in the SELECT statement.

I think the error is farther down the PHP file.
malemar 26-May-11 5:23am    
I also think the error in the query

did you thing there are anther solution??

thank you Kim Togo

Kim Togo 26-May-11 5:38am    
The line

$sql=mysql_query("SELECT sID FROM ".$tbl_name." WHERE sID=".$sID) or die(mysql_error());

Does not have any relation to column "Abrar_Saad_Al".
Is there other SQL statements in the PHP file that requires column "Abrar_Saad_Al" ?
malemar 26-May-11 5:40am    
loooooooool
I solved it
thanks Mr. Kim Togo

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900