Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...