Jump to content

Recommended Posts

I'm trying to write a registration script and I keep getting this error:

Warning: mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /mysite/connect.php on line 30

Here's the offending code:
        // Check that the e-mail address conforms
        if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))) {
            $e = escape_data($_POST['email']);
        } else {
            $e = FALSE;
            echo '<p><font color="red" size="+1">Please enter a valid email address.</p></font>';
        }
Link to comment
https://forums.phpfreaks.com/topic/23730-probably-a-dumb-question/
Share on other sites

1 - I'm guesing you are not actually connected to MySQL database before calling [b]mysql_real_escape_string ()[/b] somewhere (looks like file is :  [b]connect.php[/b] on line 30)

[i]string[/i] mysql_real_escape_string ( [i]string[/i] unescaped_string[i] [, resource link_identifier][/i] )

2 - maybe your script is putting a boolean  value in place of the optional [u]resource link_identifier[/u].

I'm not sure why you believe the problem is in the code you posted???
Originally I thought I wasn't connecting to the DB as well but not only do I not get a connect error but there are about four if statemetns that rely on the DB before the e-mail one I posted (which is line 27-33), for example this apparently executes fine:
// Check for a last name
        if (eregi ("^[[:alpha:].' -]{2,30}$", stripslashes(trim($_POST['last_name'])))) {
            $ln = escape_data($_POST['last_name']);
        } else {
            $ln = FALSE;
            echo '<p><font color="red" size="+1">Please enter your last name.</font></p>';
        }

I get that PHP thinks I'm passing it a boolean (that's the error message) but I what I can't figure out where that's happening, and as for the code I posted, that is the if containing line 30 which is, apparently, where the error is occuring (according to PHP).

Like I said, this is probably some dumb newbie issue but I'm at my wits' end.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.