I am using this script on this page to update my database however nothing happens when i submit the form. The only thing that does happen is I get this:
"Article updated" but nothing is put to the dba does anyone know why this might be?
<?php
if(isset($_GET['cid']))
{
$query = "SELECT cid, user_id, first, last, year, age, gender ".
"FROM collegiate ".
"WHERE cid = '{$_GET['cid']}'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
if (mysql_num_rows($result) == 0) {
$_SESSION['is_rec'] = false;
} else {
$_SESSION['is_rec'] = true; // this session acts like an extra controle
}
list($cid, $user_id, $first, $last, $year, $age, $gender) = mysql_fetch_array($result, MYSQL_NUM);
$content = htmlspecialchars($content);
}
else if(isset($_POST['first']))
{
$cid = $_POST['cid'];
$first = $_POST['first'];
$last = $_POST['last'];
$year = $_POST['year'];
$age = $_POST['age'];
$gender = $_POST['gender'];
if(!get_magic_quotes_gpc())
{
$first = addslashes($first);
$last = addslashes($last);
$year = addslashes($year);
$age = addslashes($age);
$gender = addslashes($gender);
}
// update the article in the database
if ($_SESSION['is_rec'])
{
$query = "UPDATE collegiate ".
"SET first = '$first', last = '$last', year = '$year', age = '$age', gender = '$gender' ".
"WHERE cid = '$cid'";
mysql_query($query) or die('Error : ' . mysql_error());
}
else
{
echo "Database could not be UPDATED";
}
// then remove the cached file
$cacheDir = dirname(__FILE__) . '/cache/';
$cacheFile = $cacheDir . '_' . $_GET['cid'] . '.html';
@unlink($cacheFile);
// and remove the index.html too because the file list
// is changed
@unlink($cacheDir . 'index.html');
echo "<p align='center'>Article updated</p>";
// now we will display $title & content
// so strip out any slashes
$first = stripslashes($first);
$last = stripslashes($last);
$year = stripslashes($year);
$age = stripslashes($age);
$gender = stripslashes($gender);
}
?>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="id" value="<?=$cid;?>">
<table width="500" border="0" cellpadding="2" cellspacing="1" class="box" align="center">
<tr>
<td width="100">first</td>
<td><input name="first" type="text" class="box" id="first" value="<?=$first;?>"> </td>
</tr>
<tr>
<td width="100">last</td>
<td><input name="last" type="text" class="box" id="last" value="<?=$last;?>"></td>
</tr>
<tr>
<td width="100">year</td>
<td><input name="year" type="text" class="box" id="year" value="<?=$year;?>"></td>
</tr>
<tr>
<td width="100">age</td>
<td><input name="age" type="text" class="box" id="age" value="<?=$age;?>"></td>
</tr>
<tr>
<td width="100">gender</td>
<td><input name="gender" type="text" class="box" id="gender" value="<?=$gender;?>"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="update" type="submit" class="box" id="update" value="Update Article"></td>
</tr>
</table>
<p align="center"><a href="add_manage_coll.php">Back to admin page</a></p>
</form>