Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9
  1. #1
    Lor
    Lor is offline
    Member Lor's Avatar
    Join Date
    Mar 2003
    Posts
    39
    Member #
    795
    I am trying to incorporate a php validation script into another script I have (written for me by JR). I found this script somewhere out there on the web, and I am trying to modify it to suit my needs. But it doesn't even work unto itself, nevermind with my modifications. I get a parse error on line 103. Anyone know what it is? Or alternatively, does anyone know of a good functioning validation php script(for the moment, I am just looking to validate that all fields have been filled in).

    Thanks



    PHP Code:
    <?php

    //Do some validation
    if ($submit) {
    $doit 1;
    $i 0
    if (!
    $Name) {
    $doit 0;
    $error[$i] = "Missing Name";
    $i++;
    }

    if (!
    $Address) {
    $doit 0;
    $error[$i] = "Missing Address";
    $i++;
    }

    if (!
    $areacode) {
    $doit 0;
    $error[$i] = "Missing Area code";
    $i++;
    }
    if (
    $areacode) {
    if (!
    ereg("^[0-9]{3}$"$areacode$arg_vars)) { 
    $doit 0;
    $error[$i] = "Areacode must contain 3 numbers";
    $i++;
    }
    }

    if (!
    $prefix) {
    $doit 0;
    $error[$i] = "Missing First 3 digits in phone number";
    $i++;
    }
    if (
    $prefix) {
    if (!
    ereg("^[0-9]{3}$"$prefix$arg_vars)) { 
    $doit 0;
    $error[$i] = "First part of phone number must contain 3 numbers";
    $i++;
    }
    }

    if (!
    $pnumber) {
    $doit 0;
    $error[$i] = "Missing Last 4 digits in phone number";
    $i++;
    }
    if (
    $pnumber) {
    if (!
    ereg("^[0-9]{4}$"$pnumber$arg_vars)) { 
    $doit 0;
    $error[$i] = "Last part of phone number must contain 4 numbers";
    $i++;
    }
    }



    if (!
    $email) {
    $doit 0;
    $error[$i] = "Missing email";
    $i++;
    }

    if (
    $email) {
    if ( 
    eregi("(@.*@)|(..)|(@.)|(.@)|(^.)"$email$arr_vars
    or !
    eregi ("^.+@([?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,3}|[0-9]{1,3})(]?)$"$email$arr_vars)) {
    $doit 0;
    $error[$i] = "Bad email";
    $i++;

    }
    }
    //End if submit


    if ($submit && ($doit == 1)) {
    //Add to db here
    $dbupdated 1;
    }

    ?>
    <html>
    <head>
    <title>Add a listing</title>
    </head>
    <body>

    <form method="post" action="<?php print $PHP_SELF?>">
    <table width=400 cellspacing="0" cellpadding="4">
    <?php if ($submit && ($doit == 0)) { ?>
    <tr>
    <td colspan=2>Sorry there were the following problems with your submission:<ul>
    <?php 
    for ($j=0;$j count($error);$j++) {
    print 
    "<li><b>"$error[$j] ."</b>n";
    }
    ?>
    </ul>
    </td>
    </tr>
    <?php ?>
    <?php 
    if (($submit && ($doit == 0)) | | !$submit) { ?>
    <tr>
    <td>* Name:</td>
    <td><input type="text" name="Name" size="20" maxlength="100" value="<?php print $Name?>"></td>
    </tr>
    <tr>
    <td>* Street Address:</td>
    <td><input type="text" name="Address" size="20" maxlength="100" value="<?php print $Address?>"></td>
    </tr>
    <tr>
    <td>* Phone:</td>
    <td>(<input type="text" name="areacode" size="3" maxlength="3" value="<?php print $areacode?>"> ) 
    <input type="text" name="prefix" size="3" maxlength="3" value="<?php print $prefix?>">-
    <input type="text" name="pnumber" size="4" maxlength="4" value="<?php print $pnumber?>"></td>
    </tr>
    <tr>
    <td>* Email:</td>
    <td><input type="text" name="email" size="20" maxlength="100" value="<?php print $email?>"></td>
    </tr>
    <tr><td colspan=2><input type="submit" name="submit" value="Submit"></td></tr>
    <?php ?>
    <?php 
    if ($dbupdated == 1) {
    ?>
    <tr><td colspan=2>Thank you for adding your listing. br>
    <?php ?>
    </td></tr>
    </table>
    </form>
    </body>
    </html>

  2.  

  3. #2
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    Can you copy/paste the error so we can see it ?
    - Brian

  4. #3
    Lor
    Lor is offline
    Member Lor's Avatar
    Join Date
    Mar 2003
    Posts
    39
    Member #
    795
    Sure:

    Parse error: parse error in /home/vmsbass/www/www/tests/submit.php3 on line 103

  5. #4
    Member nepharo's Avatar
    Join Date
    Jun 2003
    Posts
    73
    Member #
    1729
    it's kinda difficult figuring out which one is line 103. If you're using dreamweaver or a program that tell you the lines in the source code, check out which lines fall around 103 and post them here. Don't just post line 103 as sometimes the problem lyies a couple of lines above or below. Also, I would not recomend checking for variables like this:
    if(!$Name){
    ...
    }

    I encountered errors doing it that way before. You should use this.
    if(empty($Name)){
    ...
    }
    I cannot self terminate, you must lower me into the fire.

  6. #5
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    Ok, I played with your code for a few minutes and figured out your problem (actually one of two).

    Your first problem, and the cause of the error message, is here:

    PHP Code:
    <?php if (($submit && ($doit == 0)) | | !$submit) { ?>
    You should change it to :
    PHP Code:
    <?php if (($submit && ($doit == 0)) || !$submit) { ?>
    (hold shift and \ to make the | or "pipe line" symbol)

    After that is changed, there is a problem with your email address validation. I'm not very familiar with regular expressions so I can't really help here, but now that you should be able to get to that step in the process somebody else hopefully should be able to help.
    - Brian

  7. #6
    Lor
    Lor is offline
    Member Lor's Avatar
    Join Date
    Mar 2003
    Posts
    39
    Member #
    795
    Thank you Skrlin :cheeky:

  8. #7
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    BTW, once again proving PHP's uber-easiness, you can also just say "or" instead of "||", "and" instead of "&&", etc.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  9. #8
    Senior Member james's Avatar
    Join Date
    May 2003
    Location
    Melbourne, AUSTRALIA
    Posts
    364
    Member #
    1352
    It might be you need to escape the '$' at the end of the regular expressions... eg

    "^[0-9]{3}$" goes to "^[0-9]{3}\$"

    Does php interpret a trailing "$" literally? Anyone?
    James H
    Home Page · Mars Page · www.fihsf1.net (formerly www·fihs·net)

  10. #9
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    When using a $ followed by an illegal character in a literal string, it ignores it.

    To be safe, you can always use single quotes for regexps which don't parse variables.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 02:33 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com