简体   繁体   中英

update in php and sql

i have this function

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());    
}

but an error appears "Syntax error near 'street , category = informatique , date = 01/07/2013 , description = nothing' "

  1. why i have this error ?
  2. how to fix it?

You need to use single quotes around strings. Below I assume that all your columns are some string type. You also need to stop using mysql_ functions immediately as they are officially deprecated . See the red box ? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which.

$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'";

I guess the problem is because of you didn't use single quotations in set clause for non-numeric values.
try this one:

$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 ";

you may also want to check your variable values to remove possible single quotations or use addslashes function to make the query safe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM