I am trying to create a form that will take a title, block of text, student ID and add it to a database when the submit button is pressed.
The student_ID
is kept the same for simplicity and will be changed later in the project.
The HTML and PHP are in the same file.
My code doesn't add anything to the database.
PHP
<?php
if($_POST["submit_button"]){
//here is the title and text that will be added to the database by the user
$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);"; //the student_ID is a foreign key and for simplicity I kept it at 1
$result = mysqli_query($con,$sql);
mysqli_close($con);
}
?>
HTML
<<!--Page Content-- >
<h1 class="page-header">
Learning Journals<small>- Admin</small>
</h1>
<h3>
Update Learning Journals Plans
</h3>
<form name = "membership_form"
action = ""
id = "contactForm"
method = "post">
<label>Learning Journals Title:</label><br/>
<input type="text" name="testimonial_title" /><br/>
<label>Learning Journal:</label><br/>
<textarea rows="10" cols="100" name="testimonial_text"
maxlength="999" style="resize:none"></textarea>
<button type="submit" name ="submit_button" class="btn btn-primary">
Update
</button>
</form>
<hr/>
</body>
</html>