Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Warning: ereg(): REG_BADRPT:

    Hi,
    I'm new in PHP.
    i get an warning:
    Warning: ereg(): REG_BADRPT: in C:\Program Files\Apache Group\Apache2\htdocs\additem.php on line 26
    when i'm trying to run a php file,anyone know what's wrong?

    PHP Code:
    <?php 
    $name
    =$HTTP_POST_VARS['name'];
    $location=$HTTP_POST_VARS['location'];
    $email=$HTTP_POST_VARS['email'];
    $url=$HTTP_POST_VARS['url'];
    $comments=$HTTP_POST_VARS['comments'];
    $submit=$HTTP_POST_VARS['submit'];
    $text="";
     @ 
    $db mysql_pconnect('localhost''root''');

      if (!
    $db)
      {
         echo 
    'Error: Could not connect to database.  Please try again later.';
         exit;
      }

      
    mysql_select_db('guestbook');

    if(empty(
    $name))
    {
      
    $text="Please enter name.<br>";
      
    $submit=false;
    }

    if(!
    ereg("*@*.*",$email))
    {
      
    $text="$email doesn't look like a valid e-mail address";
      
    $submit=false;
    }

    if(!
    ereg("^http://*.*",$url))
    {
        
    $text="$url doesn't look like a valid URL";
          
    $submit=false;
    }

     
      if (
    $submit)
      {
        
    $query="insert into guestbook(name,location,email,url,comments)
            values('"
    .$name."','".$location."',
            '"
    .$email."','".$url."',
            '"
    .$comments."')";
        
    mysql_query($query);
        
        echo 
    '<h2>Thanks!</h2>';
        echo 
    '<h2><a href="view.php">View My Guest Book!!!</a></h2>';
       }
        else 
        { 
            echo 
    $text;
            include(
    'sign.php');
        }
    ?>
    thanks!

  • #2
    New Coder
    Join Date
    Apr 2004
    Location
    Texas
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Good question, not sure, but you might try echoing $email before that statement to see if you're possibly passing ereg a null or empty string....

    good luck!
    Jason

  • #3
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    thanks for the reply, i finally found out what's wrong with my coding.
    it's at these lines
    PHP Code:
    if(!ereg("*@*.*",$email)) 

      
    $text="$email doesn't look like a valid e-mail address"
      
    $submit=false


    if(!
    ereg("^http://*.*",$url)) 
    i change it to

    PHP Code:
    if(!ereg("(.*@.*\..*)",$email)) 

      
    $text="$email doesn't look like a valid e-mail address"
      
    $submit=false


    if(!
    ereg("^http://.*\..*",$url)) 
    and the warning message disappear..

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Welcome here wamping !

    If you're just starting out on PHP, then best only use the currently recommended syntax.

    $HTTP_POST_VARS['name'] is depreciated and shoulf be replaced by $_POST['name']
    $text="" should be $text='' because double-quoted strings are parsed (which means extra processingresaources are wasted --> make a habit of using single quotes for strings that don't need parsing)
    @ $db = mysql_pconnect('localhost', 'root', '') should be $db = @mysql_pconnect('localhost', 'root', '') --> the error-supressing @ needs to be in front of the functio you wan't to supres the errors from + you should realy set up a pwd for your root-user... In fact,
    @ $db = mysql_pconnect('localhost', 'root', '');

    if (!$db)
    {
    echo 'Error: Could not connect to database. Please try again later.';
    exit;
    }

    mysql_select_db('guestbook');
    hould be
    PHP Code:
    $link = @mysql_pconnect('localhost''root''') or die('Error: Could not connect to database.  Please try again later.'); 
    //$link is the conventional name to store the connectionID in. $db is kinda confusing
    @mysql_select_db('guestbook',$link); 
    or queryexecution then becomes
    mysql_query($query,$link) or die ('Queryproblem');

    there are also better regex's for email end url's then just these wildcards things. run a search at www.php.net or google for them
    Here's an url example
    ^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$

    and an email-example

    ^([a-zA-Z0-9_\-\.])+@(([0-2]?[0-5]?[0-5]\.[0-2]?[0-5]?[0-5]\.[0-2]?[0-5]?[0-5]\.[0-2]?[0-5]?[0-5])|((([a-zA-Z0-9\-])+\.)+([a-zA-Z\-])+))$
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    rwt
    rwt is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm getting the same error here with this expression:
    Code:
    ^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9- 
    //]+)*(\.[a-z]{2,3})$
    I've looked over it again and again, and I don't seem to get whats wrong.

    please help

  • #6
    rwt
    rwt is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    haaaaa, I am soo dumn sometimes... its easy, I had two backslashes // and a space witch doesn't seem to be allowed.

    thanks for not answering


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •