mysql_real_escape_string and $_GET

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
petrosa
Forum Newbie
Posts: 12
Joined: Fri Feb 27, 2009 9:13 pm

mysql_real_escape_string and $_GET

Post by petrosa »

Hello,

i have a problem with my webpage, i want to use mysql_real_escape_string() on a $_GET variable, but when i use mysql_real_escape_string($_GET['var']) , i dont get the GET variable, i only get a blank.

This has been bugging me all day, any help would be appreciated

Thanks in advance
User avatar
bala_1225
Forum Commoner
Posts: 29
Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india

Re: mysql_real_escape_string and $_GET

Post by bala_1225 »

hi,

<?
$string = $_GET['var'];
echo mysql_real_escape_string($string);
?>
try this one..... :lol:
User avatar
bala_1225
Forum Commoner
Posts: 29
Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india

Re: mysql_real_escape_string and $_GET

Post by bala_1225 »

<?php
$string = $_GET['var'];

$string = mysql_real_escape_string($string);

$query = "INSERT INTO `table` (`string`) VALUES ('$string')";

?>

Also, Try this method...... :D
petrosa
Forum Newbie
Posts: 12
Joined: Fri Feb 27, 2009 9:13 pm

Re: mysql_real_escape_string and $_GET

Post by petrosa »

bala_1225 wrote:hi,

<?
$string = $_GET['var'];
echo mysql_real_escape_string($string);
?>
try this one..... :lol:
i tried that, but still i have the same problem...

echo $string; --> works fine
echo mysql_real_escape_string($string); -->doesnt work
User avatar
bala_1225
Forum Commoner
Posts: 29
Joined: Tue Jul 28, 2009 3:20 am
Location: chennai,india

Re: mysql_real_escape_string and $_GET

Post by bala_1225 »

hi,

<?
$string = $str; //$str --- from database only then only it will work...........
echo mysql_real_escape_string($string);
?>
try this one..... :lol:
petrosa
Forum Newbie
Posts: 12
Joined: Fri Feb 27, 2009 9:13 pm

Re: mysql_real_escape_string and $_GET

Post by petrosa »

bala_1225 wrote:hi,

<?
$string = $str; //$str --- from database only then only it will work...........
echo mysql_real_escape_string($string);
?>
try this one..... :lol:
That didnt work either... did some more research, and it seems that mysql_real_escape_string(); needs to have a connection to the database first to work, so i just moved my connection at the start and voila :)

Thanks for the responces
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: mysql_real_escape_string and $_GET

Post by jackpf »

Yes, you need a connection to the mysql server in order to use mysql_real_escape_string().

If you turn on error reporting you should get an error about not being connected to a database or something.
Post Reply