Beginner in php here. I have programmed a form in an html format and then included some php code to direct the form submission to process.php file. The code in process.php will then insert the form submission into MySQL.
The first time I ran the code, it worked perfectly fine. However, I have no idea what happened later as subsequent attempts to run the code results in failure.
After i submit the form, it begins directing me to a blank process.php file. I tried check my code for errors but everything seems to be the same. The error it gives me is:
Parse error: syntax error, unexpected end of file in D:\XAMPP\htdocs\inthoughts\process.php on line 31
I did a search online and realize that the error usually comes from some minor error in the code where i didn't include a ;
or placed the {
in a wrong place. But when i looked into the code, it seems fine, i went through line by line and couldn't find any error.
May I know what is wrong? Thank you.
Below is the form coding for index.php:
<div class="jquery"/>
<form method="post" action="process.php"/>
<ul class="lists">
<li class="title">Personal Details</li>
<li class="fields">
<label>Your Name:</label><br>
<input type="text" name="name" /><br>
<label>Contact Number:</label><br>
<input type="text" name="contact"/><br>
<label>Email:</label><br>
<input type="text" name="email" /><br>
<label>Address:</label><br>
<input type="text" name="address" /><br>
</li>
<li class="title" id="student">Student Details<span style="color:red" id="fontred">(Click Me To Expand!)</span></li>
<li class="fields">
<label>Student Name:</label><br />
<input type="text" name="studentname"/><br />
<label>Student Level:</label><br />
<input type="text" name="level"/><br />
<label>Subject:</label><br />
<input type="text" name="subject"/><br />
<label>Student Stream:</label><br />
<input name="stream" type="text" /><br />
</li>
</ul>
<div class="submit1">
<input type="submit" value="Find me a tutor now!" name="submit1" />
</div>
</form>
Here is the code for process.php:
<?php
include('database.php');
if(isset($_POST['submit1'])){
$name=mysqli_real_escape_string($con,$_POST['name']);
$contact=mysqli_real_escape_string($con,$_POST['contact']);
$email=mysqli_real_escape_string($con,$_POST['email']);
$address=mysqli_real_escape_string($con,$_POST['address']);
$studentname=mysqli_real_escape_string($con,$_POST['studentname']);
$level=mysqli_real_escape_string($con,$_POST['level']);
$subject=mysqli_real_escape_string($con,$_POST['subject']);
$stream=mysqli_real_escape_string($con,$_POST['stream']);
if(!isset($name) || $name=='' || !isset($contact) || $contact=='' || !isset($email) || $email==''
|| !isset($address) || $address==''|| !isset($studentname) || $studentname==''|| !isset($level) || $level==''|| !isset($subject)
|| $subject==''|| !isset($stream) || $stream==''
){
$error="Please fill in all required fields before submission.";
header("Location:index.php?error=".urlencode($error));
exit();
}else{
$sql = "INSERT INTO assignments(name,contact,email,address,studentname,level,subject,stream) VALUES('$name','$contact','$email','$address','$studentname','$level','$subject','$stream')";
}
if(!mysqli_query($con,$sql)){
die("Error".mysqli_error($con));
}else{
header('Location:index.php?status=thanks');
exit();
}
I have edited it and included a }
at the end but it still doesn't work. The new php code for process.php now is:
<?php
include('database.php');
if(isset($_POST['submit1'])){
$name=mysqli_real_escape_string($con,$_POST['name']);
$contact=mysqli_real_escape_string($con,$_POST['contact']);
$email=mysqli_real_escape_string($con,$_POST['email']);
$address=mysqli_real_escape_string($con,$_POST['address']);
$studentname=mysqli_real_escape_string($con,$_POST['studentname']);
$level=mysqli_real_escape_string($con,$_POST['level']);
$subject=mysqli_real_escape_string($con,$_POST['subject']);
$stream=mysqli_real_escape_string($con,$_POST['stream']);
if(!isset($name) || $name=='' || !isset($contact) || $contact=='' || !isset($email) || $email==''
|| !isset($address) || $address==''|| !isset($studentname) || $studentname==''|| !isset($level) || $level==''|| !isset($subject)
|| $subject==''|| !isset($stream) || $stream==''
){
$error="Please fill in all required fields before submission.";
header("Location:index.php?error=".urlencode($error));
exit();
}else{
$sql = "INSERT INTO assignments(name,contact,email,address,studentname,level,subject,stream) VALUES('$name','$contact','$email','$address','$studentname','$level','$subject','$stream')";
}
if(!mysqli_query($con,$sql)){
die("Error".mysqli_error($con));
}else{
header('Location:index.php?status=thanks');
exit();
}