Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Posts
    2

    Unanswered: need help with ereg function

    i'm using the datecheck () ereg function inside of a while loop and its giving me this error.
    here's the function:

    PHP:
    --------------------------------------------------------------------------------

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

    echo("\"$intext\" $isamatch<br>\n");

    }

    --------------------------------------------------------------------------------


    here' s the error:

    Fatal error: Cannot redeclare datecheck() (previously declared in /home/username/public_html/folder/thanks2.php:332) in /home/username/public_html/folder/thanks2.php on line 332


    when i take the function outside of the loop, the form on the page just keeps copying itself all the way down the page, i'm guessing it has something to do with the loop, but i'm not sure whats going on with it, and why its giving me this error if
    i don't have 2 functions with the same name? also i don't have an include file with the same function in that file.
    can anyone tell me how i could fix this so that i don't get this error?

    thanks

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen
    Posts
    12
    can you supply the while loop code where the function is called.

    thanks
    Calum
    www.4-3-3.com
    Online football Management Game

  3. #3
    Join Date
    Apr 2004
    Posts
    2

    need help with ereg functions

    here's the whole code that i'm using

    PHP:
    __________________________________________________ _____


    session_start();

    require_once('bookmark_fns.php');

    $username = $HTTP_POST_VARS['username'];
    $passwd = $HTTP_POST_VARS['passwd'];

    if ($username && $passwd)
    {
    if (login($username, $passwd))
    {
    $HTTP_SESSION_VARS['valid_user'] = $username;
    }
    else
    {
    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);

    echo "<br>";
    echo "the number of rows are:&nbsp;&nbsp;&nbsp;&nbsp;";
    echo $num;
    echo "<br>";
    function ret_upper_case($text){
    $text = strtoupper($text);
    return $text;
    }
    echo 'Just ', ret_upper_case('a quick return'), ' test';

    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");
    }

    function datecheck($intext) {
    $result = ereg("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $intext, $trashed);
    if ($result) { $isamatch = ""; } else { $isamatch = "No - NOT A MATCH"; }
    return "\"".$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>";

    }
    }


    __________________________________________________ ______

Posting Permissions

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