Can anyone help me with an if statement?
My script looks like this.

$results= mysql_query("SELECT * FROM customers WHERE username='$user'and password='$pass'",$db);


if ($myrow = mysql_fetch_array($results)) {

do { I WANT THIS TO GO TO "details.php"}

while ($myrow = mysql_fetch_array($results));

} else {

echo "Sorry, Incorrect Username or Password!";

}

I'm not sure if this is possible. Any help would be greatly appreciated!

Thanks

I don't think that can work the way you want it to. Instead of trying to execute details.php in your script, include it and call functions from it. Now your code would probably better formed like this:

$result = mysql_query("SELECT * FROM customers WHERE username='$user'and password='$pass'",$db);

$myrow = mysql_fetch_array($results));

if($myrow)
{
  foreach($myrow as $key => $row)
  {
    do something with $row or do something with $myrow[$key]
  }
}
else
{
   echo "Sorry, Incorrect Username or Password!";
}

Hope this helps,
Dance

I modified the sql query to only pull the data you are usign, since there's no sense adding the extra overhead to the database if you only need 2 columns. I've also found it a bad idea to use SELECT * instead of just calling the items columns individually.

The one restriction on this script is that no text/html can be sent to the user's computer before encountering the header tag

$result= mysql_query("SELECT username,password FROM customers WHERE username='$user'and password='$pass'",$db);
if ($result == 0)
{
     echo "<font color=\"red\">There was an error accessing the database!</font>";
     exit();
}

$result = mysql_fetch_row($result);

if ($result[0] == $user && $result[1] == $pass)
{
    header("Location: details.php");
}
else
{
     echo "Sorry, Incorrect Username or Password!";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.