Log in

View Full Version : How to echo error if there is wrong URL? Need help



toplisek
12-02-2006, 10:28 AM
I have code and it reads from URL number ID. How to report error message if $_GET['number'] is not the same as in db? :)



reactivationnum=$_GET['number'];


$query = "SELECT * FROM membership WHERE reactivationnum = '$reactivationnum'";
$result1 = mysql_query($query);

while ($row = mysql_fetch_array($result1))
{ $reactivation = $row["reactivation"];
if ($reactivation==1 )

{
echo "<script language='javascript'>
document.location='activated.php';</script>"; }

else
{
echo "<script language='javascript'>
document.location='notactivated.php';</script>";
}
}

thetestingsite
12-02-2006, 04:31 PM
If you're trying to do what I think you're doing, try the following:



<?php

$reactivationnum=$_GET['number'];


$query = "SELECT * FROM membership WHERE reactivationnum = '$reactivationnum'";
$result1 = mysql_query($query);

if (!mysql_num_rows($result1)) {

echo "<script language='javascript'>
document.location='notactivated.php';</script>";
}

else {

echo "<script language='javascript'>
document.location='activated.php';</script>";
}

?>


That will check the database for any matching rows for $reactivationnum. If it does not have any matching rows, it redirects to notactivated.php. If it does have a matching row, it redirects to activated.php. Let me know if this is what you're talking about.