Why wont my PHP script update the database record?

retlav

New member
My Php script will not update my database. it reads the database just fine. BUt it does not post updates. Please help. I am pulling my hair out.



<?php
session_start();
include('dbconnect_main.php');
?>

<?php
session_start();
// get course id and year

$id = htmlspecialchars($_GET['id']);

$year = htmlspecialchars($_GET['year']);


if (!empty($id)) { $_SESSION['recordId']=$id; }

else { $id = $_SESSION['recordId']; }



// if the script has been called without ID or the user hit "Cancel" just return to listing

if (empty($id) || isset($_POST['cancel'])) {

Header("Location: listpolicy.php?year=$year");

exit;

}





// run this only, once the user has hit the "OK" button

if (isset($_POST['ok'])) {

// assign form inputs

$policy_name = $_POST['policy_name'];
$year = $_POST['year'];
$description_p = $_POST['description_p'];
$visible = $_POST['visible'];
$orderx = $_POST['orderx'];

// validate inputs

// add member to database

$query = "UPDATE policy SET policy_name='".$policy_name."',
year='".$year."',
description_p='".$description_p."',
visible='".$visible."',
orderx='".$orderx."',
WHERE id='".$id."'";

$result = $database->query($query);

$database->disconnect();

Header("Location: listpolicy.php?year=$year");

exit;

}

else {

$error = true; // input validation failed

}

}

else { // read member data from database

$query = "SELECT * FROM policy WHERE id='".$id."'";
$result = $database->query($query);
$policy = $result->fetchRow(DB_FETCHMODE_ASSOC,0);
$database->disconnect();


$policy_name = $policy['policy_name'];
$year = $policy['year'];
$description_p = $policy['description_p'];
$visible = $policy['visible'];
$orderx = $policy['orderx'];
}

?>


<script language="JavaScript" type="text/javascript" src="../wysiwyg/wysiwyg.js"></script>

<link rel="stylesheet" type="text/css" href="./fancybox/jquery.fancybox-1.3.1.css" media="screen" />




<link rel="stylesheet" href="style.css" />



</head>
<body>
<div id="ctr" align="center">
<table width="100%" cellspacing="0" cellpadding="5" class="titleTable">
<tr>
<td class="titleCell">
Edit Policy</td>
<td align="right">
<input type="button" value="Policy Listing" class="appbuttons" onClick="location.href='listpolicy.php?year=2010'">
<input type="button" value="Add a Policy" class="appbuttons" onClick="location.href='addpolicy.php'">
</td>
</tr>
</table>
<h3 align="center">You are now editing <?php echo $policy_name; ?> for <?php echo $year; ?> </h3>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="596" border="0" align="center">
<tr>
<td><div align="right">Policy</div></td>
<td width="377"><input name="policy_name" class="singleline" type="text" value="<?php echo $policy_name; ?>" size="52"> <br> <?php

if ( $error && empty($policy_name) ) {

echo '<span style="color:red">Error! Please enter a Policy Name.</span><br>',"\n";

}

?></td>
</tr>
<tr>
<td align="right">Year</td>
<td width="377"><input name="year" class="singleline" type="text" value="<?php echo $year; ?>" size="15"><?php

if ( $error && empty($year) ) {

echo '<span style="color:red">Please enter a Year for this course</span><br>',"\n";

}

?></td>
</tr>
<tr>
<td></td>
<td><textarea name="description_p" cols="60" class="textarea"
 
Back
Top