Jump to content

mysql_real_escape_string()


sofia403

Recommended Posts

Hi, just wondering do i need to use mysql_real_escape_string() on login information (username and password). I use it as shown below but get an error when connecting.

 

if(isset($_POST['submit'])){
if( empty($_POST['uname']) && (empty($_POST['upass']))){
header( "Location:Messages.php?msg=1" ); 
exit();
}

$n=mysql_real_escape_string($_POST['uname']);
$p=mysql_real_escape_string($_POST['upass']);

include('config.php');
$query="select * from country where uname='$n'  and pw='$p'";
$result=mysql_query($query);

Link to comment
Share on other sites

Yes, it should be used on any and all string type data being used in a DB query. If your database connection is in your config.php file, you'll need to make sure it gets included before you try to use mysql_real_escape_string().

 

When you post a question and it involves an error message, it's usually helpful to also post the error, BTW.

Link to comment
Share on other sites

ok, sorry my error was

 

access denied for user with password "NO" or something of that nature.

 

My config.php was after mysql_real_escape_string() i moved it to the top and it works now, thanks!

 

Also i was wondering, probably a silly question, but anyways, if i have a selection form where users select predefined values, then i dont need mysql_real_escape_string() is that right? :S

 

Link to comment
Share on other sites

Don't make the mistake of thinking that <select> and other fields with a "limited" number of options don't need to be validated and sanitized. It doesn't take anything for a malicious user to make their own form and use it to submit values to your script.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.