guymrodgers
-
Posts
2 -
Joined
-
Last visited
Never
Posts posted by guymrodgers
-
-
I'm sure that my problem is caused by a really stupid typo, but I can't find it. I'm trying to grab a column from a database, and then go through it as an array in order to find a username. However, my foreach loop only checks the first username in the column, and then stops. I searched the web for a similar problem, and then I scoured the forums, and it appears that no one else has this problem, which is why I'm betting that it's a typo, but still, it's stumping me...
PLEASE HELP!!!
[code]
<?php
$name = $_POST["compid"];
$pass = $_POST["pass"];
$con = mysql_connect("localhost","root","quantico");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("argo", $con);
$results = mysql_fetch_array(mysql_query("SELECT user FROM customers",$con));
$correctUser = 0;
foreach ($results as $value)
{
if ($name == $value)
{
$correctUser = 1;
}
}
if ($correctUser == 0)
{
$theEnd = <<<END
<script language='Javascript' type='text/javascript'>
alert("We do not have that username on file.");
</script>
END;
die($theEnd);
}
[/code]
There's more code, but I didn't think it was part of the problem. If this part of the code isn't the problem, I'll post the rest.
Thanks in advance,
Guy
Foreach Loop problem...
in PHP Coding Help
Posted
[code]
mysql_select_db("argo", $con);
$query=mysql_query("SELECT user FROM customers WHERE user = '$name'",$con);
$correctUser = 0;
$user = mysql_fetch_array($query);
if ($user !== '')
{
$correctUser = 1;
}
if ($correctUser == 0)
{
$theEnd = <<<END
<script language='Javascript' type='text/javascript'>
alert("We do not have that username on file.");
</script>
END;
die($theEnd);
}
if($pass != mysql_query("SELECT password FROM 'customers' WHERE user=$name"))
{
$theEnd = <<<END
<script language='Javascript' type='text/javascript'>
alert("The password you entered does not match the username you provided.");
</script>
END;
die($theEnd);
}
[/code]
But it didn't work, so I tried a longer route:
[code]
$resultant = mysql_query("SELECT password FROM customers WHERE user=$name",$con);
$correctPass = 0;
foreach(mysql_fetch_array($resultant) as $val)
{
if ($pass == $val)
{
$correctPass = 1;
}
}
if ($correctPass == 0)
{
$theEnd = <<<END
<script language='Javascript' type='text/javascript'>
alert("The password you entered does not match the username you provided.");
</script>
END;
die($theEnd);
}
if (mysql_query("SELECT id FROM customers WHERE password=$pass") != mysql_query("SELECT id FROM customers WHERE user=$name"))
{
$theEnd = <<<END
<script language='Javascript' type='text/javascript'>
alert("The password you entered does not match the username you provided.");
</script>
END;
die($theEnd);
}
[/code]
But it will only accept the first password in the list, no matter what the username is.
Help!!!
--Guy