Parse error: syntax error, unexpected ;

I'm sorry if this has been mentioned many times in the thread but I just want to ko some answer. Can someone tell me how I got an error like this

Parse error: syntax error, unexpected ';' in C:xampphtdocscreate.php on line 8

Here is my code:

<?php

mysql_connect("localhost","root");
mysql_select_db("comment");

if(isset($_POST['submit']))
    (
        $Name = $_POST['name'];
        $Email = $_POST['email'];


        mysql_query("INSERT INTO demo (c_name,c_email) VALUES ('$Name','$Email')");

        echo "Inserted !!!";
    )
?>
<form method = "post" action = "">
    <div>
            <label for="name">Your Name</label>
            <input type="text" name="name" id="name">

            <label for="email">Your Email</label>
            <input type="text" name="email" id="email">

            <label for="submit">Submit</label>
            <input type="submit" name="submit" id="submit">

    </div>


</form>

I'm pretty sure the php codes are correct so I ended up in confusion.

PS I've acknowledged that mysql_function are outdated now but I don't have the luxury to study for PDO or mysqli_ this semestral end term. Thanks


if clauses in PHP have to be surrounden with curly brackets:

if(statement) { /* your code goes here */ }

Your code works this way:

if(isset($_POST['submit']))
{
        $Name = $_POST['name'];
        $Email = $_POST['email'];


        mysql_query("INSERT INTO demo (c_name,c_email) VALUES ('$Name','$Email')");

        echo "Inserted !!!";
}

BTW [OT]: beware of SQL injections.


I am not sure why people don't use any IDE like phpStorm or NetBeans

If you were using an IDE you should see something like this and never post this question:

在这里输入图像描述

You can guess something is wrong with (

<?php
mysql_connect("localhost","root");
mysql_select_db("comment");

if(isset($_POST['submit'])) {
    $Name = $_POST['name'];
    $Email = $_POST['email'];


    mysql_query("INSERT INTO demo (c_name,c_email) VALUES ('$Name','$Email')");

    echo "Inserted !!!";
}
?>
<form method = "post" action = "">
    <div>
        <label for="name">Your Name</label>
        <input type="text" name="name" id="name">

        <label for="email">Your Email</label>
        <input type="text" name="email" id="email">

        <label for="submit">Submit</label>
        <input type="submit" name="submit" id="submit">

    </div>


</form>
链接地址: http://www.djcxy.com/p/69458.html

上一篇: 语法错误,意外的'。' 在PHP OOP中

下一篇: 解析错误:语法错误,意外;