I have an HTML form, and I need to past data from it to mysql database in phpMyAdmin. I’m far from php and I don’t know what to do with these errors, also I was unable to set up server and phpMyAdmin locally so I test it right away on the hosting.
index.html:
<section class="form">
<form class="form__wrapper" action="form.php" method="post">
<h2 class="form__wrapper_text">Leave your contacts below</h2>
<div class="form__wrapper_inputs">
<div class="form__wrapper_inputs_number">
<p>Phone</p>
<input type="tel" value="+380">
</div>
<div class="form__wrapper_inputs_name">
<p>Name</p>
<input type="text">
</div>
<div class="form__wrapper_inputs_company">
<p>Company</p>
<input type="text">
</div>
<div class="form__wrapper_inputs_email">
<p>Email</p>
<input type="email">
</div>
<div class="form__wrapper_inputs_energy" >
<p>Consumption</p>
<input type="text" pattern="[0-9]*">
</div>
<button type="submit" class="form__wrapper_inputs_send">Submit</button>
</div>
</form>
</section>
form.php:
<?php
$dbhost = "***Link to phpmyadmin of my hosting***";
$dbuser = "***phpmyadmin unsername***";
$dbpass = "***phpmyadmin password";
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn) {
die('Could not connect: ' . mysqli_error());
}
if(isset($_POST['submit']))
{
$number = $_POST['number'];
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$consumption = $_POST['consumption'];
$insert = mysqli_query($db,"INSERT INTO `form`(`number`, `name`, `company`, `email`, `consumption`) VALUES ('$number',
'$name', '$company', '$email', '$consumption')");
if(!$insert)
{
echo mysqli_error();
}
else
{
echo "Records added successfully.";
}
}
mysqli_close($conn);
?>
When I press submit button, I get following errors:
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name does not resolve in /sata2/home/users/***user***/www/***site***/form.php on line 5
Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name does not resolve in /sata2/home/users/***user***/www/***site***/form.php on line 5
Warning: mysqli_error() expects exactly 1 parameter, 0 given in /sata2/home/users/***user***/www/***site***/form.php on line 8
Could not connect:
In comments I’ve been told that $dbhost
variable is wrong, but I’m not sure what to use there. If I assign it IP of my hosting, I get timed out error.
3
Answers
You are connecting to mysql not to phpmyadmin.
So you should change your credentials like this:
These credentials have been provided to you by your hosting.
$dbuser
and$dbpass
are the same that you use for phpmyadmin but the dbhost should be differentit would be network configuration. The database server is blocking ext-connection to port 3306.
Those info should be:
Make sure your server open port 3306 from your webserver.
Thanks.
index.html (note: you are missing the HTML input element name attributes, so nothing is being sent)
form.php