0

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

5
Contributors
5
Replies
39
Views
4 Years
Discussion Span
Last Post by anandatheerthan
2

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

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

and try it again.....

0

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);
}

?>
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.