Results 1 to 2 of 2

Thread: PHP Validation problems with mysql count rows and array_push

  1. #1
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default PHP Validation problems with mysql count rows and array_push

    I have a registration form, and it is not working properly. This is when I fill out all of the fields.
    I get these two errors:
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\getaband.net\register\musicians.php on line 31

    PHP Code:
    <?php
    $errors 
    = array("fix.php?register=musician");
    function 
    validate($input){
        if(
    $input=="nameFirst"){
            
    strip_tags($_POST['nameFirst']);
            
    $c++;
        }
        elseif(
    $input=="nameLast"){
            
    strip_tags($_POST['nameLast']);
            
    $c++;
        }
        elseif(
    $input=="email"){
            
            if(!
    filter_var($_POST['emailAddress'], FILTER_VALIDATE_EMAIL)){
                
    array_push($errors,"&errorid3b=tripped");
                
            }
        else
            {
                
    $con mysql_connect("localhost","","");
                if (!
    $con)
                  {
                  die(
    'Could not connect: ' mysql_error());
                  }

                
    $db_selected mysql_select_db("SECRET",$con);
                
    $sql "SELECT * FROM musicians WHERE email='$_POST[emailAddress]'";
                
    $result mysql_query($sql,$con);
                if(
    mysql_num_rows($result)>=1){ //Line 31
                    
    array_push($errors,"&errorid3c=tripped");
                }
                else{
                    
    $c++;
                }
            }
        }
        elseif(
    $input=="sex"){
            
    strip_tags($_POST['sex']);
            if(
    $_POST['sex']=="male" || $_POST['sex']=="female"){
                
    $c++;
            }
        else
            {
                
    array_push($errors,"&errorid4b=tripped"); // Line 46
            
    }
        }
        elseif(
    $input=="password"){
            
    strip_tags($_POST['password']);
            
    strip_tags($_POST['password2']);
            if(
    $_POST['password']==$_POST['password2']){
                
    $c++;
            }
        else
            {
                
    array_push($errors,"&errorid5b=tripped");
            }
        }
        elseif((
    checkdate($_POST['month'],$_POST['day'],$_POST['year']))){
        
    $c++;
        }
        else{
            
    array_push($errors,"&errorid6b=tripped");
        }
    }
    ?>
    <?php
    function createAccount(){
        
    $con mysql_connect("localhost","","");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_select_db("SECRET!"$con);
    $sql="INSERT INTO musician (first_name, last_name, email, password, birthday, birthmonth, birthyear, primary_instrument, country) VALUES('$_POST[firstName]','$_POST[lastName]','$_POST[emailAddress]','md5($_POST[password])','$_POST[day]','$_POST[month]','$_POST[year]','$_POST[primary_instrument]','$_POST[country]')";
    if (!
    mysql_query($sql,$con))
      {
      die(
    'Error: ' mysql_error());
      }
    mysql_close($con);
    }
    ?>
    Hopefully I am using array_push correctly. If I'm right, it should insert the error code at the last position of the array? Something like that...

    I don't know whats going on the with the mysql_row_count thingy... I'm just trying to check there to make sure that there are no accounts with that email address.

    Thanks a lot...
    *BTW there is a second part, but its lengthy so let me know if you guys need it to figure out whats wrong...*

  2. #2
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    "mysql_num_rows(): supplied argument is not a valid MySQL result resource" means that the $result you passed to mysql_num_rows() wasn't actually a mySQL result set. This is due to the query not executing properly, so it didn't return any resulset - not even a blank one. I would try doing echo $sql; to see what your query actually looks like when parsed, then try to execute it manually in mySQL. Is it possible one of your field names is wrong? e.g. should "email" be "musician_email" ?

Bookmarks

Posting Permissions

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