the corect sintax

Post here if you need help with SQL.
Post Reply
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

the corect sintax

Post by ta2shop »

hy guys, i am playng with the browser identification thing, and i want to add some data to a DB, but a dont want to define everi thing in a new $var haw can i add the values in using just the $_POST['thing']; thing?
thanks.
$query = mysql_query("INSERT INTO brovsers VALUES('','$_POST['1']','$_POST['2']','$_POST['2']')") or die(mysql_error());
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: the corect sintax

Post by jacek »

Easiest way is to wrap them in {} like this ...
$query = mysql_query("INSERT INTO brovsers VALUES('','{$_POST['1']}','{$_POST['2']}','{$_POST['2']}')") OR die(mysql_error());
Bare in mine though that these variables need to be escaped ;)
Image
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: the corect sintax

Post by ta2shop »

jacek wrote:Easiest way is to wrap them in {} like this ...
$query = mysql_query("INSERT INTO brovsers VALUES('','{$_POST['1']}','{$_POST['2']}','{$_POST['2']}')") OR die(mysql_error());
Bare in mine though that these variables need to be escaped ;)
like so?
$query = mysql_query("INSERT INTO brovsers VALUES('','{$_POST['\1\']}','{$_POST['\2\']}','{$_POST['\2\']}')") OR die(mysql_error())
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: the corect sintax

Post by jacek »

There is no need for the \ but yeah pretty much like that.
Image
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: the corect sintax

Post by ta2shop »

ok, now i get it, one last thing, i now that to add the ip i need to do this $_SERVER['REMOTE_ADDR']; but how can i add the date(); thing to this query?
thanks

EDIT* all done, fixed.
Image
Post Reply