Page 1 of 1
will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 3:33 am
by NikBruce
i'm having trouble with my login system.
users create an account like so:
Code: Select all
$ti = "INSERT INTO accTable (name, nameU, profession, company, site, email, word, country)
VALUES ('$accNameSafe', '$accNameUSafe', '$accProfessionSafe', '$accCompanySafe', '$accSiteSafe', '$accEmailSafe', '$accPassSafe', '$accCountrySafe')";
mysql_query($ti, $con);
everything inserts fine. but when i try to login like this,
Code: Select all
$sql = "SELECT `email`, `word` FROM `accTable` WHERE `email` = `$email` AND `word` = `$password`";
$result = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($result);
if($count == 1)
{ blah blah blah
i get a
Unknown column '*my email address*' in 'where clause'
What's going on?
thanks
Re: will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 4:11 am
by aravona
where are you getting the $email and $password from? your form?
is that the full error ? (except the changed password)
Re: will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 4:15 am
by NikBruce
that is the full error, and the variables are posted from a form.
Re: will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 4:44 am
by aravona
Having looked at old code of mine doing similar things, I don't have any quotes around my field attributes
Code: Select all
$sql = "SELECT email, word FROM accTable WHERE email = `$email` AND word = `$password`";
Always try the simplist thing first in my opinion, does taking them out effect your code at all?
(Having done php at uni I spent ages trying to find what my errors were and often it wasnt as complicated as I made out!)
But best to eliminate the obvious

Re: will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 4:59 am
by NikBruce
that's a fair statement.
but no, the error stays the same.
Re: will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 5:23 am
by aravona
Ok having a look on the net for similar issues and it seems that when ur selecting your email its taking your actual email address as the column name (as we know) instead of 'email'
So having looked more I found that having the variable in single quotes should fix it, alas not so even tho this seems to work for other people.
Can you show your form ?
Re: will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 5:37 am
by NikBruce
Code: Select all
<form name="form1" method="post" action="accLogin.php">
<div align="right">email address:
<input type="text" name="email" id="email">
personal password:
<input type="password" name="password" id="password">
<input type="image" src="img/loginBtn.png" name="button" id="button" value="Submit" />
</div>
</form>
Re: will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 5:40 am
by aravona
have you tried having ur $email as $_POST[email] and $password as $_POST[password] ?
I've done it in the past

Re: will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 5:48 am
by NikBruce
nothing, it assumes the variables to be 'email' and 'password' anyway.
Re: will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 6:01 am
by aravona
not sure then since most people with this problem used the quotes fix. will need some imput from someone with more experience methinks.
but i would have thought
Code: Select all
$sql = "SELECT email, word FROM accTable WHERE email = $_POST[email] AND word = $_POST[password]";
would have worked

Re: will insert to table, but can't select (login system)
Posted: Thu Jan 07, 2010 6:17 am
by NikBruce
when i use single quotes instead of back ticks as shown below,
Code: Select all
$sql = "SELECT `email`, `word` FROM `accTable` WHERE `email` = '$email' AND `word` = '$password'";
$result = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($result);
if($count == 1)
{
while($row = mysql_fetch_array($result))
{
$accEmailSSafe = $row['email'];
$accPassSSafe = $row['word'];
$_SESSION["accEmailSafe"] = $accEmailSSafe;
$_SESSION["accPassSafe"] = $accPassSSafe;
}
header("Location: accountPage.php");
}// from if count == 1
else { echo "Your email and password combination are incorrect.<br /><input type='image' src='img/backBtn.png' name='button' id='button' value='Submit' onClick='history.go(-1);'/>"; echo $count; }
no mysql errors show up, but count = 0. but it really should be 1!
The email address and password i'm entering really are correct, i checked on the database.
Re: will insert to table, but can't select (login system)
Posted: Fri Jan 08, 2010 1:30 pm
by NikBruce
just to clarify my last post, when i said as shown below i was referring to the variables after the "WHERE" clause in line 1.
Re: will insert to table, but can't select (login system)
Posted: Fri Jan 08, 2010 2:07 pm
by NikBruce
found the problem. the word field was a Varchar with a length of 17....
that's not really long enough for a password that's been md5'd.
my bad
Thanks for all you help
Re: will insert to table, but can't select (login system)
Posted: Mon Jan 11, 2010 3:19 am
by aravona
No problem

thanks for posting your solution
