mysql_real_escape_string errror: expects string, resource given. 
June 19th, 2009, 05:17 AM
| | Newbie | | Join Date: Jun 2009
Posts: 26
| |
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: - # Gather all required data
-
$name = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['name']);
-
$mime = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['type']);
-
$size = $_FILES['uploaded_file']['size'];
-
$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..
Last edited by Atli; June 19th, 2009 at 09:20 AM.
Reason: Moved from the article into it's own thread.
| 
June 19th, 2009, 09:18 AM
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,701
Provided Answers: 4 | | | re: mysql_real_escape_string errror: expects string, resource given. Quote:
Originally Posted by roseple 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.
| 
June 19th, 2009, 11:10 AM
| | Newbie | | Join Date: Jun 2009
Posts: 26
| | | 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. - $name = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['name']);
-
$mime = mysql_real_escape_string($dbLink, $_FILES['uploaded_file']['type']);
-
$size = $_FILES['uploaded_file']['size'];
-
$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.
| 
June 19th, 2009, 11:57 AM
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9 | | | re: mysql_real_escape_string errror: expects string, resource given. Quote:
Originally Posted by roseple 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.
| 
June 19th, 2009, 12:02 PM
| | Newbie | | Join Date: Jun 2009
Posts: 26
| | | re: mysql_real_escape_string errror: expects string, resource given.
Can you tell me how can I do that..
Thanks
| 
June 19th, 2009, 12:04 PM
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9 | | | re: mysql_real_escape_string errror: expects string, resource given. Quote:
Originally Posted by roseple Can you tell me how can I do that.. | do what? you mean to correct the error?
| 
June 20th, 2009, 02:53 PM
| | Newbie | | Join Date: Jun 2009
Posts: 26
| | | re: mysql_real_escape_string errror: expects string, resource given.
Yup, if you don't mind..
Thank you very much..
| 
June 20th, 2009, 06:49 PM
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,701
Provided Answers: 4 | | | 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.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|