468,505 Members | 1,559 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

mysql_real_escape_string errror: expects string, resource given.

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

Error:
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..
Jun 19 '09 #1
7 4760
Atli
5,058 Expert 4TB
@roseple
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.
Jun 19 '09 #2
roseple
26
Hi, I'm sorry I have another question..
Can anyone know why this warning message occur:
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.
Jun 19 '09 #3
Dormilich
8,651 Expert Mod 8TB
@roseple
because you defined the parameters in the wrong order. as stated in the manual, the string comes first and the resource comes second.
Jun 19 '09 #4
roseple
26
Can you tell me how can I do that..

Thanks
Jun 19 '09 #5
Dormilich
8,651 Expert Mod 8TB
@roseple
do what? you mean to correct the error?
Jun 19 '09 #6
roseple
26
Yup, if you don't mind..

Thank you very much..
Jun 20 '09 #7
Atli
5,058 Expert 4TB
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.
Jun 20 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by leegold2 | last post: by
2 posts views Thread by Marcus | last post: by
9 posts views Thread by frizzle | last post: by
2 posts views Thread by Sam Martin | last post: by
2 posts views Thread by comp.lang.php | last post: by
4 posts views Thread by JM Ivler | last post: by
11 posts views Thread by zach | last post: by
13 posts views Thread by ndlarsen | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.