I am writing code to update a database and the checkbox to select whether a entry is active is having a few problems. It does correctly update something to being active when clicked, but because when the page is loaded it is unchecked even though it is active you cannot make it inactive unless you go directly to the database and do this. I am a little lost on what to do, here is the code for the checkbox/active. Also as a side note it is displaying other correct data being pulled from the database just not the checkbox
$result = mysql_query("SELECT * FROM Words where Title= '$Title'");
$row = mysql_fetch_array($result);
$qry_string = "UPDATE Words SET";
if($row['Title'] != $Title)
{
$end_string .= " Title = '$Title'";
}
$_REQUEST["active"] == "on"?$active=1:$active=0;
if($row["active"] != $active)
{
if(isset($end_string)) $end_string .= ", ";
$end_string .= "active = " . $active;
}
And i know that it isn't visible because it isn't the entire code but these are contained in php tags i.e. .
Whole code:
</div>
<div id="main-content" style="padding-bottom: 30000px;margin-bottom: -30000px;" class="col-2-3">
<div class="wrap-col">
<div align="center"><h2>Amazing Health Advances Content Management Systems <br/><br/>Update Words</h2></div>
<?php
$ID = mysql_escape_string($_POST['ID']);
$Title = mysql_escape_string($_POST['Title']);
$Author = mysql_escape_string($_POST['Author']);
$Display_Date = mysql_escape_string($_POST['Display_Date']);
$Word = mysql_escape_string($_POST['Word']);
$Date_Created = mysql_escape_string($_POST['Date_Created']);
$Email = mysql_escape_string($_POST['Email']);
$From = mysql_escape_string($_POST['From']);
$image = mysql_escape_string($_POST['image']);
$URL = mysql_escape_string($_POST['URL']);
$category = mysql_escape_string($_POST['category']);
$active = mysql_escape_string($_REQUEST['active']);
if(isset($_REQUEST["delete"])) {
mysql_query("DELETE FROM Words WHERE Title= '$Title'");
echo mysql_error();
echo 'This Article has been successfully removed from the database. <br><br>';
echo '<a href=index.html>Return to the Articles Page</a><p>';
echo '<a href=art_list.php>Return to the Articles List</a>';
exit;
}
if($_REQUEST["Title"] == "")
{
$EString = 'You must include a Title.';
}
if($_REQUEST["Author"] == "")
{
$EString .= '<br>You must include an Author.';
}
if($_REQUEST["Word"] == "")
{
$EString .= '<Br>You must include an Article';
}
if(isset($EString))
{
echo $EString;
echo '<br><br>Please use your browsers back button to correct the above errors.';
exit;
}
$result = mysql_query("SELECT * FROM Words where Title= '$Title'");
$row = mysql_fetch_array($result);
$qry_string = "UPDATE Words SET";
if($row['Title'] != $Title)
{
$end_string .= " Title = '$Title'";
}
if($row['Author'] != $Author)
{
if(isset($end_string))
{
$end_string .= ", Author = '$Author'";
}
else
{
$end_string = " Author = '$Author'";
}
}
if($row['Display_Date'] != $Display_Date)
{
if(isset($end_string))
{
$end_string .= ", Display_date = '$Display_Date'";
}
else
{
$end_string = " Display_date = '$Display_Date'";
}
}
if($row['Word'] != $Word)
{
echo 'Alter Word<br>';
if(isset($end_string))
{
$end_string .= ", Word = '$Word'";
}
else
{
$end_string = " Word = '$Word'";
}
}
if($row['Date_Created'] != $Date_Created)
{
if(isset($end_string))
{
$end_string .= ", Date_Created = '$Date_Created'";
}
else
{
$end_string = " Date_Created = '$Date_Created'";
}
}
if($row['Email'] != $Email)
{
if(isset($end_string))
{
$end_string .= ", Email = '$Email'";
}
else
{
$end_string = " Email = '$Email'";
}
}
if($row['Source'] != $From)
{
if(isset($end_string))
{
$end_string .= ", Source = '$From'";
}
else
{
$end_string = " Source = '$From'";
}
}
if($row['URL'] != $URL)
{
if(isset($end_string))
{
$end_string .= ", URL = '$URL'";
}
else
{
$end_string = " URL = '$URL'";
}
}
if($row['image'] != $image)
{
if(isset($end_string))
{
$end_string .= ", image = '$image'";
}
else
{
$end_string = " image = '$image'";
}
}
if($row['category'] != $category)
{
if(isset($end_string))
{
$end_string .= ", category = '$category'";
}
else
{
$end_string = " category = '$category'";
}
}
$_REQUEST["active"] == "on"?$active=1:$active=0;
if($row["active"] != $active)
{
if(isset($end_string)) $end_string .= ", ";
$end_string .= "active = " . $active;
}
if(!isset($end_string))
{
echo 'There was no information to be updated.<br><br>';
echo '<a href=index.html>Return to the Articles Page';
exit;
}
$qry_string = $qry_string.$end_string." WHERE Title = '$Title'";
if(mysql_query($qry_string) == FALSE)
echo mysql_error();
echo '<a href=index.html>Return to the Articles Page</a><p>';
echo '<a href=art_list.php>Return to the Articles List</a>';
{
echo 'There was an error attempting to update the database.<br>';
echo 'Please contact the system administrator with the following information:';
echo "<br><br>Query String -> $qry_string";
echo "<br/><br/>mysql_error();";
echo '<a href=index.html>Return to the Articles Page</a><p>';
echo '<a href=art_list.php>Return to the Articles List</a>';
exit;
}
echo 'The database has been successfully updated<br><br>';
echo '<a href=index.html>Return to the Articles Page</a><P>';
echo '<a href=art_list.php>Return to the Articles List</a>';
?>