Connecting Tech Pros Worldwide Forums | Help | Site Map

mysql_real_escape_string errror: expects string, resource given.

Newbie
 
Join Date: Jun 2009
Posts: 26
#1: Jun 19 '09
Hi, can anyone please help me why I got this error every I uploaded files.

Error:
Quote:
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwroot\uploadingfiles\add_file.php on line 89

Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwroot\uploadingfiles\add_file.php on line 90

Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwroot\uploadingfiles\add_file.php on line 92
Here is the code on the said warning message:
Expand|Select|Wrap|Line Numbers
  1. # Gather all required data
  2.         $name = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['name']);
  3.         $mime = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['type']);
  4.         $size = $_FILES['uploaded_file']['size'];
  5.         $data = mysql_real_escape_string($dbLink, file_get_contents($_FILES['uploaded_file']['tmp_name']));
And because of that error the name and mime of the files I uploaded didn't appear, thats why I cannot properly download the files. Maybe because the mime/filetype is not present.

Your help will be highly appreciated.

Thanks guys..

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,752
#2: Jun 19 '09

re: mysql_real_escape_string errror: expects string, resource given.


Quote:

Originally Posted by roseple View Post

Hi, can anyone please help me why I got this error every I uploaded files.

Hi.

Did you swap back to the old mysql extension, or did you just forget the "i" in the function name?

The old mysql_real_escape_string function expects the first parameter to be a string and the second one to be the mysql connection resource.
Your code has it backwards.

The improved mysqli_real_escaped_string function (note the "i" in the function name) expects the first parameter to be a mysqli object, and the second one to be a string.
Your code has the parameters right, but leaves out the "i" in the function name.
Newbie
 
Join Date: Jun 2009
Posts: 26
#3: Jun 19 '09

re: mysql_real_escape_string errror: expects string, resource given.


Hi, I'm sorry I have another question..
Can anyone know why this warning message occur:
Quote:
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwroot\uploadingfiles\add_file.php on line 89

Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwroot\uploadingfiles\add_file.php on line 90

Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in c:\Inetpub\wwwroot\uploadingfiles\add_file.php on line 92
Here's the code on the said line.
Expand|Select|Wrap|Line Numbers
  1. $name = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['name']);
  2.         $mime = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['type']);
  3.         $size = $_FILES['uploaded_file']['size'];
  4.         $data = mysql_real_escape_string($dbLink, file_get_contents($_FILES['uploaded_file']['tmp_name']));
And because of that warning messae the name, mime and filedata is not present that's why I cannot properly download the files I uploaded.

Thank you very much in advance.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,658
#4: Jun 19 '09

re: mysql_real_escape_string errror: expects string, resource given.


Quote:

Originally Posted by roseple View Post

Can anyone know why this warning message occur:

because you defined the parameters in the wrong order. as stated in the manual, the string comes first and the resource comes second.
Newbie
 
Join Date: Jun 2009
Posts: 26
#5: Jun 19 '09

re: mysql_real_escape_string errror: expects string, resource given.


Can you tell me how can I do that..

Thanks
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,658
#6: Jun 19 '09

re: mysql_real_escape_string errror: expects string, resource given.


Quote:

Originally Posted by roseple View Post

Can you tell me how can I do that..

do what? you mean to correct the error?
Newbie
 
Join Date: Jun 2009
Posts: 26
#7: Jun 20 '09

re: mysql_real_escape_string errror: expects string, resource given.


Yup, if you don't mind..

Thank you very much..
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,752
#8: Jun 20 '09

re: mysql_real_escape_string errror: expects string, resource given.


You have the parameters of the function in reverse order.
One would think the solution would be obvious...

The database link is supposed to go after the data.
(Or not at all. That would work to.)

Keep in mind that the example code in my article is meant for a different function, as I explained in my first post in this thread.

Take a look at the examples in the links both myself and Dormilich posted. See how the parameters are used there.
Reply