PHP - Querying and Displaying data from MYSql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vamsinadella
Forum Newbie
Posts: 15
Joined: Fri Dec 22, 2006 6:05 pm

PHP - Querying and Displaying data from MYSql

Post 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]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

echo '<pre>post: '; print_r($_POST); echo "</pre>\n";
echo '<pre>get: '; print_r($_GET); echo "</pre>\n";
vamsinadella
Forum Newbie
Posts: 15
Joined: Fri Dec 22, 2006 6:05 pm

- Solved

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Sounds strange. Sorry, can't figure what you've done.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply