Forum Moderators: coopster
mysql_query("SELECT memberName , passwd FROM smf_members WHERE memberName=$realuser AND passwd=$realpass");
if (!$result) {
echo "7";
}
if ($result) {
echo "1";
}
There is my attempt and it doesn't quite work. Im just learning PHP by the way. So really I'm just wondering how to use variables in a MySQL query. The variables $realuser and $realpass are strings by the way.
$result = mysql_query("SELECT memberName, passwd FROM smf_members WHERE memberName='" . [url=http://www.php.net/mysql-real-escaep-string]mysql_real_escape_string[/url]($realuser)."' AND passwd='" . mysql_real_escape_string($realpass) . "'");
Make sure to take a look at that because it's very important to the security of your database.
while ($row = mysql_fetch_assoc($result))
{
if ($row['memberName']==$user & $row['passwd']==$hashed)
{
echo "1";
}
else
{
echo "7";
}
}
mysql_close($con);
This is the end of my code. It works and displays a "1" if you enter correct information, however it doesn't display a "7" if you enter incorrect information.
if ($row['memberName']==$user & $row['passwd']==$hashed)
Should be written like the following:
if ($row['memberName']==$user [b]&&[/b] $row['passwd']==$hashed)
Notice how I added the additional ampersand sign.
error_reporting(E_ALL);
Make sure to let us know what errors this is giving you.
<?php
$con = mysql_connect("localhost","removed","removed");
if (!$con)
{
echo "8";
}$hashed = sha1(strtolower($user) . $password);
mysql_select_db("dinsdale_forum", $con);
error_reporting(E_ALL);
$result = mysql_query("SELECT memberName , passwd FROM smf_members WHERE memberName='" . mysql_real_escape_string($user)."' AND passwd='" . mysql_real_escape_string($hashed)."'");
while ($row = mysql_fetch_assoc($result))
{
if ($row['memberName']==$user && $row['passwd']==$hashed)
{
echo "1";
}
else
{
echo "7";
}
}
mysql_close($con);
?>
You might also want to consider checking for mysql errors:
$result = mysql_query("SELECT memberName , passwd FROM smf_members WHERE memberName='" . mysql_real_escape_string($user)."' AND passwd='" . mysql_real_escape_string($hashed)."'") or die(mysql_error());
if(!$result) {
echo 7;
}