插入数据库错误

时间:2015-10-30 19:03:37

标签: php mysql

每当我输入我的详细信息并提交查询时都会给我一个错误

INSERT INTO `temp_user_detail` (`email`, `username`, `profession`, 
`experience`, `current_work`, `state`, `job_type`, `about`, `college`, 
`diploma`, `department`, `looking`) VALUES 
('mailmeabhishek95@gmail.com', 'abhinift2014', 'nj', 'Less than 2 
years', 'Home', 'Kerala', 'Fixed Term', 'hii', 'Arch Academy Of Design', 
'Bachelor's Of Fashion Technology', 'Lifestyle Design', 'Work')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 's Of Fashion 
Technology', 'Lifestyle Design', 'Work')' at line 1

这是php部分

 $hi= "INSERT INTO `temp_user_detail` (`email`, `username`, 
 `profession`, `experience`, `current_work`, `state`, `job_type`, 
 `about`, `college`, `diploma`, `department`, `looking`) VALUES 
('$email', '$userid1', '$profession', '$experience', '$current', 
'$state', '$jobtype', '$about', '$college', '$diploma', '$depart', 
'$looking')";
$run=mysql_query($hi)
or die(mysql_error());

2 个答案:

答案 0 :(得分:1)

mysql 已弃用 应改为使用mysqli

  

每当我输入我的详细信息并提交查询时都会给我一个错误

您需要撤消$diploma Bachelor's < - here 的单引号。您可以使用mysql_real_escape_string,即:

$diploma = mysql_real_escape_string($diploma);

mysqli使用:

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
...
$diploma = $mysqli->real_escape_string($diploma);
...

这里有一些examples

答案 1 :(得分:0)

将此PHP函数用于变量:

$email = mysql_real_escape_string($email);
$userid1 = mysql_real_escape_string($userid1);

... 和

$hi= "INSERT INTO `temp_user_detail` (`email`, `username`, 
 `profession`, `experience`, `current_work`, `state`, `job_type`, 
 `about`, `college`, `diploma`, `department`, `looking`) VALUES 
($email, $userid1, $profession, $experience, $current, 
$state, $jobtype, $about, $college, $diploma, $depart, $looking)";