Warning: mysql_real_escape_string() expects parameter 2 to be resource

Posted on 2011-04-22
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)
Question by:katlees
    LVL 107

    Expert Comment

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

    Author Comment

    resource(1) of type (mysql link)
    LVL 8

    Accepted Solution

    Try removing the ,$link (resource identifier):


    Open in new window

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

    Expert Comment

    by:Ray Paseur
    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now