I am trying to connect to a MySQL database to save information passed via a registration form on my website. for some reason, it won't connect. I have searched in Stack Overflow but can't find the right answer.
Here is my PHP code:
<?php
$con = mysqli_connect("mysite","my username","my password","My database");
if($con === false){
die("ERROR: Could not connect. ". mysqli_connect_error());
}
$sql = "CREATE TABLE clients(client_id INT(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, username CHAR(30) NOT NULL, password CHAR(30) NOT NULL)";
if (mysqli_query($con, $sql)){
echo "Table clients created successfully";
}
else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($con);
}
$user_info = “INSERT INTO clients(username, password) VALUES ( '$_POST["username"]','$_POST["password"]')”;
mysqli_query($con,$user_info);
if (!mysqli_query($con, $user_info)){
die('Error: ' . mysql_error());
}
echo “Your information was added to the database.”;
mysqli_close($con);
?>
And here is my HTML code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<div class="register">
<h1>Register Here</h1>
<form action="register.php" method="post">
<input type="text" id="username" placeholder="Username" required="required" /><br><br>
<input type="password" id="password" placeholder="Password" required="required" /><br>
<button id="btnreg" type="submit">Let Me In</button>
</form>
</div>
</body>
</html>
When I press the submit button, it just shows me a black page, with no errors, and in phpMyAdmin, the table has not been created and of course the information has not been passed. I'm using GoDaddy hosting if it has any signification for this issue, and i have checked like 25 times that I'm using the correct hostname and database information.
Thanks.