Jump to content

mysqli_num_rows Error


Glese

Recommended Posts

This is the form:

 

<form id="submit_form" method="post" action="">	

        
<label for="knuffix_category"><h4>Choose a category</h4></label><br />
     
        <?php 
        require_once ($sort_category_func);
        $switch = 0;
        sort_category ($switch); 
        ?>


<br /><br />

        
        <label for="contribution_description"><h4>Enter your description here</h4></label><br />
        <textarea maxlength="150" type="text" name="contribution_description" value=""></textarea><br />
        
        
        
        
<label for="contribution"><h4>Enter your contribution here</h4></label><br />
<textarea maxlength="300" type="text" name="contribution" value=""></textarea><br />

        
        
<input type="submit" name="submit" value="Contribute" />
        
        
</form>



<?php
    include($submit_script);
?>

 

 

 

 

And this is the script:

 

<?php
if (isset($_POST['submit'])){

if (isset($user_name)) {	
	 // Connect to the database 
	  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
	  
                  
                  
	// Grab the score data from the POST
                
	//$knuffix_name = strip_tags(trim($_POST['knuffix_name']));

                $contribution_name = uniqid();
                
                if (!empty($_POST['contribution_description']))
                    $contribution_description = $_POST['contribution_description'];
               // if (!empty($_POST['knuffix_contribution']))
                    $contribution = $_POST['contribution'];
                // if (!empty($_POST['cat'])) {
                    $contribution_category = strip_tags(trim($_POST['cat']));
               // }
                
                
                  // Check if the fields and variables are empty
                
	  if (!empty($contribution_category) && !empty($contribution)) {

                      
                      
                      
                      // Check if the submission exists twice in the whole database
                      
                      $query_get = "SELECT contribution FROM con WHERE = '{$contribution}'";
                      
                      $query_run = mysqli_query($dbc, $query_get);
                      
                      $num_rows = mysqli_num_rows($query_run);
                      

                   
                      
                      if ($num_rows == 0) {

                      
                          
                          
                          
                          // Write the data into the database
                          
		  $query = sprintf("INSERT INTO con (user_id, name, contribution, category, contribution_date, description) VALUES ('$user_id', '%s', '%s', '%s', now(), '%s')",
				mysqli_real_escape_string($dbc, $contribution_name),
				mysqli_real_escape_string($dbc, $contribution),
				mysqli_real_escape_string($dbc, $contribution_category),
                                        mysqli_real_escape_string($dbc, $contribution_description));

                          
                            mysqli_query($dbc, $query) or die (mysqli_error($dbc));

                            mysqli_close($dbc);
		   
		  /* Set a cookie (later) to prevent duplicate submissions */
		  // redirect the page to prevent duplicate submissions
		//	header ('Location: redirect.php');
		echo 'Contributing was successful.';		  

                                
                          
                                
                                
                      } else {
                          
                          
                          echo "This contribution already exists in the database. 
                              To keep this place clean we do not allow duplicate submissions.";
                          
                          
                          
                      }
                       
                      
                      
                      } else {



                            echo "Please enter all of the information to add your contribution.";



                            }

                        
                        
                      } else {



                            echo "You have to be signed-in to do a contribution.";



                            }
    }
?>

 

 

 

And this is the error message:

 

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\php_projects\myproject\controller\contribution\submit_script.php on line 38

 

 

 

As the error message states it is not becoming a result, and I do not see where the problem lies, everything looks right to me. Does somebody else see a mistake in there?

Link to comment
https://forums.phpfreaks.com/topic/252230-mysqli_num_rows-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.