?
Solved

Warning: mysql_real_escape_string() expects parameter 2 to be resource

Posted on 2011-04-22
4
Medium Priority
?
503 Views
Last Modified: 2012-05-11
I recently moved a website to a new server and now a specific form keeps throwing this error
Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in /home/blackhil/public_html/ordercatelog.php on line 185

184 $bname = $_POST['to_name'];
185 $bname = mysql_real_escape_string($bname, $link);

The form works (sends emails and writes to database)
0
Comment
Question by:katlees
  • 2
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35447854
Print out the contents of $link with var_dump() and post it here, thanks.
0
 

Author Comment

by:katlees
ID: 35447887
resource(1) of type (mysql link)
0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 2000 total points
ID: 35447898
Try removing the ,$link (resource identifier):

mysql_real_escape_string($bname);

Open in new window


If that doesn't work,
use the same resource identifier as you use in mysql_query($query, $your_resource_identifier);
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35448214
Removing the $link will produce a "default" condition.  If you understand what that default condition is, and it is the condition you want to choose, you might be OK.  If you do not understand that please read the man page for the function.  You may want to consider which DB connection you want to have in play.
http://us.php.net/manual/en/function.mysql-real-escape-string.php
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question