I am trying to submit this form data to another database using php on xampp server. Once i click on submit it shows waiting for localhost and does not even save the entries in the database. I have made the changes in the xampp to listen on port 8080.I am pretty new to php. Thanks in advance!
Here is my html
<!DOCTYPE html>
<html>
<body>
<form action="submit.php" method=post">
First name:<br>
<input type="text" name="firstname" >
<br>
Last name:<br>
<input type="text" name="lastname" >
<br><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Here is my php code
<?php
$x=$_POST['firstname'];
$y=$_POST['lastname'];
$servername= 'localhost';
$username = 'root';
$password = '';
$dbname = 'db1';
$port = 8080;
//$mysqli = new mysqli("localhost", "username", "password", "dbname");
$conn = new mysqli($servername, $username, $password, $dbname, $port);
echo "Connection successful!" . "<bc>";
$sql = "INSERT INTO user (fname, lname) VALUES ('$x', '$y')";
if($conn->query($sql) === TRUE){
echo "New record created successfully";
} else {
echo "<bc> Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
I also seem to get the following errors: Notice: Undefined index: first in F:\Xampp\htdocs\Project\submit.php on line 3
Notice: Undefined index: last in F:\Xampp\htdocs\Project\submit.php on line 4
Warning: mysqli::__construct(): MySQL server has gone away in F:\Xampp\htdocs\Project\submit.php on line 13
Warning: mysqli::__construct(): Error while reading greeting packet. PID=4572 in F:\Xampp\htdocs\Project\submit.php on line 13
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone away in F:\Xampp\htdocs\Project\submit.php on line 13
Fatal error: Maximum execution time of 120 seconds exceeded in F:\Xampp\htdocs\Project\submit.php on line 13