PHP Code:
<?php
$action = $_REQUEST['action'];
echo "<h2>Edit Listing</h2>\n";
if ($action == 'delete')
{
$id = $_REQUEST['id'];
$query = "DELETE FROM listings WHERE id = $id";
$result = mysql_query($query) or die(mysql_error());
if ($result)
{
echo "You have successfully deleted that listing.<br>\n";
echo "<a href=\"index.php?content=listings\">Return to Listings</a>\n";
exit;
} else
{
echo "Sorry, there was a problem deleting that listing.<br>\n";
echo "<a href=\"index.php?content=listings\">Return to Listings</a>\n";
exit;
}
exit;
}
else if($action == 'add')
{
$name = $_POST['name'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$type = $_POST['type'];
if (get_magic_quotes_gpc())
{
$name = stripslashes($name);
$phone = stripslashes($phone);
$address = stripslashes($address);
$type = stripslashes($type);
}
$name = mysql_real_escape_string($name);
$phone = mysql_real_escape_string($phone);
$address = mysql_real_escape_string($address);
$type = mysql_real_escape_string($type);
if (isset($_POST['featured']))
$featured = 1;
else
$featured = 0;
if (isset($_POST['active']))
$display = 1;
else
$display = 0;
$areaid = $_POST['area'];
$areaquery = "SELECT city, state, zip FROM area WHERE id=$areaid";
$arearesult = mysql_query($areaquery) or die(mysql_error());
$arearow = mysql_fetch_array($arearesult, MYSQL_ASSOC);
$areacity = $arearow['city'];
$areastate = $arearow['state'];
$areazip = $arearow['zip'];
$city = $areacity . ", " . $areastate . " " . $areazip;
$zip = $areazip . " (" . $areacity . ", " . $areastate . ")";
$nearids = $_POST['nareas'];
$nearquery = implode("' OR id = '", $nearids);
$areaquery = "SELECT id, city, state, zip FROM area WHERE id='$nearquery'";
$arearesult = mysql_query($areaquery) or die(mysql_error());
$i = 0;
while($arearow = mysql_fetch_array($arearesult, MYSQL_ASSOC)){
$areacity = $arearow['city'];
$areastate = $arearow['state'];
$areazip = $arearow['zip'];
$nearcityarray[$i] = $areacity . ", " . $areastate . " " . $areazip;
$nearziparray[$i] = $areazip . " (" . $areacity . ", " . $areastate . ")";
$i++;
}
$nearcity = implode(";", $nearcityarray);
$nearzip = implode(";", $nearziparray);
$nearidimplode = implode(";", $nearids);
$query = "INSERT INTO listings (name, phone, address, type, featured, display, areaid, nearids, city, nearcity, zip, nearzip) VALUES ('$name', '$phone', '$address', '$type', '$featured', '$display', '$areaid', '$nearidimplode' ,'$city', '$nearcity', '$zip', '$nearzip')";
$result = mysql_query($query) or die(mysql_error());
if ($result)
{
echo "You have successfully added '" . stripslashes($name) . ".'<br>\n";
echo "<a href=\"index.php?content=listings\">Return to Listings</a>\n";
exit;
} else
{
echo "Sorry, there was a problem adding '" . stripslashes($name) . ".'<br>\n";
echo "<a href=\"index.php?content=listings\">Return to Listings</a>\n";
exit;
}
exit;
}
else if($action == 'update')
{
$id = $_REQUEST['id'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$type = $_POST['type'];
if (get_magic_quotes_gpc())
{
$name = stripslashes($name);
$phone = stripslashes($phone);
$address = stripslashes($address);
$type = stripslashes($type);
}
$name = mysql_real_escape_string($name);
$phone = mysql_real_escape_string($phone);
$address = mysql_real_escape_string($address);
$type = mysql_real_escape_string($type);
if (isset($_POST['featured']))
$featured = 1;
else
$featured = 0;
if (isset($_POST['active']))
$display = 1;
else
$display = 0;
$areaid = $_POST['area'];
$areaquery = "SELECT city, state, zip FROM area WHERE id=$areaid";
$arearesult = mysql_query($areaquery) or die(mysql_error());
$arearow = mysql_fetch_array($arearesult, MYSQL_ASSOC);
$areacity = $arearow['city'];
$areastate = $arearow['state'];
$areazip = $arearow['zip'];
$city = $areacity . ", " . $areastate . " " . $areazip;
$zip = $areazip . " (" . $areacity . ", " . $areastate . ")";
$nearids = $_POST['nareas'];
$nearquery = implode("' OR id = '", $nearids);
$areaquery = "SELECT id, city, state, zip FROM area WHERE id='$nearquery'";
$arearesult = mysql_query($areaquery) or die(mysql_error());
$i = 0;
while($arearow = mysql_fetch_array($arearesult, MYSQL_ASSOC)){
$areacity = $arearow['city'];
$areastate = $arearow['state'];
$areazip = $arearow['zip'];
$nearcityarray[$i] = $areacity . ", " . $areastate . " " . $areazip;
$nearziparray[$i] = $areazip . " (" . $areacity . ", " . $areastate . ")";
$i++;
}
$nearcity = implode(";", $nearcityarray);
$nearzip = implode(";", $nearziparray);
$nearidimplode = implode(";", $nearids);
$query = "UPDATE listings SET name='$name', phone='$phone', address='$address', type='$type', featured='$featured', display='$display', areaid='$areaid', nearids='$nearidimplode', city='$city', nearcity='$nearcity', zip='$zip', nearzip='$nearzip' WHERE id = $id";
$result = mysql_query($query) or die(mysql_error());
if ($result)
{
echo "You have successfully updated '" . stripslashes($name) . ".'<br>\n";
echo "<a href=\"index.php?content=listings\">Return to Listings</a>\n";
exit;
} else
{
echo "Sorry, there was a problem updating '" . stripslashes($name) . ".'<br>\n";
echo "<a href=\"index.php?content=listings\">Return to Listings</a>\n";
exit;
}
exit;
}
?>
thanks in advance!
Bookmarks