Click to See Complete Forum and Search --> : How to echo error if there is wrong URL?Need help
toplisek
12-02-2006, 04:24 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>";
}
}
coppocks
12-02-2006, 04:33 AM
You could always do this:
$num_rows = mysql_num_rows($result1); // tells how many rows match the query, if any
if ($num_rows > 0) {
// do your processing
}
else {
// do your error reporting since no matches exist
}
toplisek
12-02-2006, 04:45 AM
$reactivationnum=$_GET['number'];
$query = "SELECT * FROM membership WHERE reactivationnum = '$reactivationnum'";
$result1 = mysql_query($query);
while ($row = mysql_fetch_array($result1))
{
$num_rows = mysql_num_rows($result1); // tells how many rows match the query, if any
if ($num_rows > 0)
{
// do your processing}
else {
// do your error reporting since no matches exist
echo "<script language='javascript'>
document.location='errorin URL.php';</script>";
}
}
Is this correct that it is in while code?I'm new to this...
If I put URL for page that is secured like account.php , it will show error in URL but if I have page like: account.php?number=26 it will not detect error and show error in URL.php. Do you know why? Even there is 26 which is wrong number it will show secured account.php. If user puts wrong number it should transfer him to errorin URL.php
coppocks
12-02-2006, 04:54 AM
$query = "SELECT * FROM membership WHERE reactivationnum = '$reactivationnum'";
$result1 = mysql_query($query);
$num_rows = mysql_num_rows($result1);
if ($num_rows > 0) {
while ($row = mysql_fetch_array($result1)) {
// do your processing
}
}
else {
// do your error reporting since no matches exist
// echo "<script language='javascript'>document.location='errorin URL.php';</script>";
header("Location: http://www.example.com/errorinURL.php"); /* Redirect browser via PHP */
}
that should work.
toplisek
12-02-2006, 05:02 AM
great, it works. Thank you