Abdullah Nurum Abdullah Nurum - 4 months ago 4x
PHP Question

how to add count number to insert value

There are a questions in mysql, and user can add questions. when user add question,I want to the question number equal to question count, since the question number start from 0. I know problem come from here,

$results=mysqli_query($link,"SELECT count(*) from Question");
echo $data;
but I don't know how to solve this, and I tried a lot, but I failed. How to change my code? Thank you ver much for helpers. here is my full php code.

if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;

$results=mysqli_query($link,"SELECT count(*) from Question");
echo $data;

echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;

$Question = isset($_GET["Question"]) ? $_GET["Question"] : '';

$AnswerA = isset($_GET["AnswerA"]) ? $_GET["AnswerA"] : '';

$AnswerB = isset($_GET["AnswerB"]) ? $_GET["AnswerB"] : '';

$AnswerC = isset($_GET["AnswerC"]) ? $_GET["AnswerC"] : '';

$AnswerD = isset($_GET["AnswerD"]) ? $_GET["AnswerD"] : '';

$CorrectAnswer = isset($_GET["CorrectAnswer"]) ? $_GET["CorrectAnswer"] : '';

$Explanation = isset($_GET["Explanation"]) ? $_GET["Explanation"] : '';

$query = "INSERT INTO Question VALUES ('$data','0','0','0','0','0','0','0','0','0','0','0','0', '$Question', '$AnswerA', '$AnswerB', '$AnswerC', '$AnswerD', '$CorrectAnswer', '$Explanation')";
mysqli_query($link, $query) or die (mysqli_error("error"));




$results=mysqli_query($link,"SELECT count(*) as num from Question");
$myNo = $data['num'];

$query = "INSERT INTO Question VALUES ($myNo,...)";

So on..