i have a web host, which has MySQL, and phpMyAdmin. The code below shows the PHP in my .php file. When i submit the form, the data does not store in the SQL database.
My database is a table called 'Logins'. It has three fields: 'userID' which is an autoincrement type,'email' which is a VARCHAR, and 'password' which is also a VARCHAR.
I have tested my connection, and it does work, meaning something in the code is wrong, but i can't find it. I would be grateful if you guys could help me.
This is my code:
<form action="index.php" method="post">
<p>Email Address:</p>
<input type="text" name="email" required autofocus pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" placeholder="Please enter your email">
<p>Password:</p>
<input type="text" name="password" required placeholder="Enter your password">
<p>Confirm Password:</p>
<input type="text" name="confirmpassword" required placeholder="Confirm your password">
<br>
<input class="button" type="submit" value="Register">
</form>
<?php
if($_POST['submit']=="Submit")
{
$email = cleanData($_POST['email']);
$password = cleanData($_POST['password']);
$message = "wrong answer";
addData($email, $pasword);
}
function cleanData($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
$data = strip_tags($data);
return $data;
}
function addData ($email, $password)
{
//include("dbinfo.php");
$dbhost = 'mysql11.000webhost.com';
$dbuser = '************'; //censored for security
$dbpass = '******'; //censored for security
$conn = mysql_connect("$dbhost", "$dbuser", "$dbpass");
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql="INSERT INTO Logins ('userID','email','password') VALUES (null, '$email', '$password')";
$result=mysql_query($sql) or die(mysql_error());
}
?>