
Originally Posted by
chris.upjohn
The only thing i can see wrong is that all your array index names are missing the colon at the beginning.
Eg. 'email' should be ':email'
Even After Adding the colons the data is not inserted.
Here's the full script (minus the salt)
PHP Code:
<?php
require_once('../../lib/connect.php');
if(strlen(trim($_POST['email'] == 0)))
{
$emptyEmail = TRUE;
}
if(strlen(trim($_POST['nameFirst'] == 0)))
{
$emptyNameFirst = TRUE;
}
if(strlen(trim($_POST['nameLast'] == 0)))
{
$emtpyNameLast = TRUE;
}
if(strlen(trim($_POST['farmName'] == 0)))
{
$emptyFarmName = TRUE;
}
$email = strip_tags(trim($_POST['email']));
$nameFirst = htmlspecialchars(strip_tags(stripslashes($_POST['nameFirst'])));
$nameLast = htmlspecialchars(strip_tags(stripslashes($_POST['nameLast'])));
$farmName = htmlspecialchars(stripslashes(strip_tags($_POST['farmName'])));
$group = '2';
$date = date("d/m/y");
$passWdRaw = strtolower(stripslashes(htmlspecialchars(trim($_POST['password']))));
$passwd = hash('sha512',$passWdchar);
$salt['0'] = '';
$salt['1'] = '';
$password = $salt['1']."".$passwd."".$salt['0'];
try
{
$queryCheck = 'SELECT * FROM users WHERE email=:email';
$s = $dbconnect->prepare($queryCheck);
$s->bindValue(':email', $email);
$emailAllreadyInUse = $s->rowCount();
$s->execute();
}
catch(PDOException $e)
{
$error = 'Error adding your account: ' . $e->getMessage();
exit();
}
if ($emailAllreadyInUse > 0)
{
echo 'That email is allready in use. Please Use a different email';
}
else {
try
{
$query = 'INSERT INTO users (
`email`,
`password`,
`nameFirst`,
`nameLast`,
`farmName`,
`joinDate`,
`groupNum`
) VALUES (
:email,
:password,
:nameFirst,
:nameLast,
:farmName,
:date,
:groupNum
)';
$s = $dbconnect->prepare($sql);
// Bind the Values
$values = array(':email' => $email, ':password' => $password, ':nameFirst' => $nameFirst, ':nameLast' => $nameLast, ':farmName' => $farmName, ':date' => $date, ':groupNum' => $groupNum);
$s->execute($values);
}
catch(PDOException $e)
{
echo '<p class=\"DB_Error\">There was an error adding your account please try again latter</p>';
}
echo '<p class=\"username\">You can now log in with the email '.$email.' and your chosen password';
}
?>
Bookmarks