Page 1 of 1

PHP - Querying and Displaying data from MYSql

Posted: Wed Jan 10, 2007 2:43 pm
by vamsinadella
Hi,

I should design a form that gets data from mysql dB, based on the user selection on the form, and display it on the same page. I facing a werd problem. All my values are becoming nulls once i hit the 'Query' button. So i commented all my code to get to the exact problem. Now, all i have is this:
  • Variables to store the values from the user
    Echos to display these values after clicking the 'Query' button.
    The code for both is given below correspondingly.

Code: Select all

$name = mysql_real_escape_string($_POST['vendorname']);
$model = mysql_real_escape_string($_POST['productmodel']);
$code = mysql_real_escape_string($_POST['codename']);
$targ_date = mysql_real_escape_string($_POST['date']);

Code: Select all

if ($_SERVER['REQUEST_METHOD'] == "POST")
	{ echo "Vendor: '$name' \n";
		echo "Model: '$model' \n";
		echo "Code: '$code'"; echo "\n";
		echo "Target DATE: '$targ_date'"; echo "\n";
}
As soon as i click the 'Query' button all the select boxes on the form gets defaulted to 'None' value (an option that is put in manually. All other options are queried from database.) all i get is:

Vendor: '' Model: '' Code: '' Target Date: ''

No matter what you select from the select box all i get is ''. Period.

Can anyone get me out of this weird problem? Actually, am i coding it right? Any help is appreciated. Thanks.

- Vamsi


and immediately as i [/b]

Posted: Wed Jan 10, 2007 2:52 pm
by volka

Code: Select all

echo '<pre>post: '; print_r($_POST); echo "</pre>\n";
echo '<pre>get: '; print_r($_GET); echo "</pre>\n";

- Solved

Posted: Wed Jan 10, 2007 5:17 pm
by vamsinadella
Hi Volka,

Thanks for the response. Actually, i figured it out myself. I removed the 'mysql_real_escape_string' and it worked....everything worked... and now the page is ready. One question though.

I have used this 'mysql_real_escape_string' in another page and it worked fine. The only difference though is in the page that worked i was inserting into the dB and in the page that failed i was selecting and displaying data from dB.

Any comments??????? Just curious to learn that's all. Thanks Anyway.

- Vamsi

Posted: Wed Jan 10, 2007 5:46 pm
by volka
Sounds strange. Sorry, can't figure what you've done.

Posted: Wed Jan 10, 2007 10:29 pm
by feyd
mysql_real_escape_string() returns false on error. I'm going to guess mysql didn't have a connection open at the time.