Hiya,
I know its so frustrating because it looks right to me.
What I’ve done is taken out the encryption of both forms and everything works perfectly.
I’ll post the working scripts here. If you have a spare few minutes would you mind seeing if you can put encryption back into them how you normally would to make sure its not me doing some daft by mistake. I don’t mind how its done.
no worries if your too busy. Thank you for looking anyway.
Registration form:
[php]<?php
// Connection to database
$con = mysql_connect(“databse”,“user”,“pass!”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
mysql_select_db(“database”) or die(mysql_error());
//This makes sure they did not leave any fields blank
if (!$_POST[‘screen_name’] | !$_POST[‘pass’] | !$_POST[‘pass2’] | !$_POST[‘terms’]) {
die('You did not complete all of the required fields');
}
// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['screen_name'] = addslashes($_POST['screen_name']);
}
$usercheck = $_POST[‘screen_name’] or $_POST[‘screen_name’];
$check = mysql_query(“SELECT screen_name FROM login WHERE screen_name = ‘$usercheck’ or screen_name=’$_POST[screen_name]donkey’”)
or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$_POST['screen_name'].' is already in use.');
}
//this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. ');
}
session_start();
//Encrypt the posted code field and then compare with the stored key
if(md5($_POST[‘captcha_input’]) != $_SESSION[‘key’])
{
die(“Error: You must enter the code correctly”);
}
// now we insert it into the database
$sql=“INSERT INTO login (title, forename, surname, email, screen_name, pass, join_date, last_login, time)
VALUES
(’$_POST[title]’,’$_POST[forename]’,’$_POST[surname]’,’$_POST[email]’,’$_POST[screen_name]donkey’,’$_POST[pass]’,CURDATE(), CURDATE(), CURTIME())”;
if (!mysql_query($sql,$con))
{
die('Error: ’ . mysql_error());
}
echo “Thank You for registering a screen name. You can now post freely :)”;
mysql_close($con);
?>[/php]
Submit:
[php]<?php
//This makes sure they did not leave any fields blank
if (!$_POST[‘story’] || !$_POST[‘screen_name’] ) {
die('You did not complete all of the required fields');
}
// Connection to database
$con = mysql_connect(“database”,“user”,“pass”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
mysql_select_db(“database”) or die(mysql_error());
// Limit the result to only one row, because there should only be one user with that screen_name:
$result = mysql_query(“SELECT * FROM login WHERE screen_name=’$_POST[screen_name]donkey’ LIMIT 0,1”);
// Check to see if it actually got something, if so, continue on:
if(mysql_num_rows($result) != 0) {
// Fetch the row and drop it into an array:
$row = mysql_fetch_array($result);
// Assuming that the password is entered in the database already, and is encrypted using sha1() :
if (($_POST[‘pass’]) == $row[‘pass’]) {
// Password is correct
$sql=“INSERT INTO banter (story, screen_name)
VALUES
(’$_POST[story]’,’$_POST[screen_name]donkey’)”;
if (!mysql_query($sql,$con))
{
die('Error: ’ . mysql_error());
}
echo “Thank You for posting”;
mysql_close($con);
}
else {
// Password is incorrect
echo “Your password does not match our records”;
}
}
else {
echo “Your username does not exist”;
}
?>[/php]
Many Thanks,
Sam