I am simply trying to call a table and check if the user inputted username maches any in the table, however I am always geting the 'your new here' response. If I put single quotes around $UserName then it will always return true instead.
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>DunGen</h1>
<?php
$email = $_POST["email"];
$name = $_POST["name"];
require_once('config.inc.php');
$mysqli = new mysqli($database_host, $database_user, $database_pass, $database_name);
if($mysqli -> connect_error) {
die('Connect Error ('.$mysqli -> connect_errno.') '.$mysqli -> connect_error);
}
if($result = $mysqli -> query("SELECT * FROM UserDetails WHERE UserName=$name"))
{
echo "Welcome back ",$name, "<br>";
}
else
{
echo "Hello ",$name, " you're new here ain't yah? <br>";
$sql = "INSERT INTO UserDetails (UserName, UserEmail) VALUES ('$name','$email')'";
}
if (filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo " Email adress: ", $email;
}
else
{
echo "Invalid Email";
}
echo "<br>";
//copied from w3 schools
$conn->close();
?>
</body>
<html>
fixed edit: following the advice given I replaced the if statement with these two lines:
$result = mysqli_query($mysqli,"SELECT * FROM UserDetails WHERE UserName='$name'");
if($result ->num_rows == 0)
simply put I was evaluating weather I had correct SQL, not weather or not it was returning correctly.
Mark Bakerin the name field of your form and submit,SELECT * FROM UserDetails WHERE UserName='Mark Baker'would be valid,SELECT * FROM UserDetails WHERE UserName=Mark Bakerwould be invalid