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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.