dongweng9474 2015-06-27 06:41
浏览 120
已采纳

process.php无法正常工作,不知道为什么尽管尝试了多次并在线搜索

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();
}
  • 写回答

2条回答 默认 最新

  • doumei2023 2015-06-27 07:33
    关注

    The first expression has no closing }. It pays to format your code, like"

    <?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')";
        }
    } // end $_POST['submit1']
    if(!mysqli_query($con,$sql)){
        die("Error".mysqli_error($con));
    }else{
        header('Location:index.php?status=thanks');
        exit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