Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Mysql syntax problem, prob simple
Old 01-18-2008, 04:09 PM PHP Mysql syntax problem, prob simple
Experienced Talker

Posts: 36
Trades: 0
Code:
$sql = "UPDATE machines SET oil_pr='$_REQUEST['en_oil_pr']' WHERE id='$_REQUEST['machid']'";
mysql_query($sql);
Getting this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
nlassiter is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-18-2008, 05:29 PM Re: PHP Mysql syntax problem, prob simple
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Because when you use an array syntax, either you need to enclose it between {}, or you need to declare it outside the string:
PHP Code:
$sql "UPDATE machines SET oil_pr='{$_REQUEST['en_oil_pr']}' WHERE id='{$_REQUEST['machid']}'";
mysql_query($sql); 
or
PHP Code:
$sql "UPDATE machines SET oil_pr='".$_REQUEST['en_oil_pr']."' WHERE id='".$_REQUEST['machid']."'";
mysql_query($sql); 
And on a side note, it's a very bad idea to pass $_REQUEST parameters like that directly from the page call.
I seriously hope you sanitize the values in your array before sending them to the db...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-18-2008, 05:59 PM Re: PHP Mysql syntax problem, prob simple
Experienced Talker

Posts: 36
Trades: 0
oh, sanitize the values of what?
nlassiter is offline
Reply With Quote
View Public Profile
 
Old 01-18-2008, 06:34 PM Re: PHP Mysql syntax problem, prob simple
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Of $_REQUEST['en_oil_pr'] and$_REQUEST['machid']
If someone forge the page query simply adding
PHP Code:
http://www.site.com/update.php?en_oil_pr=test&machid=1';drop table machines; 
If you have not sanitized your variables, you will send a query like this:
PHP Code:
UPDATE machines SET oil_pr='test' WHERE id='1';drop table machines
which are 2 correct sql statements for the db, and those will result in the loss of the machines table.

It's called SQL injection, and believe me, it's very common.
I see dozens of tries on my server every days...

The rule: don't use $_REQUEST/$_POST nor $_GET directly in a query.
If machid is an id, it should be numeric, so test it before:
PHP Code:
$machid=$_REQUEST['machid'];
if(!
is_numeric($machid)){
  die(
'wrong record id');

and so on...
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 01-18-2008 at 06:35 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-18-2008, 11:20 PM Re: PHP Mysql syntax problem, prob simple
Experienced Talker

Posts: 36
Trades: 0
Thank you for the detailed response. This particular script is used by only a handful of people I work with so security is not a problem because it will be run locally. I will definitly keep this in mind for the future.
nlassiter is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Mysql syntax problem, prob simple
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.15657 seconds with 12 queries