I have a following table structure (for some reasons i cannot change the table structure so plz suggest me a solution which can be easily done by this table structure)
#
Table structure for table cities
#
CREATE TABLE cities (
CityName varchar(50) NOT NULL default '',
CityChamberofCommerce varchar(100) default NULL,
CityPicture varchar(50) default NULL,
UNIQUE KEY CityName (CityName)
) TYPE=MyISAM;
now i want to use update records query in it, but i am a bit confused on how to use where clause as when i use CityName field it gives me an error "Uknown column 'test'"(city name)
i am pasting my code so that u can better understand
<?php
include("../includes/ez_sql.php");
include("../includes/mailto.php");
if(isset($_POST['submit']))
{
//create a function for escaping the data
function escape_data ($data)
{
global $dbc;
if(ini_get('magic_quotes_gpc'))
{
$data = stripslashes($data);
}
return mysql_real_escape_string($data,$dbc);
}
$CityName = $POST['city'];
$CityChamber = escape_data($POST['CityChamber']);
$CityPicture = escape_data($_POST['CityPicture']);
$db->query("UPDATE cities SET CityName = '$CityName', CityChamberofCommerce = '$CityChamber', CityPicture = '$CityPicture' WHERE CityName = '{$_GET["city"]}' ");
}
$city_name = $_GET['city'];
$city = $db->get_row("SELECT * FROM cities WHERE CityName = '$city_name'");
?>
<html><!-- InstanceBegin template="/Templates/admin.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<link type="text/css" rel="stylesheet" href="../styles/admin.css">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="db_images/logo.gif" width="255" height="72" border="0" usemap="#Map"></td>
</tr>
<tr>
<td bgcolor="black">
<div align="center" id="navcontainer">
<ul id="navlist">
<li><a href="StanHomeList.php" title="">Cities</a></li>
<li><a href="SubdivisionList.php" title="">Subdivisions</a></li>
<li><a href="LotList.php" title="">Lots</a></li>
<li><a href="StanHomeList.php" title="">Semi-Custom Homes</a></li>
<li><a href="FloorplanList.php" title="">Floorplans & Elevations</a></li>
<li><a href="VisitorList.php" title="">Visitors</a></li>
<li><a href="#" title="">Web Statistics</a></li>
</ul>
</div>
</td>
</tr>
</table>
<div align="center" style="margin-top:20px; max-width: 750px">
<!-- InstanceBeginEditable name="AdminContent" -->
<form action="CityEdit.php?city=<?PHP echo $GET['city'];?>" method="post">
<p align="center"><strong>Edit this city:</strong></p>
<p align="center">
<img src="/db_images/"></p>
<table align="center">
<tr valign="top">
<td align="right" nowrap>City Name:</td>
<td> <input name="CityName" type="text" id="CityName" value="<?php echo $city->CityName;?>" size="50" maxlength="45"></td>
</tr>
<tr valign="top">
<td align="right" nowrap><a href="" target="blank">Chamber
of Commerce</a>:</td>
<td><input name="CityChamber" type="text" id="CityChamber" value="<?php echo $city->CityChamberofCommerce;?>" size="50" maxlength="45">
<br />
Be sure to include the ENTIRE web address...including http://www. or leave
blank for none</td>
</tr>
<tr valign="top">
<td height="45" align="right" nowrap>City Picture Filename:</td>
<td><input name="CityPicture" type="text" id="CityPicture" value="<?php echo $city->CityPicture;?>" size="50" maxlength="45">
<br /> <a href="Upload.asp">Upload... </a>leave blank for none</td>
</tr>
<tr valign="top">
<td colspan="2" align="right" nowrap>
<div align="center">
<input type="hidden" name="city_name" value ="<?php echo $city_name;?>">
<input name="submit" type="submit" value="Update Record">
</div></td>
</tr>
</table>
</form> <!-- InstanceEndEditable --></div>
<div align="center" class="footer"><? mailto('larry@sigmawebstudios.com','email the webmaster');?></div>
<map name="Map">
<area shape="rect" coords="3,3,251,69" href="admin.php" alt="NKH Admin Home">
</map>
</body>
<!-- InstanceEnd --></html>