hi ,i am new to php i have problem with my code . problem is when ever a page is loded

<?php

if(isset($_POST['submit']));

{
$conn=mysql_connect("localhost","root","vamshi");
if(!$conn)
{
die("couldn't Connected : " .mysql_error());
}

mysql_select_db("ninepixel",$conn);

$sql="insert into  empattendence (name,daydate,choice) values('$_POST[name]',now(),'$_POST[choice]')";

if(mysql_query($sql,$conn))

{
echo("Your Data Has been Submitted");
}

else{

echo("Please Enter All the Fields");

}
mysql_close($conn);

}

?>

or refreshing it inserting a blank row in table,i want to insert data after filled the fields and click the button it has to insert pls help me

hi...
pls remove the ";" this from

if(isset($_POST['submit']));

and try it again.....

As amiyar posted is correct, but here is a better way to write your code ;)

<?php

if(isset($_POST['submit'])){
    $conn=mysql_connect("localhost","root","vamshi") or die(mysql_error());
    mysql_select_db("ninepixel",$conn) or die(mysql_error());
    $sql="INSERT into  empattendence (name,daydate,choice) VALUES('$_POST[name]',now(),'$_POST[choice]')";

    if(mysql_query($sql,$conn)){
        echo("Your Data Has been Submitted");
    }else{
        echo("Please Enter All the Fields");
    }
    mysql_close($conn);
}

?>

thanks for ur code and help

Please mark this post as solved ... if your code is finally working

its better to use PDO instead of old mysql_connect(),mysql_query() methods are these are deprecated in latest php versions. You will also have better security against attacks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.