Web Analytics Made Easy -
StatCounter validate true false - CodingForum

Announcement

Collapse
No announcement yet.

validate true false

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • validate true false

    Hi everyone,
    I hope someone can help me, I’m not that good with php, but I often find very generous people in this group willing to give me a hand.
    I will try my best to explain how the script should work.
    I would like to use one of mysql database field ("approve") and have it validated by using using a true or false statement.
    When the script is searching mysql database and finds the field approve as false it should give me give me the following message “Registration Pending” and end the script, if no search string found the following message “The Name not Registered you may use this name to Register a new Cultivar” and end script
    The field (approve) defaults to false
    if it finds the field true, then it should display all data.
    please help me


    PHP Code:
    <?PHP

    $link 
    mysql_connect('localhost''xxxx_jxxxx''jxxxx');
    if (!
    $link) {   die('Could not connect: ' mysql_error()); }
    mysql_select_db('xxxxx');

    // Fetch total number of records
    $result mysql_query("SELECT COUNT(*) AS recordCount FROM ihsreg");
    $row mysql_fetch_assoc($result);
    $recordCount $row['recordCount'];


    // Perform Search
    $results = array();
    if(isset(
    $_REQUEST['search'])){
        
        
    $limit 20;
        if(
    $_GET['offset']){ $offset $_GET['offset']; } else { $offset 0; }

        
    $SQL "SELECT * FROM ihsreg ";

        
    //$term = strtoupper(addslashes($_REQUEST['search']));
        
    $term strtoupper($_REQUEST['search']);
        if(
    stristr($term,"'") && !stristr($term,"\'")){
            
    $term addslashes($term);
        }

        if(
    $_REQUEST['radiobutton']){
            switch(
    $_REQUEST['radiobutton']){
            case 
    '1'$SQL.=" WHERE Bloom_Name LIKE \"$term\""; break;
            case 
    '2'$SQL.=" WHERE Pod_Name LIKE \"$term\""; break;
            case 
    '3'$SQL.=" WHERE Pollen_Name LIKE \"$term\""; break;
            case 
    '4'$SQL.=" WHERE Hybridiser LIKE \"$term\""; break;
            case 
    '5'$SQL.=" WHERE Origin LIKE \"$term\""; break;
            case 
    '6'$SQL.=" WHERE Grower LIKE \"$term\""; break;
            case 
    '7'$SQL.=" WHERE Color_Group LIKE \"$term\""; break;
            case 
    '8'$SQL.=" WHERE Bloom_Type LIKE \"$term\""; break;
            case 
    '9'$SQL.=" WHERE Reg_Mini LIKE \"$term\""; break;
            case 
    '10'$SQL.=" WHERE Size_Range LIKE \"$term\""; break;
            case 
    '11'$SQL.=" WHERE Propagation LIKE \"$term\""; break;
            case 
    '12'$SQL.=" WHERE Bloom_Color LIKE \"$term\""; break;
            case 
    '13'$SQL.=" WHERE Bloom_Characteristics LIKE \"$term\""; break;
            case 
    '14'$SQL.=" WHERE Leaf_Characteristics LIKE \"$term\""; break;
            case 
    '15'$SQL.=" WHERE Bush_Characteristics LIKE \"$term\""; break;
            case 
    '24'$SQL.=" WHERE Cross_Made LIKE \"$term\""; break;
            case 
    '25'$SQL.=" WHERE date LIKE \"$term\""; break;
                    default: 
    $SQL.=" WHERE Bloom_Name LIKE \"$term\""; break;
            } 
    // switch
        
    } else {
            
    // If they didnt' select a radio button... 
            
    $SQL.=" WHERE Bloom_Name LIKE \"$term\"";
        }

        
    $result mysql_query($SQL);
        
    $resultCount mysql_num_rows($result);
        
        
    $SQL.= " LIMIT $offset$limit";

        
    $result mysql_query($SQL);
        
        if(
    $resultCount 0){
            while(
    $row mysql_fetch_assoc($result)){
                
    $results[$row['id']] = $row;
            } 
    // while
        
    // if there are results
    // if user performed a search
    ?>

  • #2
    Im not 100% sure what you are trying to do. To get it to exit if field approve was false you can use break to exit the while loop.
    Is the search string you refer to $term in your code. And you want it to exit if that was not found (well something similar found also), but it only checks it against the value submitted by your radio button? Well since you are using that as a WHERE clause in your SQL if it wasn't found it simply wont return any results so mysql_num_rows would return 0. So you can just echo the string if $resultCount==0

    Heres the code

    PHP Code:
    <?php

    $breakstring
    ='';

    $link mysql_connect('localhost''xxxx_jxxxx''jxxxx');
    if (!
    $link) {   die('Could not connect: ' mysql_error()); }
    mysql_select_db('xxxxx');

    // Fetch total number of records
    $result mysql_query("SELECT COUNT(*) AS recordCount FROM ihsreg");
    $row mysql_fetch_assoc($result);
    $recordCount $row['recordCount'];


    // Perform Search
    $results = array();
    if(isset(
    $_REQUEST['search'])){
        
        
    $limit 20;
        if(
    $_GET['offset']){ $offset $_GET['offset']; } else { $offset 0; }

        
    $SQL "SELECT * FROM ihsreg ";

        
    //$term = strtoupper(addslashes($_REQUEST['search']));
        
    $term strtoupper($_REQUEST['search']);
        if(
    stristr($term,"'") && !stristr($term,"\'")){
            
    $term addslashes($term);
        }

        if(
    $_REQUEST['radiobutton']){
            
    $fields=array(=> "Bloom_Name"=> "Pod_Name"=> "Pollen_Name"=> "Hybridiser"=> "Origin"=> "Grower"=> "Color_Group"=> "Bloom_Type"=> "Reg_Mini"10 =>  "Size_Range"11 => "Propagation"12 => "Bloom_Color"13 => "Bloom_Characteristics"14 => "Leaf_Characteristics"15 => "Bush_Characteristics"16 => "Cross_Made"24 => "date"25 => "Bloom_Name");

            
    $SQL.=" WHERE \"$fields[(int)$_REQUEST['radiobutton']]\" LIKE \"$term\""; break;
        } else 
        {
            
    // If they didnt' select a radio button... 
            
    $SQL.=" WHERE Bloom_Name LIKE \"$term\"";
        }

        
    $result mysql_query($SQL);
        
    $resultCount mysql_num_rows($result);
        
        
    $SQL.= " LIMIT $offset$limit";

        
    $result mysql_query($SQL);
        
        if(
    $resultCount 0){
            while(
    $row mysql_fetch_assoc($result)){
                
    // What does the line below do
                  // $results[$row['id']] = $row;

                    
    if($row['approve'] == false) {$breakstring='Registration Pending';break;}
            } 
    // while
        
    }
    else
    {
         
    $breakstring='The Name not Registered you may use this name to Register a new Cultivar';
    // if there are results
    // if user performed a search

    if(!empty($breakstring))
    {
         echo 
    $breakstring;
    // do what ever
    }
    else
    {
     
    // do whatever else
    }

    ?>
    This code is untested but should work ok, provided i have grasped what you are trying to do?
    Last edited by timgolding; Apr 2, 2009, 05:14 AM.
    You can not say you know how to do something, until you can teach it to someone else.

    Comment


    • #3
      Hi thanks for your help
      I'm getting the following error

      Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

      Comment


      • #4
        Ah so there are errors, as i said i didn't test it. There is an error on line 33 and 37. This code should work however.

        PHP Code:
        <?php

        $breakstring
        ='';

        $link mysql_connect('localhost''xxxx_jxxxx''jxxxx');
        if (!
        $link) {   die('Could not connect: ' mysql_error()); }
        mysql_select_db('xxxxx');

        // Fetch total number of records
        $result mysql_query("SELECT COUNT(*) AS recordCount FROM ihsreg");
        $row mysql_fetch_assoc($result);
        $recordCount $row['recordCount'];


        // Perform Search
        $results = array();
        if(isset(
        $_REQUEST['search'])){
            
            
        $limit 20;
            if(
        $_GET['offset']){ $offset $_GET['offset']; } else { $offset 0; }

            
        $SQL "SELECT * FROM ihsreg ";

            
        //$term = strtoupper(addslashes($_REQUEST['search']));
            
        $term strtoupper($_REQUEST['search']);
            if(
        stristr($term,"'") && !stristr($term,"\'")){
                
        $term addslashes($term);
            }

            if(
        $_REQUEST['radiobutton']){
                
        $fields=array(=> "Bloom_Name"=> "Pod_Name"=> "Pollen_Name"=> "Hybridiser"=> "Origin"=> "Grower"=> "Color_Group"=> "Bloom_Type"=> "Reg_Mini"10 =>  "Size_Range"11 => "Propagation"12 => "Bloom_Color"13 => "Bloom_Characteristics"14 => "Leaf_Characteristics"15 => "Bush_Characteristics"16 => "Cross_Made"24 => "date"25 => "Bloom_Name");

                
        $SQL.=" WHERE ".$fields[(int)$_REQUEST['radiobutton']]." LIKE '".$term."'"; break;
            } else 
            {
                
        // If they didnt' select a radio button... 
                
        $SQL.=" WHERE Bloom_Name LIKE ".$term;
            }

            
        $result mysql_query($SQL);
            
        $resultCount mysql_num_rows($result);
            
            
        $SQL.= " LIMIT $offset$limit";

            
        $result mysql_query($SQL);
            
            if(
        $resultCount 0){
                while(
        $row mysql_fetch_assoc($result)){
                    
        // What does the line below do
                      // $results[$row['id']] = $row;

                        
        if($row['approve'] == false) {$breakstring='Registration Pending';break;}
                } 
        // while
            
        }
        else
        {
             
        $breakstring='The Name not Registered you may use this name to Register a new Cultivar';
        // if there are results
        // if user performed a search

        if(!empty($breakstring))
        {
             echo 
        $breakstring;
        // do what ever
        }
        else
        {
         
        // do whatever else
        }

        ?>
        You can not say you know how to do something, until you can teach it to someone else.

        Comment

        Working...
        X