0

Can someone help me to fix this query? I dont know what error i have made. Please help me out..

insert into docs values('"$_POST['inputString']"','"$_POST['inputStringa']"','"$_POST['inputStringa1']"','"$_POST['inputStringa2']"','"$_POST['inputStringa3']"','"$_POST['inputStringa4']"')" ;
Nikita Rybak
  • 67,365
  • 22
  • 157
  • 181
jeni
  • 973
  • 4
  • 18
  • 32
  • Please show any errors you get and the actual, generated SQL query. And your query is vulnerable to [SQL injection](http://stackoverflow.com/questions/4749588/protect-against-sql-injection) – Pekka Jan 28 '11 at 09:54
  • maybe it's time to accept an answer! otherwise you won't get much help for your next question – Christophe Apr 05 '11 at 10:24

4 Answers4

4

Your quotes are not right. Single quotes and double quotes are getting mixed up. Do it like this:

mysql_query("insert into docs
values('{$_POST['inputString']}','{$_POST['inputStringa']}',
'{$_POST['inputStringa1']}','{$_POST['inputStringa2']}',
'{$_POST['inputStringa3']}','{$_POST['inputStringa4']}')") ;

Also, remember to pass through all the POST variables through mysql_real_escape_string like this:

$_POST['inputString'] = mysql_real_escape_string($_POST['inputString']);

Do this BEFORE running the query.

shamittomar
  • 46,210
  • 12
  • 74
  • 78
3

Read the PHP manual entry on strings and learn the basic syntax, you'll discover why this code doesn't work:

http://php.net/manual/en/language.types.string.php

Dan Grossman
  • 51,866
  • 10
  • 112
  • 101
2

you are missing "." in the query

$sql = "INSERT INTO docs VALUES('".$_POST['inputString']."','".$_POST['inputStringa']."','".$_POST['inputStringa1']."','".$_POST['inputStringa2']."','".$_POST['inputStringa3']."','".$_POST['inputStringa4']."')";

or use

for remove vulnerablities

mysql_query("insert into docs values ( ' { $_POST['inputString'] }' ,'{$_POST['inputStringa']}',' {$_POST['inputStringa1']}','{$_POST['inputStringa2']}',
'{$_POST['inputStringa3']}','{$_POST['inputStringa4']}')") ;
Pradeep Singh
  • 3,582
  • 3
  • 29
  • 42
1

you use both single quote and double quotes, you cant do that. You need to concatenate the post values like so:

$sql = "INSERT INTO docs VALUES('".$_POST['inputString']."','".$_POST['inputStringa']."','".$_POST['inputStringa1']."','".$_POST['inputStringa2']."','".$_POST['inputStringa3']."','".$_POST['inputStringa4']."')";

mysql_query($sql);
Christophe
  • 4,798
  • 5
  • 41
  • 83