-2
include("db_connector.php");
    $soru = "asdasds";
    $tip = 1;
    $soruId = 0;

        $sql = "insert into 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 an error like this : Unknown column 'asdasds' in 'field list'

0

2 Answers 2

3

You need to change the SQL statement in this:

$sql = "INSERT INTO `sor` (anketId,soruMetni,tip) 
        VALUES ('".$_SESSION['anket']."','".$soru."',".$tip.")";

Strings needs to be encapsulated with a single quote. :)

0

I just add ' before and after every variable in query. You cannot pass string to query without adding single quote '.

Change From:

$sql = "insert into sor (anketId,soruMetni,tip) values (".$_SESSION['anket'].",".$soru.",".$tip.")";

to :

$sql = "INSERT INTO `sor` (anketId,soruMetni,tip) 
        VALUES ('".$_SESSION['anket']."', '".$soru."', '".$tip."')";
4
  • thank you man problem solved :) Jul 27, 2015 at 11:28
  • @BatuhanGÜNGÖR please accept my answer if you found it useful.
    – Hassaan
    Jul 27, 2015 at 11:29
  • I will... 8 min later :) this is a proc Jul 27, 2015 at 11:31
  • @BatuhanGÜNGÖR sure :)
    – Hassaan
    Jul 27, 2015 at 11:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.