The subject update failed.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = 6' at line 5.
This is in the edit_subject.ph p page.
I dont know whats wrong with the query i;v had.
[HTML]<?php require_once("i ncludes/connection.php" ); ?>
<?php require_once("i ncludes/functions.php") ; ?>
<?php
if (intval($_GET['subj']) == 0) {
redirect_to("ma in.php");
}
if (isset($_POST['submit'])) {
$errors = array();
$required_field s = array('menu_nam e', 'position', 'visible');
foreach($requir ed_fields as $fieldname) {
if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) {
$errors[] = $fieldname;
}
}
$fields_with_le ngths = array('menu_nam e' => 30);
foreach($fields _with_lengths as $fieldname => $maxlength ) {
if(strlen(trim( mysql_prep($_PO ST[$fieldname]))) > $maxlength ) { $errors[] = $fieldname; }
}
if (empty($errors) ) {
$id = mysql_prep($_GE T['subj']);
$menu_name = mysql_prep($_PO ST['menu_name']);
$position = mysql_prep($_PO ST['position']);
$visible = mysql_prep($_PO ST['visible']);
$query = "UPDATE subjects SET
menu_name = {$menu_name},
position = {$position},
visible = {$visible}
WHERE id = {$id}";
$result = mysql_query($qu ery. $connection);
if (mysql_affected _rows() == 1) {
$message = "Successful ly updated.";
} else {
$message = "The subject update failed.";
$message .= "<br />". mysql_error();
}
} else {
$message = "There were " . count($errors) . " errors in the form.";
}
} if (isset($_POST['submit']))
?>
<?php find_selected_p age(); ?>
<?php include("includ es/header.php"); ?>
<table id="structure" >
<tr>
<td id="navigation" >
<?php echo navigation($sel _subject, $sel_page); ?>
</td>
<td id="page">
<h2>Edit Subject <?php echo $sel_subject['menu_name']; ?></h2>
<?php if (!empty($messag e)) {
echo "<p class=\"message \">" . $message . "</p>";
} ?>
<?php
if (!empty($errors )) {
echo "<p class=\"errors\ ">";
echo "Please review the following fields: <br />";
foreach($errors as $error) {
echo " - " . $error . "<br />";
}
echo "</p>";
}
?>
<form action="edit_su bject.php?subj= <?php echo urlencode($sel_ subject['id']); ?>" method="post">
<p>Subject Name:
<input type="text" name="menu_name " value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" /></p>
<p>Position:
<select name="position" >
<?php
$subject_set = get_all_subject s();
$subject_count = mysql_num_rows( $subject_set);
for($count=1; $count <= $subject_count+ 1; $count++) {
echo "<option value=\"{$count }\"";
if ($sel_subject['position'] == $count) {
echo " selected";
}
echo ">{$count}</option>";
}
?>
</select>
</p>
<p>Visible:
<input type="radio" name="visible" value="0"<?php
if ($sel_subject['visible'] == 0) {echo " checked"; } ?>
/>No
<input type="radio" name="visible" value="1"<?php
if ($sel_subject['visible'] == 1) {echo " checked"; } ?>
/>Yes
</p>
<input type="submit" name="submit" value="Edit Subject" />
<a href="delete_su bject.php?subj= <?php
echo urlencode($sel_ subject['id']); ?>" onclick="return confirm('Are you sure?');">Delet e Subject</a>
</form>
<br />
<a href="main.php" >Cancel</a>
</td>
</tr>
</table>
<?php require("includ es/foot.php"); ?> [/HTML]
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = 6' at line 5.
This is in the edit_subject.ph p page.
I dont know whats wrong with the query i;v had.
[HTML]<?php require_once("i ncludes/connection.php" ); ?>
<?php require_once("i ncludes/functions.php") ; ?>
<?php
if (intval($_GET['subj']) == 0) {
redirect_to("ma in.php");
}
if (isset($_POST['submit'])) {
$errors = array();
$required_field s = array('menu_nam e', 'position', 'visible');
foreach($requir ed_fields as $fieldname) {
if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) {
$errors[] = $fieldname;
}
}
$fields_with_le ngths = array('menu_nam e' => 30);
foreach($fields _with_lengths as $fieldname => $maxlength ) {
if(strlen(trim( mysql_prep($_PO ST[$fieldname]))) > $maxlength ) { $errors[] = $fieldname; }
}
if (empty($errors) ) {
$id = mysql_prep($_GE T['subj']);
$menu_name = mysql_prep($_PO ST['menu_name']);
$position = mysql_prep($_PO ST['position']);
$visible = mysql_prep($_PO ST['visible']);
$query = "UPDATE subjects SET
menu_name = {$menu_name},
position = {$position},
visible = {$visible}
WHERE id = {$id}";
$result = mysql_query($qu ery. $connection);
if (mysql_affected _rows() == 1) {
$message = "Successful ly updated.";
} else {
$message = "The subject update failed.";
$message .= "<br />". mysql_error();
}
} else {
$message = "There were " . count($errors) . " errors in the form.";
}
} if (isset($_POST['submit']))
?>
<?php find_selected_p age(); ?>
<?php include("includ es/header.php"); ?>
<table id="structure" >
<tr>
<td id="navigation" >
<?php echo navigation($sel _subject, $sel_page); ?>
</td>
<td id="page">
<h2>Edit Subject <?php echo $sel_subject['menu_name']; ?></h2>
<?php if (!empty($messag e)) {
echo "<p class=\"message \">" . $message . "</p>";
} ?>
<?php
if (!empty($errors )) {
echo "<p class=\"errors\ ">";
echo "Please review the following fields: <br />";
foreach($errors as $error) {
echo " - " . $error . "<br />";
}
echo "</p>";
}
?>
<form action="edit_su bject.php?subj= <?php echo urlencode($sel_ subject['id']); ?>" method="post">
<p>Subject Name:
<input type="text" name="menu_name " value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" /></p>
<p>Position:
<select name="position" >
<?php
$subject_set = get_all_subject s();
$subject_count = mysql_num_rows( $subject_set);
for($count=1; $count <= $subject_count+ 1; $count++) {
echo "<option value=\"{$count }\"";
if ($sel_subject['position'] == $count) {
echo " selected";
}
echo ">{$count}</option>";
}
?>
</select>
</p>
<p>Visible:
<input type="radio" name="visible" value="0"<?php
if ($sel_subject['visible'] == 0) {echo " checked"; } ?>
/>No
<input type="radio" name="visible" value="1"<?php
if ($sel_subject['visible'] == 1) {echo " checked"; } ?>
/>Yes
</p>
<input type="submit" name="submit" value="Edit Subject" />
<a href="delete_su bject.php?subj= <?php
echo urlencode($sel_ subject['id']); ?>" onclick="return confirm('Are you sure?');">Delet e Subject</a>
</form>
<br />
<a href="main.php" >Cancel</a>
</td>
</tr>
</table>
<?php require("includ es/foot.php"); ?> [/HTML]
Comment