Created
June 24, 2017 18:11
-
-
Save spkellydev/04d38998a18f0bcdfba07f26285bf28d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php require_once("inc/connect.php"); ?> | |
<?php require_once("inc/functions.php"); ?> | |
<?php | |
if (intval($_GET['info']) == 0) { | |
header("Location: content.php"); | |
exit; | |
} | |
if(isset($_POST['submit']) && $_POST['submit'] == "Edit") { | |
//If it is set, run form validation | |
//form validation | |
$errors = array(); | |
$required_fields = array('menu', 'position', 'visible'); | |
foreach ($required_fields as $field_name) { | |
if(!isset($_POST[$field_name]) || empty($_POST[$field_name]) && !is_numeric($_POST[$field_name])) { | |
$errors[] = $field_name; | |
} | |
} | |
$fields_with_lengths = array('menu' => 30); | |
foreach ($fields_with_lengths as $field_name => $max_length) { | |
if(strlen(trim(mysql_prep($_POST[$field_name]))) > $max_length) { | |
$errors[] = $field_name; | |
echo "<p>You've Entered More Than 30 Characters</p>"; | |
} | |
} | |
if (empty($errors)){ | |
$id = mysql_prep($_GET['info']); | |
$menu = mysql_prep($_POST['menu']); //use POST array for form method | |
$position = mysql_prep($_POST['position']); | |
$visible = mysql_prep($_POST['visible']); | |
$query = "UPDATE information SET | |
menu = '{$menu}', | |
position {$position}, | |
visible = {$visible} | |
WHERE id = {$id}"; | |
$result = mysql_query($query, $connection); | |
if (mysql_affected_rows() == 1 ) { | |
//Successful | |
$message = "The information was correctly updated"; | |
} else { | |
//Failure | |
$message = "The information was not accepted"; | |
$message .= "<br>" . mysql_error(); | |
} | |
} else { | |
//Errors are happening | |
$message = "There were " . count($errors) . " too many errors in the form"; | |
} | |
} | |
?> | |
<?php find_selected_page(); ?> | |
<?php include("inc/header.php"); ?> | |
<h2>Edit Info <?php echo $sel_table1['menu']; ?></h2> | |
<?php | |
if (!empty($message)) { | |
//Successful update | |
echo "<p>" . $message . "</p>"; | |
} | |
?> | |
<form action="edit_info.php?info=<?php echo urlencode($sel_table1['id']); ?>" method="post"> | |
<label>Info Title: | |
<input type="text" name="menu" value="<?php | |
echo $sel_table1['menu']; | |
?>" id="menu"> | |
</label> | |
<label>Position: | |
<select name="position"> | |
<?php | |
$info_set = get_all_info(); | |
$info_count = mysql_num_rows($info_set); //ask how mnay rows | |
for($count=1; $count <=$info_count+1; $count++) { | |
echo "<option value=\"{$count}\""; | |
if ($sel_table1['position'] == $count) { | |
echo "selected"; | |
} | |
echo " >{$count}</option>"; | |
} | |
?> | |
</select> | |
</label> | |
<label>Visible: | |
<input type="radio" name="visible" value="0" | |
<?php | |
if ($sel_table1['visible'] == 0) { | |
echo "checked"; | |
} | |
?> | |
>No | |
| |
<input type="radio" name="visible" value="1" | |
<?php | |
if ($sel_table1['visible'] == 1) { | |
echo "checked"; | |
} | |
?> | |
>Yes | |
</label> | |
<input type="submit" name="submit" value="Edit"> | |
</form> | |
<br> | |
<a href="content.php">Cancel</a> | |
<!--END MAIN id="content"--> | |
<?php | |
require("inc/footer.php"); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment