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'];
?>