-1

我有这个功能

function update_job($title, $type, $salary, $country,
                    $city, $state, $category,$date,
                    $description, $responsabilities,
                    $requirements, $id_job ) {

  $HOST_DB ="localhost";
  $NAME_DB="jobs";
  $USER_DB ="root";
  $PWD_DB="";

  $connect = mysql_connect($HOST_DB, $USER_DB, $PWD_DB);
  $db=mysql_select_db($NAME_DB);    

  $requete_insert_tem = "UPDATE employment  SET title = $title , type = $type , salary = $salary , country = $country , city = $city , state = $state , category = $category , date = $date , description = $description , responsabilities = $responsabilities ,
                requirements = $requirements where id = $id_job ";
  mysql_query($requete_insert_tem)
    or die(mysql_error());    
}

但出现错误“'street, category = informatique, date = 01/07/2013, description = nothing'附近的语法错误”

  1. 为什么我有这个错误?
  2. 如何解决?
4

2 回答 2

1

您需要在字符串周围使用单引号。下面我假设您的所有列都是某种字符串类型。您还需要mysql_立即停止使用函数,因为它们已被正式弃用。看到红框了吗?改为了解准备好的语句,并使用PDOMySQLi -本文将帮助您决定使用哪个。

$requete_insert_tem = "UPDATE employment SET title = '$title' , type = '$type' , salary = '$salary' , country = '$country' , city = '$city' , state = '$state' , category = '$category' , date = '$date' , description = '$description' , responsabilities = '$responsabilities' , requirements = '$requirements' where id = '$id_job'";
于 2013-01-02T20:04:23.460 回答
1

我想问题是因为您没有在 set 子句中对非数字值使用单引号。
试试这个:

$requete_insert_tem  ="UPDATE employment  SET title = '$title' , type = '$type' , salary = '$salary' , country = '$country' , city = '$city' , state = '$state' , category = '$category' , date = '$date' , description = '$description' , responsabilities = '$responsabilities' ,
                requirements = '$requirements' where id = $id_job ";

您可能还想检查变量值以删除可能的单引号或使用 addlashes 函数来确保查询安全。

于 2013-01-02T20:09:52.230 回答