Forum Moderators: coopster
if($rows_returned >= strip_tags($_GET['id']))
{
echo "OOps out of range";
}
$sql = "SELECT * FROM `your_table` WHERE `ID` = '".strip_tags($_GET['id'])."'";
$content = mysql_query($sql, $your_conn_detail) or die(mysql_error());
$detail_there = mysql_num_rows($content) or die(mysql_error());
if($detail_there > 0)
{
echo "id exists";
}else{
echo "There is no matching ID in the database";
exit;
}
If you are pulling the data from the database, count the rows returned from query, and then use that as a reference to see if the id requested is valid (ie: out of range)
<?php
include("connect.php");
$id = $_POST['id'];
$password = $_POST['password'];
$qProfile = "SELECT * FROM listings WHERE id='$id' AND password='$password'";
$rsProfile = mysql_query($qProfile);
$row = mysql_fetch_array($rsProfile);
extract($row);
$d = stripslashes($d);
$cat = stripslashes($cat);
$subcat = stripslashes($subcat);
$title = stripslashes($title);
$price = stripslashes($price);
$description = stripslashes($description);
$area = stripslashes($area);
$img1 = stripslashes($img1);
$img2 = stripslashes($img2);
$img3 = stripslashes($img3);
$password = stripslashes($password);
$firstname = stripslashes($firstname);
$lastname = stripslashes($lastname);
$email = stripslashes($email);
$phone = stripslashes($phone);
$timestamp = stripslashes($timestamp);
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Edit An Advert</title>
</head>
<body>
<h1>Edit An Advert</h1>
<?php if ([size=3][b]something to go here[/b][/size]) {
echo "<p><a href=\"login.php\">Login</a> to edit your advert.</p>";
} else {
echo "
<form id=\"FormName\" action=\"edited.php\" method=\"post\" name=\"FormName\">
<fieldset>
<legend>Cat</legend>
<div align=\"left\"><label for=\"cat\">cat</label></div>
<input id=\"cat\" name=\"cat\" type=\"text\" size=\"25\" value=\"$cat\" maxlength=\"255\">
<div align=\"left\"><label for=\"subcat\">subcat</label></div>
<input id=\"subcat\" name=\"subcat\" type=\"text\" size=\"25\" value=\"$subcat\" maxlength=\"255\">
</fieldset>
<fieldset>
<legend>Ad Details</legend>
<div align=\"left\"><label for=\"title\">title</label></div>
<input id=\"title\" name=\"title\" type=\"text\" size=\"25\" value=\"$title\" maxlength=\"255\">
<div align=\"left\"><label for=\"price\">price</label></div>
<input id=\"price\" name=\"price\" type=\"text\" size=\"25\" value=\"$price\" maxlength=\"255\">
<div align=\"left\"><label for=\"description\">description</label></div>
<textarea id=\"description\" name=\"description\" rows=\"10\" cols=\"70\">$description</textarea>
<div align=\"left\"><label for=\"area\">area</label></div>
<input id=\"area\" name=\"area\" type=\"text\" size=\"25\" value=\"$area\" maxlength=\"255\">
<div align=\"left\"><label for=\"img1\">img1</label></div>
<input id=\"img1\" name=\"img1\" type=\"text\" size=\"25\" value=\"$img1\" maxlength=\"255\">
<div align=\"left\"><label for=\"img2\">img2</label></div>
<input id=\"img2\" name=\"img2\" type=\"text\" size=\"25\" value=\"$img2\" maxlength=\"255\">
<div align=\"left\"><label for=\"img3\">img3</label></div>
<input id=\"img3\" name=\"img3\" type=\"text\" size=\"25\" value=\"$img3\" maxlength=\"255\">
<div align=\"left\"><label for=\"password\">password</label></div>
<input id=\"password\" name=\"password\" type=\"text\" size=\"25\" value=\"$password\" maxlength=\"255\">
</fieldset>
<fieldset>
<legend>Personal Details</legend>
<div align=\"left\"><label for=\"firstname\">Name</label></div>
<input id=\"firstname\" name=\"firstname\" type=\"text\" size=\"25\" value=\"$firstname\" maxlength=\"255\"> <input id=\"lastname\" name=\"lastname\" type=\"text\" size=\"25\" value=\"$lastname\" maxlength=\"255\">
<div align=\"left\"><label for=\"email\">email</label></div>
<input id=\"email\" name=\"email\" type=\"text\" size=\"25\" value=\"$email\" maxlength=\"255\">
<div align=\"left\"><label for=\"phone\">phone</label></div>
<input id=\"phone\" name=\"phone\" type=\"text\" size=\"25\" value=\"$phone\" maxlength=\"255\">
</fieldset>
<fieldset>
<legend>Update Your Ad</legend>
<input type=\"submit\" name=\"submitButtonName\" value=\"Update Advert\">
<p>Or <a href=\"deleted.php?id=$id\"> delete your ad.</a></p>
</fieldset>
<input type=\"hidden\" name=\"id\" value=\"$id\">
<input id=\"d\" name=\"d\" type=\"hidden\" value=\"$d\">
<input id=\"timestamp\" name=\"timestamp\" type=\"hidden\" value=\"$timestamp\">
</form>
";
} ?>
</body>
</html>
$id = $_GET['id'];
if(isset($id) && $id != "") {
$sql = 'SELECT etc...'; // Make sure you include quotations: id="' . $id . '"
$result = mysql_query($sql);
if(mysql_fetch_array($result)) {
// Page for a correct ID
} else {
header('HTTP/1.1 404 Not Found');
// Page for a incorrect ID
}
} else {
// Page for when no ID has been set
} [edited by: Readie at 5:15 pm (utc) on Feb 25, 2010]
<?php
include("connect.php");
$id = $_POST['id'];
$password = $_POST['password'];
if (isset($id) && $id != "") {
$sql = "SELECT * FROM listings WHERE id='$id' AND password='$password'";
$result = mysql_query($sql);
$row = mysql_fetch_array($rsProfile);
extract($row);
$id = stripslashes($id);
$password = stripslashes($password);
$d = stripslashes($d);
$cat = stripslashes($cat);
$subcat = stripslashes($subcat);
$title = stripslashes($title);
$price = stripslashes($price);
$description = stripslashes($description);
$area = stripslashes($area);
$img1 = stripslashes($img1);
$img2 = stripslashes($img2);
$img3 = stripslashes($img3);
$password = stripslashes($password);
$firstname = stripslashes($firstname);
$lastname = stripslashes($lastname);
$email = stripslashes($email);
$phone = stripslashes($phone);
$timestamp = stripslashes($timestamp);
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Edit An Advert</title>
</head>
<body>
<h1>Edit An Advert</h1>
<?php
if (mysql_fetch_array($result)) {
echo "
<form id=\"FormName\" action=\"edited.php\" method=\"post\" name=\"FormName\">
<fieldset>
<legend>Cat</legend>
<div align=\"left\"><label for=\"cat\">cat</label></div>
<input id=\"cat\" name=\"cat\" type=\"text\" size=\"25\" value=\"$cat\" maxlength=\"255\">
<div align=\"left\"><label for=\"subcat\">subcat</label></div>
<input id=\"subcat\" name=\"subcat\" type=\"text\" size=\"25\" value=\"$subcat\" maxlength=\"255\">
</fieldset>
<fieldset>
<legend>Ad Details</legend>
<div align=\"left\"><label for=\"title\">title</label></div>
<input id=\"title\" name=\"title\" type=\"text\" size=\"25\" value=\"$title\" maxlength=\"255\">
<div align=\"left\"><label for=\"price\">price</label></div>
<input id=\"price\" name=\"price\" type=\"text\" size=\"25\" value=\"$price\" maxlength=\"255\">
<div align=\"left\"><label for=\"description\">description</label></div>
<textarea id=\"description\" name=\"description\" rows=\"10\" cols=\"70\">$description</textarea>
<div align=\"left\"><label for=\"area\">area</label></div>
<input id=\"area\" name=\"area\" type=\"text\" size=\"25\" value=\"$area\" maxlength=\"255\">
<div align=\"left\"><label for=\"img1\">img1</label></div>
<input id=\"img1\" name=\"img1\" type=\"text\" size=\"25\" value=\"$img1\" maxlength=\"255\">
<div align=\"left\"><label for=\"img2\">img2</label></div>
<input id=\"img2\" name=\"img2\" type=\"text\" size=\"25\" value=\"$img2\" maxlength=\"255\">
<div align=\"left\"><label for=\"img3\">img3</label></div>
<input id=\"img3\" name=\"img3\" type=\"text\" size=\"25\" value=\"$img3\" maxlength=\"255\">
<div align=\"left\"><label for=\"password\">password</label></div>
<input id=\"password\" name=\"password\" type=\"text\" size=\"25\" value=\"$password\" maxlength=\"255\">
</fieldset>
<fieldset>
<legend>Personal Details</legend>
<div align=\"left\"><label for=\"firstname\">Name</label></div>
<input id=\"firstname\" name=\"firstname\" type=\"text\" size=\"25\" value=\"$firstname\" maxlength=\"255\"> <input id=\"lastname\" name=\"lastname\" type=\"text\" size=\"25\" value=\"$lastname\" maxlength=\"255\">
<div align=\"left\"><label for=\"email\">email</label></div>
<input id=\"email\" name=\"email\" type=\"text\" size=\"25\" value=\"$email\" maxlength=\"255\">
<div align=\"left\"><label for=\"phone\">phone</label></div>
<input id=\"phone\" name=\"phone\" type=\"text\" size=\"25\" value=\"$phone\" maxlength=\"255\">
</fieldset>
<fieldset>
<legend>Update Your Ad</legend>
<input type=\"submit\" name=\"submitButtonName\" value=\"Update Advert\">
</fieldset>
<input type=\"hidden\" name=\"id\" value=\"$id\">
<input id=\"d\" name=\"d\" type=\"hidden\" value=\"$d\">
<input id=\"timestamp\" name=\"timestamp\" type=\"hidden\" value=\"$timestamp\">
</form>
";
}
else {
echo "Not found!";
}
} else {
echo "No ID";
}
?>
</body>
</html>
$sql = "SELECT * FROM listings WHERE id='".$id."' AND password='".$password."'";
$result = mysql_query($sql)or die(mysql_error());
<?php
if(whatever)
{//opening tag
$yourvar = "Cool!";
?>
<html>
<body>
<p>Whatever you like!<?php echo $yourvar; ?></p>
<?php
}//closing tag