-
Getting error when submitting 'visible' field to database with php
I am new to php... I am actually trying to walk myself through a Lynda tutorial and have come up on a hang up I can't figure out
The code below works on everything EXCEPT when I try to make submit Visible - No. It doesn't update and says there is an error in my visibility field. If I go into the database and change all of the pages to no (changing the visibility field to zero for all of the fields), I can then use the form and successfully change the Visibility to Yes when submitting the form. I don't know why the visibility is working when I submit - yes (one) and not working when I submit - no (zero)... please can someone help me?
Code of edit_page.php:
//clean up the form data before putting it in the database
$id = mysql_prep($_GET['page']);
$menu_name = trim(mysql_prep($_POST['menu_name']));
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$content = mysql_prep($_POST['content']);
//Database submission only proceeds if there were NO errors.
if(empty($errors)) {
$query = "UPDATE pages SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
content = '{$content}'
WHERE id = {$id}";
$result = mysql_query($query, $connection);
//test to see if the update occurred
if(mysql_affected_rows() == 1) {
//Success!
$message = "The page was successfully updated.";
} else {
//Failed
$message = "The page update failed.";
$message .= "<br />" . mysql_error();
}
} else {
if(count($errors) == 1){
$message = "There was 1 error in the form.";
} else {
//Errors occurred
$message = "There were " . count($errors) . " errors in the form.";
}
}
//END FORM PROCESSING
}//end: if(isset($_POST['submit']))
?>
<?php find_selected_page (); ?>
<div id="sidebar">
<?php echo navigation($sel_subject, $sel_page) ?>
</div>
<div id="main">
<h2> Edit Page: <?php echo $sel_page['menu_name']; ?></h2>
<?php if (!empty($message)) {echo "<p class='message'>" . $message .
"</p>";} ?>
<?php if(!empty($errors)) {display_errors($errors); } ?>
<form action="edit_page.php?page=<?php echo urlencode($sel_page['id']); ?>"
method="post">
<p>Page name:
<input type="text" name="menu_name" value="<?php echo $sel_page['menu_name']; ?>" id="menu_name" />
</p>
<p>Position:
<select name="position">
<?php
$page_set = mysql_query("SELECT * FROM pages ORDER BY position ASC", $connection);
$page_count = mysql_num_rows($page_set);
for($count=1; $count <= $page_count+1; $count++){
echo "<option value='{$count}'";
if($sel_page['position'] == $count){
echo " selected";
}
echo">{$count} </option>";
}
?>
</select>
</p>
<p>Visible:
<input type="radio" name="visible" value="0" <?php if($sel_page['visible'] == 0) {echo " checked";}
?> /> No
<input type="radio" name="visible" value="1" <?php if ($sel_page['visible'] == 1) {echo " checked";}
?> /> Yes
</p>
<p> Content: <br />
<textarea name="content" rows="20" cols="50"><?php echo $sel_page['content']; ?> </textarea>
</p>
<input type="submit" name="submit" value="Edit Page" />
<a href="delete_page.php?page=<?php echo urlencode($sel_page['id']); ?>" onclick="return confirm('Are you sure you want to delete this page?');"> Delete Page </a>
<a href="content.php?page=<?php echo $sel_page['id']; ?>">Cancel</a>
</form>
</div>
I tried posting in Stackoverflow but didn't get a helpful response and I've sometimes had more luck here. The questions and responses that were posted on the other site are below .. maybe someone on here can help me get a little further in trying to figure this out...
Last edited by ristenk1; 07-16-2012 at 04:31 PM.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules