我的代码旨在从用户那里获取一个简短的文本和标题,并将它们添加到数据库中两次,并且无法理解原因.
<?php ("session.php"); ?>
<?php require_once("connect.php"); ?>
<?php include("header.php"); ?>
<?php
//if the submit button is pressed then the INSERT SQL statement is submitted to database
//if (isset($_POST['testimonial_title']) && isset($_SESSION['testimonial_text'])) {
if(isset($_POST["submit_button"])){
$title=$_POST["testimonial_title"];
$text=$_POST["testimonial_text"];
//create the sql statement
$sql=
"INSERT INTO testimonials
(testimonial_title, testimonial_text, student_ID)
VALUES(
'$title',
'$text',
1);"; //for simplicity the student_ID is kept the same
$result = mysqli_query($con,$sql);
if(!mysqli_query($con, $sql))
{
echo "Journal entry was not entered successfully";
}
else{
echo "Journal entry was entered successfully";
}
mysqli_close($con); …Run Code Online (Sandbox Code Playgroud)