Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

php - 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.

P.S. 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...