need help with ereg function

A

Anonymous

Guest
--------------------------------------------------------------------------------

i need help with the ereg function. i am getting this error message:
Fatal error: Cannot redeclare phonecheck() (previously declared in
/home/username/public_html/folder/thanks2.php:257) in /home/username/public_html/folder/thanks2.php
on line 257
i have tried a few different functions to get this to work, but still having the same error message, can someone please help me to get this to work without having this error message?

here is what i am trying to use but coming up with errors. i am not redeclaring this function anywhere else in my code. i also try changing the name of the function, for example i try to change datecheck() to dateck() and still i keep getting the same error message. what else can i try for this to work and the error message to go away?
thanks


i also have these functions inside of a while loop and when i take these functions outside of a while loop, the form keeps looping and makes at least 45 copies of itself on the page. can someone help me in trying to get the page to stop copying itself and get this page to work without any errors and without anything copying itself?
thanks
let me know if you want me to post the whole page that i am working on.
here are the functions i have used:


Code:
function datecheck($intext) { 
$theresults = ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $intext, $trashed); 
if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; } 
    
echo("\"$intext\" $isamatch<br>\n"); 
} 



if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $expire, $regs)) { 
   echo "$regs[3].$regs[2].$regs[1]"; 
} else { 
   echo "Invalid date format: $expire"; 
} 



