Glese Posted December 1, 2011 Share Posted December 1, 2011 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 More sharing options...
floridaflatlander Posted December 1, 2011 Share Posted December 1, 2011 I can't see anything right off hand have you tried " or die("Error: ".mysqli_error($dbc));" Link to comment https://forums.phpfreaks.com/topic/252230-mysqli_num_rows-error/#findComment-1293143 Share on other sites More sharing options...
Pikachu2000 Posted December 1, 2011 Share Posted December 1, 2011 WHERE = '{$contribution}' Where what equals $contribution? Link to comment https://forums.phpfreaks.com/topic/252230-mysqli_num_rows-error/#findComment-1293144 Share on other sites More sharing options...
floridaflatlander Posted December 1, 2011 Share Posted December 1, 2011 Yea I just saw that, I don't use '{$contribution}' in a query, i use '$contribution' I don't know if that's it or not. I was hoping someone with more knowledge like Pikachu2000 will chime in. Link to comment https://forums.phpfreaks.com/topic/252230-mysqli_num_rows-error/#findComment-1293147 Share on other sites More sharing options...
Glese Posted December 1, 2011 Author Share Posted December 1, 2011 You have sharp eyes. Thank you a lot. Link to comment https://forums.phpfreaks.com/topic/252230-mysqli_num_rows-error/#findComment-1293150 Share on other sites More sharing options...
Pikachu2000 Posted December 1, 2011 Share Posted December 1, 2011 The curly braces don't matter in this instance. Link to comment https://forums.phpfreaks.com/topic/252230-mysqli_num_rows-error/#findComment-1293184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.