Php mysql query syntax error (Unknown field) -
this question has answer here:
include("db_connector.php"); $soru = "asdasds"; $tip = 1; $soruid = 0; $sql = "insert sor (anketid,sorumetni,tip) values (".$_session['anket'].",".$soru.",".$tip.")"; $islem = mysql_query($sql)or die(mysql_error());; if(isset($islem)) { $soruid = mysql_insert_id(); }else { header("refresh:2;sorular.php"); }
this code give error : unknown column 'asdasds' in 'field list'
i add '
before , after every variable in query. cannot pass string query without adding single quote '
.
change from:
$sql = "insert sor (anketid,sorumetni,tip) values (".$_session['anket'].",".$soru.",".$tip.")";
to :
$sql = "insert `sor` (anketid,sorumetni,tip) values ('".$_session['anket']."', '".$soru."', '".$tip."')";
Comments
Post a Comment