check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

橙三吉。 提交于 2019-12-23 18:04:30

问题


<?php
if(isset($_POST["submit"])) ..this is form action 
{
$result3 = mysql_query("SELECT * FROM 'members' where user='$user'");
while($row3 = mysql_fetch_array($result3))
{ 
$name=$row3['name'];
$user=$row3['user'];
$number=$row3['number'];
}
$numrows=mysql_num_rows($query);
if($numrows==0)
{
$sql="INSERT INTO 'applicant' (user,name,number,) VALUES('$user','$name','$number')";
$result=mysql_query($sql);
if($result){
header('Location: thankyou2.php');
} else {
echo "Failure!";
}
}
}
else
{


$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "abcdef";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or    die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
$JobID=$_GET['JobID'];
$job_sql="SELECT * FROM job WHERE JobID=$JobID";
$job_query = mysql_query($job_sql) or die(mysql_error());
$rsjob=mysql_fetch_assoc($job_query);
};
?>
<b><center><table class="bordered"> 

( Data will fetch in this table by GET method )

<thead>
<?php echo $rsjob['jobname'];?></h1></font>
<tr>       
    <th><font face="Script MT">Description</th>
    <th><font face="Script MT">Details</th>
</tr>
</thead>
<tr>
        <td>Name</td>
         <td><?php echo $rsjob['jobname'];?></td>
</tr>        
<tr>

    <td>Type</a></td>
    <td><?php echo $rsjob['type'];?></td>
</tr>
</table><br>

<?php
if ($loggedin)
{
echo 
<<<_END
<form action="job.php" method="POST" name="jobapply">  
<input type="checkbox" name="termscondition"        required/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I have read all the 
<a href="termscondition.html">Terms and Condition</a><br>  
<br><input type="submit" value="Apply"></form> 
_END;
}
else 
{

       echo '<center> please sign up and/or log in to   <strong>Apply</strong>.</center>';

};
?>

On clicking submit button the user information get stored in applicant table in abcdef database. 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


回答1:


You seem to have an extra comma in you columns and your table name in quotes, try changing this line:

$sql="INSERT INTO 'applicant' (user,name,number,) VALUES('$user','$name','$number')";

To this

$sql="INSERT INTO applicant (user,name,number) VALUES('$user','$name','$number')";

I believe the issue is here (user,name,number) and here 'applicant'




回答2:


Try removing the quote marks from the table names so for example:

$result3 = mysql_query("SELECT * FROM 'members' where user='$user'");

becomes:

$result3 = mysql_query("SELECT * FROM members where user='$user'");


来源:https://stackoverflow.com/questions/31240873/check-the-manual-that-corresponds-to-your-mysql-server-version-for-the-right-syn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!