Page 1 of 1

$_REQUEST not working, please help

Posted: Thu Sep 24, 2009 8:04 am
by php_new_guy_09
Hi guys, i have a php script that seems to be working fine when i insert normal values into line 7, 8, 10, 17 however, when i try to use $_REQUEST then nothing happens?

here is my code

Code: Select all

$address = "localhost";
$uname = "my username"; 
$pword = "my password"; 
$database="my database"; 
 
//Incoming Variables
$sender = $_REQUEST['sender'];
$content = $_REQUEST['content'];
 
$selectednums = $sender; //Set selected numbers to sender.
 
//DB Connect
mysql_connect($address,$uname,$pword) or die("Cannot connect to database"); //Connect to database, warn if cannot connect
mysql_select_db($database) or die("Cannot Select Database");
 
//Insert received message into recievedmsg table
$sql="INSERT INTO recievedmsg (sender, content) VALUES('$sender','$content')";
$result_sql = mysql_query($sql) or die("Cannot perform insert recievedmsg query"); //Error if cannot connect
am i doing something wrong?

Re: $_REQUEST not working, please help

Posted: Thu Sep 24, 2009 8:29 am
by onion2k
php_new_guy_09 wrote:am i doing something wrong?
Yes. You're using _REQUEST. Don't. It depends on the variable input order in PHP's configuration, therefore you can't trust it to be the same value between different configurations. Using _GET and _POST instead.

Also, a bigger problem, you're not escaping your input data. Your code is open to an SQL inject attack.

Re: $_REQUEST not working, please help

Posted: Thu Sep 24, 2009 8:38 am
by php_new_guy_09
onion2k wrote:
php_new_guy_09 wrote:am i doing something wrong?
Also, a bigger problem, you're not escaping your input data. Your code is open to an SQL inject attack.
I tried GET, but it didnt work either, sorry what do you mean by the above. Im new to php

Re: $_REQUEST not working, please help

Posted: Thu Sep 24, 2009 9:34 am
by jackpf
Try turning on error reporting.

And google SQL injection ;)