Some reason my register.php is only saving the username and reloading that page with its value saved. I can't figure out why none of the errors come up.
<?php
include('deep_down/init.inc.php');
$errors = array();
if (isset($_POST['username'], $_POST['password'], $POST['check_password']))
{
if (empty($_POST['username']))
{
$errors[] = 'You need a username.';
}
if (empty($_POST['password']) || empty($_POST['check_password']))
{
$errors[] = 'You need a password.';
}
if ($_POST['passowrd'] !== $_POST['check_password'])
{
$errors[] = 'The passwords do not match.';
}
if(user_exists($_POST['username']))
{
$errors[] = 'The username is already taken.';
}
if (empty($errors))
{
add_user($_POST['username'], $_POST['password']);
$_SESSION['username'] = htmlentities($_POST['username']);
header('Location: home.php');
die();
}
}
?>
<html>
<head>
</head>
<body>
<p>
<?php
// display error messages
if (empty($errors) === false)
{
?>
<ul>
<?php
foreach ($errors as $error)
{
echo"</li>($error)</li>";
}
?>
</ul>
<?php
}
?>
</p>
<div>
<form action="" method="post">
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php if(isset($_POST['username'])) echo htmlentities($_POST['username']); ?>">
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="password">
</p>
<p>
<label for="check_password">Check Password:</label>
<input type="password" name="check_password" id="check_password">
</p>
<p>
<input type="submit" value="Submit" />
</form>
</p>
</div>
</body>
</html>
Thanks again Temor that helped me figure out that it wasn't connecting to my database. I had to change the code a bit since I'm not connecting to a local db.
but now it's not posting anything to my database, I have no idea where to start looking... oh looking through this forum I guess queries have to have tilde `
I'm used to not putting anything around my query. Do you know if it's better to have ` instead of nothing?
I always use backticks ( ` ) around table and column names. It adds to the readability of the code. I'm not sure if it makes any other difference though.