-1

Can someone please help me what is wrong with this syntax. when i run this, it doesn't insert the values into the table.

Currently all the variables e.g $land, etc have a value. in my database table, all except $nOwners,$id(int) are defined as varchar, .

Details: I am using Mysqli

$sql= "INSERT into property_list (id, title_no, status, register_type, type,land_district, issue_date,guarantee_status,provisional,title_no_srs,title_no_head_srs, survey_reference, Maori_land, number_owners) 
       VALUES($id,'$title', '$status', '$register', '$type', '$land', '$issue_date', '$guarantee', '$provision', '$title_no_srs','$head_srs', '$survery', '$maori', $nOwners)"; 


if($conn->query($sql)!==false)
{
    $flag=false;
    echo "successfully inserted ";
}
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • [Obligatory](http://bobby-tables.com/). – Amadan Sep 19 '15 at 01:35
  • ^ obligatory? where's this written? I don't remember signing a contract ;-) ...or, did I? – Funk Forty Niner Sep 19 '15 at 01:36
  • In my mind. Every time someone commits the crime of not escaping variables and not using prepared statements, Bobby Tables must be linked. It is a law. – Amadan Sep 19 '15 at 01:37
  • 2
    Your code may contain syntax errors of you've something that MySQL may be complaining about. Consult these following links http://php.net/manual/en/mysqli.error.php and http://php.net/manual/en/function.error-reporting.php and apply that to your code. – Funk Forty Niner Sep 19 '15 at 01:38
  • to be fair(i know this is unlike me) as we don't see what happens to the variable before the query, they could all be sanatised –  Sep 19 '15 at 01:39
  • Plus, looking at all those columns and variables, I didn't go in and count those. If there's a column mismatch count, well there you go. – Funk Forty Niner Sep 19 '15 at 01:40
  • Print the SQL statement after variable substitution. 95% of the time,the answer is then obvious. – Gordon Linoff Sep 19 '15 at 01:46
  • *"Details: I am using Mysqli"* - Ok and what about your connection? – Funk Forty Niner Sep 19 '15 at 01:47
  • It does connects to my database. – mindbender freethinker Sep 19 '15 at 01:52
  • echo out `$sql`. Assuming you even get that far – Drew Sep 19 '15 at 01:53
  • well then, no problem then. There's nothing more to see folks, carry on. – Funk Forty Niner Sep 19 '15 at 01:54
  • maybe we are talking past each other. It does connect to my database but it does not insert content/data into my table. the issue is with insert. – mindbender freethinker Sep 19 '15 at 01:56
  • 1
    ask the guy who's given you an answer below then. He seems to know more than I do. Good luck. Edit: Notice the upvote on my comment up there? that's a hint. – Funk Forty Niner Sep 19 '15 at 01:57
  • @mario - what reserved word is that which you closed the question with? I see `status` and `name` and `type`. Those are keywords, not reserved words. What am I missing or not grasping here? – Funk Forty Niner Sep 19 '15 at 02:02
  • @Drew I voted as "why it's not working", not the reserved word issue which it isn't. Mario and I both hold a gold for questions like that; notice the gold next to his name and not mine? ;-) there you go. Had I closed it with that, then my name would have the gold icon next to it. That's why my name also appears next to the dupe. – Funk Forty Niner Sep 19 '15 at 02:05
  • @Fred-ii- I just thought the unquoted column names most probable still, thus just closed it with that. It's as good a guess as any. (Only OP can tell if he bothered to follow the `mysqli_error` advise, or showed all relevant code and input values, table scheme etc.) – mario Sep 19 '15 at 02:15
  • can you edit the question, show error reporting info turned on (or not), show more of the php file. We can suggest an edit even if thru pastie – Drew Sep 19 '15 at 02:16
  • @mario Fair enough. The OP has been given enough information to debug their code. Ok... I am now heading for runway 1030, riding on 148 heavy. *ciao for now* – Funk Forty Niner Sep 19 '15 at 02:19

1 Answers1

-1

Hmm, the column name status might be an issue, it is a reserved keyword in sql. Try another name and see if that fixes it. https://www.drupal.org/node/141051

Adam Wolf
  • 309
  • 1
  • 4
  • 12