Dreamweaver (Update Database Problem)
Hi Jason,
I have another problem that I need to resolve… the problem related to updating database information.
I am trying to create a simple system to fill up an online event proposal for student. One student may fill more than one proposal. Each student has it own unique matrix number which I define them as my primary key. However, my current problem is whenever I try to update the data with the same matrix number and with different event the entire row with same matrix number affected. How can I restrict it so that only the event that I want to update is updated without the other event with same matrix number affected? I realized that my current method is a bad practice but I really don’t know how to do it already…. Please help me…. Or guide me please because I kindda lost here…
Thank you.
PHP
=======
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE exclusive_summary SET event=%s, category=%s, club=%s, aim=%s, theme=%s, introduction=%s, `date`=%s, `time`=%s, venue=%s, officer=%s, participant=%s, conclusion=%s WHERE matrix=%s",
GetSQLValueString($_POST['event'], "text"),
GetSQLValueString($_POST['category'], "text"),
GetSQLValueString($_POST['club'], "text"),
GetSQLValueString($_POST['aim'], "text"),
GetSQLValueString($_POST['theme'], "text"),
GetSQLValueString($_POST['introduction'], "text"),
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['time'], "date"),
GetSQLValueString($_POST['venue'], "text"),
GetSQLValueString($_POST['officer'], "text"),
GetSQLValueString($_POST['participant'], "text"),
GetSQLValueString($_POST['conclusion'], "text"),
GetSQLValueString($_POST['matrix'], "text"));
mysql_select_db($database_localhost, $localhost);
$Result1 = mysql_query($updateSQL, $localhost) or die(mysql_error());
<tr valign="baseline">
<td nowrap="nowrap" align="right">Matrix:</td>
<td><?php echo $row_E_summary['matrix']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Event:</td>
<td><input type="text" name="event" value="<?php echo htmlentities($row_E_summary['event'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Category:</td>
<td><select name="category">
<?php
do {
?>
<option value="<?php echo $row_category['code']?>" <?php if (!(strcmp($row_category['code'], htmlentities($row_E_summary['category'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_category['Category']?></option>
<?php
} while ($row_category = mysql_fetch_assoc($category));
?>
</select></td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Club:</td>
<td><select name="club">
<?php
do {
?>
<option value="<?php echo $row_club['C_Club']?>" <?php if (!(strcmp($row_club['C_Club'], htmlentities($row_E_summary['club'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_club['club']?></option>
<?php
} while ($row_club = mysql_fetch_assoc($club));
?>
<tr valign="baseline">
<td nowrap="nowrap" align="right" valign="top">Conclusion:</td>
<td><textarea name="conclusion" cols="50" rows="5"><?php echo htmlentities($row_E_summary['conclusion'], ENT_COMPAT, 'utf-8'); ?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Update record" /></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="matrix" value="<?php echo $row_E_summary['matrix']; ?>" />
</form>