...

View Full Version : Warning: ereg(): REG_BADRPT:



wanping
04-10-2004, 11:54 AM
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? :confused:



<?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!

black3842
04-11-2004, 12:23 PM
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

wanping
04-12-2004, 11:32 AM
:p thanks for the reply, i finally found out what's wrong with my coding.
it's at these lines

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

if(!ereg("^http://*.*",$url))

i change it to


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..

raf
04-12-2004, 02:22 PM
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


$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\-])+))$

rwt
08-06-2007, 07:29 PM
I'm getting the same error here with this expression:

^[_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

rwt
08-06-2007, 07:32 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum