472,983 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

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 5100
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,658 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,658 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

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

Similar topics

1
by: leegold2 | last post by:
When I look directly in my db field I see a difference between these two functions. The top line (seebelow) was inserted with addslashes vs. the bottom line where I used mysql_real_escape_string....
2
by: Marcus | last post by:
Hello, My php.ini file currently has magic quotes set to On, but I have read that it is better to code with it off. Currently with magic quotes on, I only use stripslashes() to properly...
9
by: frizzle | last post by:
Hi groupies, I have 2 small questions, which i really want to be sure about: - does mysql_real_escape_string() prevent any kind of mysq-injection? - can it put escaped quotes etc in the DB, or...
2
by: Sam Martin | last post by:
from a resource file. Hi all, Im having a bit of a moment. I've got resource files in each of my assemblies, just named like "Labels.resources" for example. I've got a commond base...
3
by: | last post by:
I'm picking up an 'IMPORTS' error for a simple database insert based on two input entry boxes in my form? It says an 'Imports' statement must preceede any declarations....... is this perahps the...
2
by: comp.lang.php | last post by:
when trying to use the mysql_real_escape_string() function, the following warning occurs: First of all, the user is not 'web' trying to connect to the database, secondly, what is...
4
by: JM Ivler | last post by:
Is there really any time when I don't want to run every _POST and _GET through mysql_real_escape_string() before I use that data in accessing the database? In other words, is there a good reason...
11
by: zach | last post by:
I created a comment form which will inserts the comments into a database and displays them immediately. I want to make sure that its safe from users inserting unwanted data into the database or...
13
by: ndlarsen | last post by:
Hello. It's been a while since I used php. Since then magic quotes has been deprecated and will be removed when php 6.0 hits. My question is, what should I be using when submitting data to a...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.