TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-03-2009, 07:50 PM   #1 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Confused mysql_real_escape_string?

Heya guys. I am truly puzzled by mysql_real_escape_string.

From what I understand you need to make a database connection before the function will work. I think that I'm doing this.
Code:
$link = mysqli_connect( $sql_server, $sql_user , $sql_password ) or die ('Unable to connect to server.'. mysqli_error());

mysqli_select_db( $link, $sql_database ) or die ('Unable to select database.'. mysqli_error());

$username 	= mysql_real_escape_string($username, $link);
$password 	= mysql_real_escape_string($password);
The $username line gives me error:
Warning: mysql_real_escape_string() expects parameter 2 to be resource...

The $password line gives me another error.
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in...

I would think one of these would work, suggestions??
nefus is offline  
Reply With Quote
Old 02-03-2009, 08:09 PM   #2 (permalink)
The Contributor
 
Join Date: Feb 2009
Posts: 65
Thanks: 0
Krik is on a distinguished road
Default

Not sure if this is relevant but on the second error with the password that reference to ODBC makes me wonder if you are using a sql database at all. And in particular a MySQL database.
Krik is offline  
Reply With Quote
Old 02-03-2009, 08:38 PM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Both errors would suggest that the MySql connection is invalid.
__________________

Village Idiot is offline  
Reply With Quote
Old 02-03-2009, 08:55 PM   #4 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Default

Actually a quick test without the mysql_real_escape_string() demonstrated that it worked fine. Data was injected correctly into the database.
nefus is offline  
Reply With Quote
Old 02-03-2009, 09:07 PM   #5 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Default

Well, I found the problem.

It should be:
$username = mysqli_real_escape_string($link, $username);

Not:
$username = mysql_real_escape_string($username, $link);

The first statements were mysqli so that was a mistake on my part. The odd thing is that $link comes first with mysqli and second with mysql.

Last edited by nefus : 02-03-2009 at 09:32 PM.
nefus is offline  
Reply With Quote
Old 02-04-2009, 12:23 AM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

It might be to make sure you can't accidentally pass one off as the other because they look almost identical.
__________________

Village Idiot is offline  
Reply With Quote
Old 02-04-2009, 01:47 AM   #7 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Do you have to specify the link in most of the mysqli_ functions? My thinking is that MySQLi has the link parameter first because that is essential for MySQLi to work correctly. In the mysql_ functions it didn't matter too much if you didn't specify the link because if only one connection was open, then that was obviously the default.

My question, why is the link parameter essential for MySQLi?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-04-2009, 10:50 AM   #8 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

My question, why use the global functions when the OO approach is much prettier?
Salathe is offline  
Reply With Quote
Old 02-19-2013, 05:25 AM   #9 (permalink)
The Wanderer
 
Join Date: Feb 2013
Posts: 17
Thanks: 0
Rainman is on a distinguished road
Default

Welcome to mmoggg website to buy RS Gold, offer a lot, of course, Diablo 3 Gold and Cheap RS Gold, to be purchased at any time, at any time shipment, and Diablo 3 Gold Kaufen look forward to your visit!
Rainman is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:20 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design