473,383 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 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 5121
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.