dojo Posted April 3, 2014 Share Posted April 3, 2014 Hello everyone, I am new to php coding and i am currently trying to check for duplicate data when inserting new values (i.e. a question) in mysql database table. I keep getting this error 'Warning: mysqli_num_rows() expects exactly 1 parameter,2 given in'. Below is the code i am currently working with. Thanks in advance <?php session_start(); $link = mysqli_connect("elephant.ecs.westminster.ac.uk", "w1268094", "euMm27FZwZDK", "w1268094_0"); ?> <?php //Error reporting due to long script error_reporting(E_ALL); ini_set('display_errors','1'); ?> <?php ob_start(); //Add question to table If (isset($_POST['question'])) { $question = mysqli_real_escape_string($link, $_POST['question']); $date = mysqli_real_escape_string($link, $_POST['questiondate']); //See if question is identical to another question in the table $sql = mysqli_query($link,"SELECT pQuestionNo FROM presidentQuestion WHERE pQuestion='$question'LIMIT 1"); $questionMatch = mysqli_num_rows($link, $sql); //count the output amount if ($questionMatch>0){ echo 'Sorry you tried to place a duplicate "Question" into the table, <a href="inventory.php">Click here</a>'; exit(); } //Add the question to the database $sql = mysqli_query($link,"INSERT INTO presidentQuestion (pQuestion,pDate) VALUES ('". mysqli_real_escape_string($link, $question) ."','". mysqli_real_escape_string($link, $date) ."')") or die (mysqli_error($link)); header("location: inventory.php"); exit(); } ?> <?php //Grabs the whole queston list $question_list=""; $sql = mysqli_query($link,"SELECT * FROM presidentQuestion LIMIT 0,10") or die(mysql_error()); $questionCount = mysqli_num_rows($sql);// count the output amount if($questionCount>0){ while($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){ $question = $row["pQuestion"]; $date = $row["pDate"]; $question_list .= "$question <br/>"; } }else{ $question_list = "There are no questions in the inventory yet"; } ?> <?php $prop_id = $_GET['prop_id']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/287503-warning-mysqli_num_rows-expects-exactly-1-parameter/ Share on other sites More sharing options...
ginerjm Posted April 3, 2014 Share Posted April 3, 2014 (edited) You get that when you don't have a query that ran. ALWAYS check the results of an operation to be sure it worked before moving on. Also as a newbie - you should read the posts at the top of the forum that say to please read them. This very problem is discussed there since everybody goes thru it once. Also I notice that your insert query is doing a second escape on your args. Not good. You already did it once, why are you doing it again? Edited April 3, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/287503-warning-mysqli_num_rows-expects-exactly-1-parameter/#findComment-1474858 Share on other sites More sharing options...
dojo Posted April 3, 2014 Author Share Posted April 3, 2014 Hi ginerjm, ps can u send me a ,link of the posts u recommend i read thanks Quote Link to comment https://forums.phpfreaks.com/topic/287503-warning-mysqli_num_rows-expects-exactly-1-parameter/#findComment-1474865 Share on other sites More sharing options...
ginerjm Posted April 3, 2014 Share Posted April 3, 2014 How about (like I said) the post at the top of this VERY FORUM that says "Readme". Quote Link to comment https://forums.phpfreaks.com/topic/287503-warning-mysqli_num_rows-expects-exactly-1-parameter/#findComment-1474867 Share on other sites More sharing options...
dojo Posted April 3, 2014 Author Share Posted April 3, 2014 I honestly cannot see any post at the top of this forum. I am new to this website Quote Link to comment https://forums.phpfreaks.com/topic/287503-warning-mysqli_num_rows-expects-exactly-1-parameter/#findComment-1474870 Share on other sites More sharing options...
ginerjm Posted April 3, 2014 Share Posted April 3, 2014 Don't know why you can't - it's right up there with other info about this site. You are at the top of THIS forum and not the freaks home page? Quote Link to comment https://forums.phpfreaks.com/topic/287503-warning-mysqli_num_rows-expects-exactly-1-parameter/#findComment-1474871 Share on other sites More sharing options...
dojo Posted April 3, 2014 Author Share Posted April 3, 2014 By this forum do u mean the page with the question i just asked? IF yes then i can't see. Can u send me a link Quote Link to comment https://forums.phpfreaks.com/topic/287503-warning-mysqli_num_rows-expects-exactly-1-parameter/#findComment-1474873 Share on other sites More sharing options...
ginerjm Posted April 3, 2014 Share Posted April 3, 2014 This is the link to this forum. http://forums.phpfreaks.com/forum/13-php-coding-help/ The first post is labeled "README: PHP Resources & FAQs Quote Link to comment https://forums.phpfreaks.com/topic/287503-warning-mysqli_num_rows-expects-exactly-1-parameter/#findComment-1474878 Share on other sites More sharing options...
DavidAM Posted April 3, 2014 Share Posted April 3, 2014 If the error message is: 'Warning: mysqli_num_rows() expects exactly 1 parameter,2 given in'. Try looking at that line: $sql = mysqli_query($link,"SELECT pQuestionNo FROM presidentQuestion WHERE pQuestion='$question'LIMIT 1"); $questionMatch = mysqli_num_rows($link, $sql); //count the output amount mysqli returns an object, so you don't need to pass the link, just the result (in your case $sql). So, it needs only 1 parameter (like the error message says). Quote Link to comment https://forums.phpfreaks.com/topic/287503-warning-mysqli_num_rows-expects-exactly-1-parameter/#findComment-1474894 Share on other sites More sharing options...
ginerjm Posted April 4, 2014 Share Posted April 4, 2014 My bad - and my apology. I didn't read the initial error message completely and made an assumption. Glad someone else re-directed the OP. Quote Link to comment https://forums.phpfreaks.com/topic/287503-warning-mysqli_num_rows-expects-exactly-1-parameter/#findComment-1474906 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.