Reply
Using Safe-Mode Form Variables in mySQL Query
Old 07-27-2003, 07:23 AM Using Safe-Mode Form Variables in mySQL Query
Friend_Al_23's Avatar
Novice Talker

Posts: 9
Location: Philippines
I am in a safe mode, I think. Anyway, in order to receive form variables through post method, I have to use $_POST['variable_name'] in order to read that variable. But how do you do it when you want to include it in query? The code is written below:

PHP Code:
$result mysql_query("INSERT INTO mytable ('column1', 'column2') VALUES ($_POST['variable1'], $_POST['variable2']") or die ("Query Error: ".mysql_error()); 
The code above gives me an mySQL error stating that I should read the manual for the proper format. Isn't the above query in proper format already?
__________________
The Star Circle Quest Community
Friend_Al_23 is offline
Reply With Quote
View Public Profile Visit Friend_Al_23's homepage!
 
When You Register, These Ads Go Away!
Old 07-27-2003, 12:15 PM
david's Avatar
King Spam Talker

Posts: 1,314
Location: Glasgow, UK
How about:
PHP Code:
$result mysql_query("INSERT INTO mytable ('column1', 'column2') VALUES (".$_POST['variable1'].", ".$_POST['variable2']) or die ("Query Error: ".mysql_error()); 
__________________
Free Webmaster Help - Everything a webmaster needs - for free
Free-Webhosting.info - Free web hosts reviewed and rated
Web Hosting Hunt - Impartial hosting directory - Add your host today for FREE
david is offline
Reply With Quote
View Public Profile Visit david's homepage!
 
Old 07-27-2003, 12:29 PM
Experienced Talker

Posts: 33
Location: Portsmouth, UK
I don't think I need mention how unbelievably unsafe that code is regardless of how safe you think you are and how you really should do some preprocessing on the posted variables before throwing them at a sql query but I think the original problem was partly because you didn't close the parentheses after the second $_POST and before the double quotes:

PHP Code:
$result mysql_query("INSERT INTO mytable ('column1', 'column2') VALUES ($_POST['variable1'], $_POST['variable2']     )    ") or die ("Query Error: ".mysql_error()); 
neOnbubble is offline
Reply With Quote
View Public Profile Visit neOnbubble's homepage!
 
Reply     « Reply to Using Safe-Mode Form Variables in mySQL Query
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12068 seconds with 12 queries