-2

What is this error in MYSQL statment

mysqli_query($con,"INSERT INTO stores(name, store_type, hours, rating_txt, rating_star, address_id) VALUES (".$name.",".$store_type.",".$hours.",".$rating_text.",".$rating_star.",".$address_count.")"))

2 Answers2

1

variable need to be inside single quotes.

change ".$name."

into

'".$name."' or or '.$name.' or '$name'

Vickel
  • 7,879
  • 6
  • 35
  • 56
  • I'd go for the one without dots. They're so over-rated – Strawberry Apr 06 '14 at 23:49
  • @Strawberry sure, just to show the 3 possibilities – Vickel Apr 06 '14 at 23:51
  • INSERT INTO stores(name, store_type, hours, rating_txt, rating_star, address_id) VALUES ('$name','$store_type','$hours','$rating_text','$rating_star','$address_count')") -- is this correct??? – vinodh Barnabas Apr 06 '14 at 23:59
  • INSERT INTO stores( name, store_type, hours, rating_txt, rating_star, address_id) VALUES ('$name', '$store_type', '$hours', '$rating_text', '$rating_star', '$address_count') – Vickel Apr 07 '14 at 00:11
  • @ Vickel that seems to sorted but i am getting syntax error on $mysql_query in this statement.... $result = $mysqli_query($con,"SELECT COUNT(*) AS addressCount from address"); $row = $result->fetch_assoc(); $address_count=$row['addressCount']; what i really want is the count number....can't believe life is so difficult, for such a simple thing...lol – vinodh Barnabas Apr 07 '14 at 00:14
  • @vinodhBarnabas check this page: http://stackoverflow.com/questions/16257217/php-mysqli-how-do-i-count-query-result-rows – Vickel Apr 07 '14 at 00:28
  • I got it done using mysqli_insert_id($con) – vinodh Barnabas Apr 07 '14 at 00:54
0

You should sanitize your input values, i.e. use prepared statements.
If you only use mysqli_real_escape_string for sanitizing you need to quote (most) values.
You've got one closing bracket too much.

VMai
  • 10,156
  • 9
  • 25
  • 34