thebenman thebenman - 1 month ago 8
Apache Configuration Question

Error connecting to MySQL in XAMPP

I have created this simple PHP code for a login page


<head>
<title>Login Page</title>
</head>
<body>
<form method=POST>
<table>
<tr><th>UserName</th>
<td><input type=text name=user></input></td></tr>
<tr><th>Password</th>
<td><input type=password name=pass></input></td></tr>
<tr><th>Phone Number</th>
<td><input type=text name=phone></input></td></tr>
<tr><th>Email</th>
<td><input type=text name=email></input></td></tr>
<tr><th>City</th>
<td><input type=text name=city></input></td></tr>
<tr><td><input type=submit name=submit value=Submit></input></td></tr>
</table>
</form>

</body>
</html>
<?php
if(isset($_POST['submit']) && !empty($_POST['user']))
{
if(preg_match("/^[a-zA-Z ]{3,40}$/",$_POST['user']))
{
if(preg_match("/^[a-zA-Z0-9]{8,20}$/",$_POST['pass']))
{
if(filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
if(preg_match("/[0-9]{10}/",$_POST['phone']))
{
$username=$_POST['user'];
$password=$_POST['pass'];
$Email=$_POST['email'];
$phoneNumber=$_POST['phone'];
$con=mysqli_connect("localhost:8080","root","","user");
mysqli_query($con,"insert into user values('$username','$Email','$phoneNumber','$city')");

}
else
{
echo "Invalid Phone number";
}
}
else
{
echo "Invalid Email";
}
}
else
{
echo "Invalid Phone number";
}
}

else
{
echo "Invalid user";
}

}

?>


Whenever i run this script and try to insert values into the tables, it takes a lot of time and throws the following error/Warning. I have not changed the username and password and i believe by default it is root and blank.

Warning: mysqli_connect(): MySQL server has gone away in C:\xampp\htdocs\home.php on line 39

Warning: mysqli_connect(): Error while reading greeting packet. PID=4708 in C:\xampp\htdocs\home.php on line 39

Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\xampp\htdocs\home.php on line 39

Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\home.php on line 39

Could someone help me with this as i believe that the problem lies with some of the port configuration.

Thanks and regards.

Answer

By default, connecting to DB using XAMPP doesn't require you to specify the port. Replace localhost:8080 with localhost