I'm having trouble inserting data into myqsl database from a form using php. This error displays:
Can someone show me what's wrong with this code? I'm using extract ($_POST) to get the input fields from the superglobal $_POST array.Meanwhile when i separate the form code from the php part of code and place them in separate php files it works correctly and the error doesn't display. Can someone shows me what's wrong with executing them in the same php file like this code attached here? Here is my code in php :
<html>
<html >
<head>
<title></title>
</head>
<body>
<?php
print ("<form action='p.php' method='post'>
<p>Name
<input type='text' name='firstname' />
</p>
<p>Surname
<input type='text' name='lastname' />
</p>
<p>Username
<input type='text' name='username' />
</p>
<p>Password
<input type='password' name='password' />
<p/>
<input type='submit' value='Log In'/>
</form>");
extract ($_POST);
if( !($database=mysql_connect("localhost","root",""))||!(mysql_select_db("st_login",$database)) )
print("Could not connect");
$query = "INSERT INTO login (firstname, lastname, username,password) VALUES ('$firstname', '$lastname', '$username','$password')";
if(isset($_POST['firstname'] )&&isset($_POST['lastname'])&&isset($_POST['username'])&&isset($_POST['password']) ){
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$username=$_POST['username'];
$password=$_POST['password'];
}
if ( !empty($firstname)&&!empty($lastname)&&!empty($username) &&!empty($password) ){
if(!($result=mysql_query($query,$database)))
{
print("Could not execute query");
die (mysql_error());//ose error
}
else echo "You are logged in successfully";
}
else echo "Fill in all the blank fields";
mysql_close($database);
?>
</body>
</html>