function dateck($expire) 
{ 
  // check an email address is possibly valid 
  if (ereg("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $expire)) 
    return true; 
  else   
    return false; 
}
 
For the error, it seems that you have more than one function named phonecheck where the first declaration of it is in the thanks2.php file at line 257. That kind of error occure too when we gave to some our function, the same name as a php predefined function.

Now, why are you using that functions inside a while loop ??
 
in thanks2.php, i only have one function that is named phonecheck on that page and in the site i'm working on. how would i get rid of the error?
at the moment the function is outside of the while loop and the form is looping all the way down the page. i put the function inside of the while loop so it would not keep copying itself down the page, if its inside the while loop it only appears once, but with that error.
how can this be fixed?
thanks
 
Ok. You´re 'including' the thanks2.php file, right !?
So try this first. For the file you´re including, use (depending of your case):
include_once() instead of include() and/or require_once() instead of require().

Also make sure that you´re not including the file twice !!
 
thanks2.php is the file that i am working on, it is not the file i am including. But there are a few files that i am including. i am using the include() and require_once() to include these files, but in the files i am including, i am not including them twice nor do i have any of the functions written twice.
how would i fix the error that i have? what would i have to do?
thanks
 
Can you please describe just what files you´re using and what files are included in each one? Please describe too the included way, i mean: include/once or require/once. And in what file is your phonecheck()!

BTW: What php version you´re using !?
 
i am using an html form page (checkout.html) with a checkout form on it, the form has name, last name, where the person live, account #, etc... there is a separate php page (checkout.php) that the form goes to that shows the user what they have entered into the fields and if what they have entered is valid.
the file that i am working on does have a few includes in it, one i am using require_once() and another i am using include(). i am using phonecheck on the checkout.php file. i have not declared the function anywhere else in the file or in the include files.
i am using php version 4.3
how would you get the from to stop copying itself? i put the functions outside of the loop and the form copies itself all the way down the page.

would you like me to post the code for the whole page that i am working on?
 
Well, it´s really difficult to see what´s wrong this way. Maybe you´re making some coding mistake!
Do you want me to see and test your code!? If so please email me, otherwise, drop your code here.
 
can you take a look at it to see what wrong with it?
here is the whole page that i am working on.

Code:
session_start();

       // include function files for this application
require_once('bookmark_fns.php'); 

//create short variable names
$username = $HTTP_POST_VARS['username'];
$passwd = $HTTP_POST_VARS['passwd'];

if ($username && $passwd)
// they have just tried logging in
{
    if (login($username, $passwd))
    {
      // if they are in the database register the user id
      $HTTP_SESSION_VARS['valid_user'] = $username;
    }  
    else
    {
      // unsuccessful login
      do_html_header('Problem:');
      echo 'You could not be logged in. 
            You must be logged in to view this page.';
      do_html_url('login.php', 'Login');
      do_html_footer();
      exit;
    }      
}


$db_name = "database"; 
$table_name = "checkout"; 

$link_id = mysql_connect("localhost", "username", "password")  
or die("Couldn't connect."); 

$db = mysql_select_db($db_name, $link_id) 
    or die("Couldn't select database."); 

mysql_query ("INSERT INTO $table_name (billfirstname, billlastname, billstreetaddr, billcity, billstate, billzipcode, billcountry, billcounty, email, phone, payment, creditnum, expire, questions, shipfirstname, shiplastname, shipstreetaddr, shipcity, shipstate, shipzipcode, shipcountry, shipcounty)  
			VALUES  ('$billfirstname', '$billlastname', '$billstreetaddr', '$billcity', '$billstate', '$billzipcode', '$billcountry', '$billcounty', '$email', '$phone', '$payment', '$creditnum', '$expire', '$questions', '$shipfirstname', '$shiplastname', '$shipstreetaddr', '$shipcity', '$shipstate', '$shipzipcode', '$shipcountry', '$shipcounty')"); 

 
echo "$select<br>";
					
	$host    ="localhost";
	$db_user="username";
	$db_pass="password";
	$database="database";
					
mysql_connect($host,$db_user,$db_pass);
mysql_select_db($database) or die ("Unable to select database");    


echo "<center>Thank You For Shopping With Us!</center><br>"; 
echo "<center>";  
check_valid_user(); 

echo "</center>"; 
echo "<br>";
echo "<center><a href='logout.php'>Click here to Logout</a></center>";
echo "<br>";
include("check.php");
echo "<br>"; 
echo "<strong>Your Billing and Shipping information!</strong>";

$query="SELECT * FROM $table_name WHERE billfirstname='$billfirstname' and billlastname='$billlastname' and billstreetaddr='$billstreetaddr' and billcity='$billcity' and billstate='$billstate' and billzipcode='$billzipcode' and billcountry='$billcountry' and billcounty='$billcounty' and email='$email' and phone='$phone' and payment='$payment' and creditnum='$creditnum' and expire='$expire' and questions='$questions' and shipfirstname='$shipfirstname' and shiplastname='$shiplastname' and shipstreetaddr='$shipstreetaddr' and shipcity='$shipcity' and shipstate='$shipstate' and shipzipcode='$shipzipcode' and shipcountry='$shipcountry' and shipcounty='$shipcounty'";  

$result=mysql_query($query);
$num=mysql_numrows($result);  

function datecheck($theresults) {
   $theresults = ereg("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $intext, $trashed);
   if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
 
  echo("$isamatch");
} 

function phonecheck($intext) {
   $theresults = ereg("([0-9]{3})-([0-9]{3})-([0-9]{4})", $intext, $trashed);
   if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
  
 echo("\"$intext\" $isamatch<br>\n");
} 

function ccnumcheck($intext) {
   $theresults = ereg("([0-9]{16})", $intext, $trashed);
   if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
  
 echo("\"$intext\" $isamatch<br>\n");
} 

function emailcheck($intext) {
   $theresults = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $intext, $trashed);
   if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
  
 echo("\"$intext\" $isamatch<br>\n");
} 

$result = mysql_query($query, $link_id);

while($query_data = mysql_fetch_row($result)) {   

echo "<table>"; 

echo "<tr>";
echo "<td>billfirstname</td>";
echo "<td>",$query_data[0],"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>billlastname</td>";
echo "<td>",$query_data[1],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>billstreetaddr</td>";
echo "<td>",$query_data[2],"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>billcity</td>";
echo "<td>",$query_data[3],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>billstate</td>";
echo "<td>",$query_data[4],"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>billzipcode</td>";
echo "<td>",$query_data[5],"</td>"; 
echo "</tr>"; 

echo "<tr>";
echo "<td>billcountry</td>";
echo "<td>",$query_data[6],"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>email<br>"; 
echo "</td>";
echo "<td>",emailcheck("$email"),"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>phone</td>";
echo "<td>",phonecheck($phone),"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>payment</td>";
echo "<td>",$query_data[10],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>creditnum</td>";
echo "<td>",ccnumcheck($creditnum),"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>expire</td>";
echo "<td>",datecheck($expire),"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>questions</td>";
echo "<td>",$query_data[13],"</td>";
echo "</tr>";   

echo "<tr>";
echo "<td>shipfirstname</td>";
echo "<td>",$query_data[14],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shiplastname</td>";
echo "<td>",$query_data[15],"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>shipstreetaddr</td>";
echo "<td>",$query_data[16],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shipcity</td>";
echo "<td>",$query_data[17],"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>shipstate</td>";
echo "<td>",$query_data[18],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shipzipcode</td>";
echo "<td>",$query_data[19],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shipcountry</td>";
echo "<td>",$query_data[20],"</td>";
echo "</tr>"; 

echo "</table>";     
                        
                        if(isset($_COOKIE['cartId']))  { 
                        
                        echo "<center><strong>----- cookie is set ----- </strong></center>";
                        
                        }
                        
                        else {
                        
                        echo "<center><strong>----- cookie is NOT set ----- </strong></center>";                        
                        }
}
 
Well, seems to be everything alright with your ereg functions!

Now let´s make same little changes!

1.
Use mysql_fetch_array() ionstead of mysql_fetch_row() in your while statement.

2.
You have errors when printing your html code (inside the while):
Code:
// Wrong 
echo "<td>" , $query_data[0] , "</td>";

// Right
echo "<td>" . $query_data[0] . "</td>";
Well, the php tags aren´t working, so i admit is hard to see the difference. You´re using a comma (,), wrong, you should use a point (.).
Ok, make this changes first to see what happens!
 
Actually, comma syntax in echo is valid, and often faster, than dot-syntax.
 
i tried the example and i get the same error as i was getting before
 
hey can you post the function file code, since i think that this fatal error is screaming at your definitions of the phonecheck function...

Note : PHP does not support function overloading, nor is it possible to undefine or redefine previously-declared functions.
 
yeah, i'll post the whole file that i am working on.

here is the file:

Code:
session_start();

       // include function files for this application
require_once('bookmark_fns.php'); 


//create short variable names
$username = $HTTP_POST_VARS['username'];
$passwd = $HTTP_POST_VARS['passwd'];

if ($username && $passwd)
// they have just tried logging in
{
    if (login($username, $passwd))
    {
      // if they are in the database register the user id
      $HTTP_SESSION_VARS['valid_user'] = $username;
    }  
    else
    {
      // unsuccessful login
      do_html_header('Problem:');
      echo 'You could not be logged in. 
            You must be logged in to view this page.';
      do_html_url('login.php', 'Login');
      do_html_footer();
      exit;
    }      
}


$db_name = "database"; 
$table_name = "checkout"; 

$link_id = mysql_connect("localhost", "username", "password")  
or die("Couldn't connect."); 

$db = mysql_select_db($db_name, $link_id) 
    or die("Couldn't select database."); 

mysql_query ("INSERT INTO $table_name (billfirstname, billlastname, billstreetaddr, billcity, billstate, billzipcode, billcountry, billcounty, email, phone, payment, creditnum, expire, questions, shipfirstname, shiplastname, shipstreetaddr, shipcity, shipstate, shipzipcode, shipcountry, shipcounty)  
			VALUES  ('$billfirstname', '$billlastname', '$billstreetaddr', '$billcity', '$billstate', '$billzipcode', '$billcountry', '$billcounty', '$email', '$phone', '$payment', '$creditnum', '$expire', '$questions', '$shipfirstname', '$shiplastname', '$shipstreetaddr', '$shipcity', '$shipstate', '$shipzipcode', '$shipcountry', '$shipcounty')"); 

 
echo "$select<br>";
					
	$host    ="localhost";
	$db_user="username";
	$db_pass="password";
	$database="database";
					
mysql_connect($host,$db_user,$db_pass);
mysql_select_db($database) or die ("Unable to select database");    


echo "<center>Thank You For Shopping With Us!</center><br>"; 
echo "<center>";  
check_valid_user(); 

echo "</center>"; 
echo "<br>";
echo "<center><a href='logout.php'>Click here to Logout</a></center>";
echo "<br>";
include("check.php");
echo "<br>"; 

echo "<strong>Your Billing and Shipping information!</strong>";

$query = "SELECT * FROM `$table_name` WHERE `id` = $id"; 

echo $query; 
$result=mysql_query($query) or die ('ERROR : '. mysql_error()); 

$num=mysql_numrows($result);  
echo "<br><br>";
echo "id variable";
$insert_id_variable = mysql_insert_id(); 

echo "<br>";
echo "the number of rows are:    ";
echo $num;

if (!function_exists('datecheck')) 
{ 
  
function datecheck($intext) { 
$theresults = ereg("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $intext, $trashed); 
if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; } 
    
echo("\"$intext\" $isamatch<br>\n"); 
} 

} 


function phonecheck($intext) {
   $theresults = ereg("([0-9]{3})-([0-9]{3})-([0-9]{4})", $intext, $trashed);
   if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
  
 echo("\"$intext\" $isamatch<br>\n");
} 

function ccnumcheck($intext) {
   $theresults = ereg("([0-9]{16})", $intext, $trashed);
   if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
  
 echo("\"$intext\" $isamatch<br>\n");
} 

function emailcheck($intext) {
   $theresults = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $intext, $trashed);
   if ($theresults) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
  
 echo("\"$intext\" $isamatch<br>\n");
} 

$result = mysql_query($query, $link_id);

 
while($query_data = mysql_fetch_row($result)) { 

echo "<table>"; 
 
echo "<tr>";
echo "<td>billfirstname</td>";
echo "<td>",$query_data[0],"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>billlastname</td>";
echo "<td>",$query_data[1],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>billstreetaddr</td>";
echo "<td>",$query_data[2],"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>billcity</td>";
echo "<td>",$query_data[3],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>billstate</td>";
echo "<td>",$query_data[4],"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>billzipcode</td>";
echo "<td>",$query_data[5],"</td>"; 
echo "</tr>"; 

echo "<tr>";
echo "<td>billcountry</td>";
echo "<td>",$query_data[6],"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>email<br>"; 
echo "</td>";
echo "<td>",emailcheck("$email"),"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>phone</td>";
echo "<td>",phonecheck("$phone"),"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>payment</td>";
echo "<td>",$query_data[10],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>creditnum</td>";
echo "<td>",ccnumcheck($creditnum),"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>expire</td>";
echo "<td>",datecheck($expire),"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>questions</td>";
echo "<td>",$query_data[13],"</td>";
echo "</tr>";   

echo "<tr>";
echo "<td>shipfirstname</td>";
echo "<td>",$query_data[14],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shiplastname</td>";
echo "<td>",$query_data[15],"</td>";
echo "</tr>";  

echo "<tr>";
echo "<td>shipstreetaddr</td>";
echo "<td>",$query_data[16],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shipcity</td>";
echo "<td>",$query_data[17],"</td>";
echo "</tr>";

echo "<tr>";
echo "<td>shipstate</td>";
echo "<td>",$query_data[18],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shipzipcode</td>";
echo "<td>",$query_data[19],"</td>";
echo "</tr>"; 

echo "<tr>";
echo "<td>shipcountry</td>";
echo "<td>",$query_data[20],"</td>";
echo "</tr>"; 

echo "</table>";     
                   
                        if(isset($_COOKIE['cartId']))  { 
                        
                        echo "<center><strong>----- cookie is set ----- </strong></center>";
                        
                        }
                        
                        else {
                        
                        echo "<center><strong>----- cookie is NOT set ----- </strong></center>";
                        
                        }
}
 
Ok, sorry for my unfortunate words about 'comma synrax'!

Try to use:
Code:
phonecheck( $query_data[phone] )
When you call to your phonecheck function. The same for your emailcheck!
 
Let me know the errors!
By the way, i see a difference in the line where you call phonecheck() between this last code you post and in the previous one!
 
when i used your last example, it gave me an error saying, parse error on line ___.
 
Back
Top