Need help in simple form validation...

Discussion in 'PHP' started by jehzlau, Jan 17, 2008.

  1. jehzlau

    jehzlau Active Member

    Messages:
    301
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #21
    I still get this error:
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jehzwins/public_html/wp-sms/process.php on line 67


    This is my complete code, without the validation of duplicates:
    <?php
    
    $errors=0;
    $error="<b>The following errors occured while processing your form input.</b><br /><br />";
    
    $Name = $_POST['Name'];
    $Email = $_POST['Email'];
    $CellNumberPre = $_POST['CellNumberPre'];
    $CellNumber = $_POST['CellNumber'];
    $AlertOn = $_POST['AlertOn'];
    
    if($Name=="" || $Email=="" || $CellNumberPre=="" || $CellNumber=="" || $AlertOn=="" ){
    $errors=1;
    $error.="<p>You did not enter one or more of the required fields. Please go <a href=\"javascript:history.go(-1)\"><b>back</b></a> and try again.</p>";
    }
    
    if(!preg_match("/^\d+$/",$CellNumber)){
    $errors=1;
    $error.="<p>Only numbers are accepted in the cell number field. Please go <a href=\"javascript:history.go(-1)\"><b>back</b></a> and try again.</p>";
    }
    
    if (strlen($CellNumber) < 7){
    $errors=1;
    $error.="<p>Your cellphone number is not valid. Please go <a href=\"javascript:history.go(-1)\"><b>back</b></a> and try again.</p>";
    }
    
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
    $error.="<p>Invalid email address entered. Please go <a href=\"javascript:history.go(-1)\"><b>back</b></a> and try again.</p>";
    $errors=1;
    }
    
    if($errors==1) echo $error;
    else{
    
    $link = mysql_connect("localhost","jehzlau","password111");
    mysql_select_db("database",$link);
    $query="insert into sms_subscribers (name,email,cnp,cn,alerton) values ('".$Name."','".$Email."','".$CellNumberPre."','".$CellNumber."','".$AlertOn."')";
    mysql_query($query);
    ?>
    PHP:

    All I want is to validate if the $CellNumber was already entered in my database.. that's all.. and where should i place it in my code :(

    I hope someone can help me because I'm so noob :(
     
    jehzlau, Jan 20, 2008 IP
  2. jehzlau

    jehzlau Active Member

    Messages:
    301
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #22
    i hope someone will reply to this post :(
     
    jehzlau, Jan 22, 2008 IP
  3. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #23
    Your warning says "mysql_num_rows...on line 67" but:

    1. There's no "mysql_num_rows" in your code
    2. There are no 67 lines

    Are you looking at the right file?
     
    SoKickIt, Jan 23, 2008 IP
  4. jehzlau

    jehzlau Active Member

    Messages:
    301
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #24
    it was my previous error.. that code that I'm showing is the one that has not duplicate entry validation...

    All I want is how to validate of the cell number already exists.. that's all T__T
     
    jehzlau, Jan 23, 2008 IP