hI all.
I have a similar problem to another thread in this forum which did help somewhat but in my case all my records are updating and I cannot get it fixed despite searching around the web... I have searched and tried different things but am not getting anywhere. Maybe someone here can help me out...
I have a page with records. There is an option for a user to edit each row individualy when they click "Edit". The 'record_id' is passed in a url to an 'editrates.php' page. Once I have clicked 'SUBMIT' there is a function "opener.location.reload(true)" which refreshes the parent page but all my records are updated...!
I only want to allow certain columns to be updated and have the necessary form fields in place (only those that I allow to be edited) and they are populated with the data that is already in the database. I have checked in a few locations on my 'editrates.php' page (by way of an echo) to check that the 'record_id' is correct and not being lost along the way. Idid this due to the fact that my UPDATE QUERY was originally not updating anything at all. That part is solved but I am now sitting in a spot where when I run the UPDATE query, all my records are updated.. I have checked the web and found that there is referenece to the WHERE clause being a sources of this type of problem so I have focused on that which brought me here.
My code is as follows and I am really hoping someone can help me here as now three solid days trying to learn php and fix this code at the same time...
<?php
include '../dbfunctions.php';
session_start();
$link = dbConnect();
checkVenueLogin();
if( isset($_GET['id']) )
$edit_id = $_GET['id'];
else $edit_id = "";
echo $edit_id;
if( isset($_POST['Submit']) ) {
$query = "UPDATE rates SET `datefrom` = '".$_POST['datefrom']."', `dateto` = '".$_POST['dateto']."', `ratename` = '".$_POST['ratename']."', `single` = '".$_POST['single']."', `double` = '".$_POST['double']."', `child` = '".$_POST['child']."', `infant` = '".$_POST['infant']."', `base` = '".$_POST['base']."' where '".$rateid."' = '".$edit_id."'";
$result = mysql_query($query) or die ("ERROR: " . MYSQL_ERROR() );
}
$rates = "SELECT * FROM rates WHERE id = '".$edit_id."' limit 1";
$rate = mysql_query($rates) or die (mysql_error());
$rate = mysql_fetch_array($rate);
echo ("id: " . $rate[0] . " ");
//$rate = mysql_fetch_array($rates, MYSQL_ASSOC);
//$rateid = $rate['id'];
$venues = dbGetRows("venues", "id = '".$_SESSION['venueid']."'");
$venue = mysql_fetch_array($venues, MYSQL_ASSOC);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Modify Rate NO. <?PHP echo $rateid; ?></title>
<link href="../bb.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" src="../calendar/calendar.js"></script>
<script language="JavaScript" src="../calendar/wcalendar.js"></script>
<script language="JavaScript" src="../calendar/calendar-en.js"></script>
</head>
<body bgcolor="#FFF4DC"
<?php if(isset($_POST['Submit']) && $result) echo "onLoad=\"window.close(); opener.location.reload(true);\""; ?>>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="32"><img src="images/admin_03.gif"></td>
<td width="0*" bgcolor="#FFFFFF" background="images/admin_04.gif" style="background-repeat: repeat-x;"> </td>
<td width="35"><img src="images/admin_07.gif" width="32" height="33"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" background="images/admin_15.gif" style="background-repeat: repeat-y;"></td>
<td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-left: 10px; margin-right: 10px;">
<tr>
<td>
<font size="3"><b><?php echo $venue['venuename']; ?> - MODIFY RATE</b></font><br>
<br>
<form name="form1" method="post" action="editrates.php">
<table width="449" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="104"><b>Rate Name</b></td>
<td width="235" valign="top"><input type="text" name="ratename" value="<?php echo $rate['ratename']; ?>">
<input type="text" name="id" value="<?php echo $rate[0]; ?>"> </td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
</tr>
<tr>
<td><strong>From Date</strong></td>
<td><input type="text" name="datefrom" id="datefrom" size="10" readonly="true" value="<?php echo $rate['datefrom']; ?>">
<img src="images/calendar01.gif" class="mxw_cld" onClick="return showCalendar('datefrom', 'yyyy-mm-dd', 'false');" style="cursor:pointer;"></td>
</tr>
<tr>
<td><strong>To Date</strong></td>
<td><input type="text" name="dateto" id="dateto" size="10" readonly="true" value="<?php echo $rate['dateto']; ?>">
<img src="images/calendar01.gif" class="mxw_cld" onClick="return showCalendar('dateto', 'yyyy-mm-dd', 'false');" style="cursor:pointer;"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><b> Adults - Single</b></td>
<td><label>
<input type="text" name="single" value="<?php echo $rate['single']; ?>">
</label></td>
</tr>
<tr>
<td><strong>Adults - Double</strong></td>
<td><label>
<input type="text" name="double" value="<?php echo $rate['double']; ?>">
</label></td>
</tr>
<tr>
<td><strong>Child</strong></td>
<td><label>
<input type="text" name="child" value="<?php echo $rate['child']; ?>">
</label></td>
</tr>
<tr>
<td><b>Infant</b></td>
<td><label>
<input type="text" name="infant" value="<?php echo $rate['infant']; ?>">
</label></td>
</tr>
<td><strong>Base Rate</strong></td>
<td><label></label>
<label>
<input type="text" name="base" value="<?php echo $rate['base']; ?>">
</label></td>
</tr>
<tr>
<td colspan="2"><input type="Submit" name="Submit" id="button" value="Submit">
.
<input type="button" name="Cancel" value="Close Window" onClick="window.close();"></td>
</tr>
</table>
</form>
</table></td>
<td bgcolor="#FFFFFF" align="right" background="images/admin_14.gif" style="background-position: right; background-repeat: repeat-y;"></td>
</tr>
<tr>
<td><img src="images/admin_21.gif" width="32" height="33"></td>
<td bgcolor="#FFFFFF" background="images/admin_23.gif" style="background-position: bottom; background-repeat: repeat-x;"></td>
<td><img src="images/admin_20.gif" width="32" height="33"></td>
</tr>
</table>
</body>
</html>