j05hr Posted November 9, 2009 Share Posted November 9, 2009 On an edit page when you want something to select what a user has previously selected from the database, how would you do this for a List/Menu box? The only way I know how is <?php echo $sel_subject['house_price']; ?> This is what I have <select name="propType" /> <?php echo $sel_subject['propType']; ?> <option></option> <option>House</option> <option>Bungalow</option> <option>Flat</option> <option>Detached</option> <option>Semi Detached</option> <option>Terraced</option> </select> Also is it wrong to leave all the options on this page? Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/ Share on other sites More sharing options...
simshaun Posted November 9, 2009 Share Posted November 9, 2009 Unless I'm misunderstanding your question, the solution is simple HTML. Make your options look like this: <option <?php echo isset($sel_subject['propType']) && $sel_subject['propType'] == 'House' ? 'selected="selected"' : ''; ?>>House</option> Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954287 Share on other sites More sharing options...
j05hr Posted November 9, 2009 Author Share Posted November 9, 2009 I think you misunderstood the question. For example if you had a list box with your age in it, when you got a year older, you would need to change it, how would you echo back from the database to have the answer you had from last time. Like in a text box you just put <?php echo $sel_subject['house_price']; ?> in the value and it echos back what you wrote in the textbox in the database. It doesn't work that simply with a listbox. Sorry for the confusion and not explaining myself properly. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954369 Share on other sites More sharing options...
simshaun Posted November 9, 2009 Share Posted November 9, 2009 If your select box does not have an option for your "new" age, then you would have to add an additional option. Example: John is 30. Your select box has 28,29,30 as options. John turns 31. There's nothing you can do with your select box unless you add an additional option for 31. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954372 Share on other sites More sharing options...
j05hr Posted November 9, 2009 Author Share Posted November 9, 2009 No, it does have an option for your next birthday. I'll explain what I mean with a text box. You write something in it, you want to change what you've written because you've made a spelling mistake. What you've already is still there when you go to edit it because it's echoed back from the database (with that line of code I posted) how would you echo back the same result with a list box? Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954378 Share on other sites More sharing options...
ThunderLee Posted November 9, 2009 Share Posted November 9, 2009 Is this what you mean? <select name="propType" /> <option selected><?php echo $sel_subject['propType']; ?></option> <option></option> <option>House</option> <option>Bungalow</option> <option>Flat</option> <option>Detached</option> <option>Semi Detached</option> <option>Terraced</option> </select> <select name="bday" /> <option selected><?php echo $sel_subject['bday']; ?></option> <option></option> <option>28</option> <option>29</option> <option>30</option> <option>31</option> <option>32</option> <option>33</option> </select> If its not I don't understand what you're trying to do o.o.. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954388 Share on other sites More sharing options...
simshaun Posted November 9, 2009 Share Posted November 9, 2009 Sorry for my ignorance if I am still not getting what you are asking. List boxes (select boxes) do not work the same way as text inputs and textareas. With inputs and textareas, you simply tell them what to display and thats it. Ex: <input type="text" name="bla" value="Hello World!" /><br /> <textarea name="blabla">Hello World!</textarea> With a list box, you have a predefined list of options that the user can choose from. <select name="blablabla"> <option>Hello World!</option> <option>Goodbye World!</option> </select> When a user pulls up an "edit info" form, you want whatever was saved in the database to be selected. If the database contains "Goodbye World!" and you want that option to be selected, this is how you would do it. <select name="blablabla"> <option <?php echo $valueFromDb == 'Hello World!' ? 'selected="selected"' : ''; ?>>Hello World!</option> <option <?php echo $valueFromDb == 'Goodbye World!' ? 'selected="selected"' : ''; ?>>Goodbye World!</option> </select> A problem arises if you have a value in the database that does not have a corresponding option in the list box. Solving it is out of scope from what you are asking I believe, but please let me know if this is not the case. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954390 Share on other sites More sharing options...
j05hr Posted November 9, 2009 Author Share Posted November 9, 2009 Thanks, yeah that is what I meant and it works, it's what I tried but where I was going wrong was, not putting the PHP in an option tag. I did it like, <select name="propType" /> <?php echo $sel_subject['propType']; ?> <option></option> <option>House</option> <option>Bungalow</option> <option>Flat</option> <option>Detached</option> <option>Semi Detached</option> <option>Terraced</option> </select> Makes sense why it wouldn't work now, thanks Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954392 Share on other sites More sharing options...
ThunderLee Posted November 9, 2009 Share Posted November 9, 2009 Sorry for my ignorance if I am still not getting what you are asking. List boxes (select boxes) do not work the same way as text inputs and textareas. With inputs and textareas, you simply tell them what to display and thats it. Ex: <input type="text" name="bla" value="Hello World!" /><br /> <textarea name="blabla">Hello World!</textarea> With a list box, you have a predefined list of options that the user can choose from. <select name="blablabla"> <option>Hello World!</option> <option>Goodbye World!</option> </select> When a user pulls up an "edit info" form, you want whatever was saved in the database to be selected. If the database contains "Goodbye World!" and you want that option to be selected, this is how you would do it. <select name="blablabla"> <option <?php echo $valueFromDb == 'Hello World!' ? 'selected="selected"' : ''; ?>>Hello World!</option> <option <?php echo $valueFromDb == 'Goodbye World!' ? 'selected="selected"' : ''; ?>>Goodbye World!</option> </select> A problem arises if you have a value in the database that does not have a corresponding option in the list box. Solving it is out of scope from what you are asking I believe, but please let me know if this is not the case. hehe that works P: .. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954395 Share on other sites More sharing options...
j05hr Posted November 9, 2009 Author Share Posted November 9, 2009 I'm doing it for bedrooms and now the one that's selected comes up first, but it displayes like this. (Say I selected 3 bedrooms) 3 1 2 3 4 5+ Also is <option selected> valid because it's coming up in red on my editor Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954397 Share on other sites More sharing options...
simshaun Posted November 9, 2009 Share Posted November 9, 2009 Post the code you are using. And it probably shows red in your editor because it needs to be selected="selected" to be valid, depending on your doctype. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954400 Share on other sites More sharing options...
j05hr Posted November 9, 2009 Author Share Posted November 9, 2009 <?php require_once("includes/session.php"); ?> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php confirm_logged_in(); ?> <?php if (intval($_GET['subj']) == 0) { redirect_to("content1.php"); } if (isset($_POST['submit'])) { $errors = array(); $required_fields = array('menu_name', 'position', 'visible', 'content', 'house_price', 'bedrooms', 'propType'); foreach($required_fields as $fieldname) { if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) { $errors[] = $fieldname; } } $fields_with_lengths = array('menu_name' => 30); foreach($fields_with_lengths as $fieldname => $maxlength ) { if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; } } if (empty($errors)) { // Perform Update $id = mysql_prep($_GET['subj']); $menu_name = mysql_prep($_POST['menu_name']); $position = mysql_prep($_POST['position']); $visible = mysql_prep($_POST['visible']); $content = mysql_prep($_POST['content']); $house_price = mysql_prep($_POST['house_price']); $bedrooms = mysql_prep($_POST['bedrooms']); $propType = mysql_prep($_POST['propType']); $query = "UPDATE subjects SET menu_name = '{$menu_name}', position = {$position}, visible = {$visible}, content = '{$content}', house_price = '{$house_price}', bedrooms = {$bedrooms}, propType = {$propType} WHERE id = {$id}"; $result = mysql_query($query, $connection); if (mysql_affected_rows() == 1) { // Success $message = "The subject was successfully updated."; } else { // Failed $message = "The subject update failed."; $message .= "<br />". mysql_error(); } } else { // Errors occurred $message = "There were " . count($errors) . " errors in the form."; } } // end: if (isset($_POST['submit'])) ?> <?php find_selected_page();?> <?php include("includes/header.php"); ?> <div id="content"> <h2> Buying Edit Page</h2> <br /> <h5>Edit Subject: <?php echo $sel_subject ['menu_name']; ?></h5> <?php if (!empty($message)) { echo "<p class=\"messge\">" . $message . "</p>"; } ?> <?php // output a list of the fields that had errors if (!empty($errors)) { echo "<p class=\"errors\">"; echo "Please review the following fields:<br />"; foreach($errors as $error) { echo " - " . $error . "<br />"; } echo "</p>"; } ?> <form action="edit_subject.php?subj=<?php echo urlencode($sel_subject['id']);?>" method="post"> <p>Subject name: <input type="text" name="menu_name" value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" /> </p> <p>House Price: <input type="text" name="house_price" value="<?php echo $sel_subject['house_price']; ?>" id="house_price" /> </p> <p>Bedrooms: <select name="bedrooms" /> <option selected><?php echo $sel_subject['bedrooms']; ?></option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5+</option> </select> </p> <p>Type of Property: <select name="propType" /> <option><?php echo $sel_subject['propType']; ?></option> <option>House</option> <option>Bungalow</option> <option>Flat</option> <option>Detached</option> <option>Semi Detached</option> <option>Terraced</option> </select> </p> <p>Edit content: <textarea name="content" rows="5" cols="70"><?php echo $sel_subject['content']; ?> </textarea> </p> <p>Position: <select name="position"> <?php $subject_set = get_all_subjects(); $subject_count = mysql_num_rows($subject_set); // $subject_count + 1 b/c we are adding a subject for($count=1; $count <= $subject_count+1; $count++) { echo "<option value=\"{$count}\""; if ($sel_subject['position'] == $count) { echo " selected"; } echo ">{$count}</option>"; } ?> </select> </p> <p>Visible: <input type="radio" name="visible" value="0"<?php if ($sel_subject['visible'] == 0) { echo " checked"; } ?> /> No <input type="radio" name="visible" value="1"<?php if ($sel_subject['visible'] == 1) { echo " checked"; } ?> /> Yes </p> <input type="submit" name="submit" value="Update Subject" /> </p> <h5 id="link"><a href="delete_subject.php?subj=<?php echo urlencode($sel_subject['id']); ?>" onclick="return confirm('Are you sure?');">Delete Subject</a></h5> </form> <br /> <h5 id="link"><a href="edit_page.php?page=<?php echo urlencode($sel_subject['id']); ?>">Edit Page</a></h5> <h5 id="link"><a href="content1.php">Cancel</a></h5> <h5 id="link"><a href="new_page.php?subj=<?php echo $sel_subject['id']; ?>">+ Add a new page to this subject</a></h5> <?php ?> </div> <?php require("includes/footer.php"); ?> My header where the main html is.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Estate Agents</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="stylenew.css" /> <!--[if lte IE 6]> <style type="text/css"> #page-wrap {display:inline-block;} .featured {padding: 0px;} </style> <![endif]--> <!--[if lte IE 7]> <style type="text/css"> #page-wrap {display:inline-block;} .featured {padding-bottom: 10px;} </style> <![endif]--> </head> <body> <div id="page-wrap"> <h1>Estate Agent</h1> <div id="navigation"> <ul> <li class="home"><a href="index.php">Home</a></li> <li class="buying"><a href="buying.php">Buying</a></li> <li class="selling"><a href="selling.php">Selling</a></li> <li class="renting"><a href="renting.php">Renting</a></li> <li class="letting"><a href="letting.php">Letting</a></li> <li class="contact"><a href="contact.php">Contact</a></li> </ul> </div> <div id="sidebar"> <h3 class="sidebar-text"></h3> <div id="menu"> <ul> <li class="home"><a href="index.php">Home</a></li> <li class="buy"><a href="buying.php">Buying</a></li> <li class="sell"><a href="selling.php">Selling</a></li> <li class="renting"><a href="renting.php">Renting</a></li> <li class="newhomes"><a href="newhomes.php">New Homes</a></li> <li class="contact"><a href="contact.php">Contact Us</a></li> <li class="about"><a href="about.php">About Us</a></li> <li class="location"><a href="location.php">Locations</a></li> <li class="why"><a href="whyus.php">Why Use Us</a></li> <li class="mailing"><a href="mailinglist.php">Mailing List</a></li> </ul> <div class="featured"> <h3 class="sidebar-text1"></h3> </div> <div class="featured-bg"> <a href="home2.php"><img src="pictures/feature-house.jpg" alt="propoftheweek" /></a> <p>Price: £1.395 000 </p> <p>5 Bedrooms </p> <p>Indoor Swimming Pool</p> <p>Tennis Court</p> <p>Gym</p> <p>Double Garage </p> </div> </div> </div> <div id="flash"> <object type="application/x-shockwave-flash" data="transition.swf" width="695" height="215"> <param name="movie" value="transition.swf" /> <param name="quality" value="high"/> </object> </div> Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954410 Share on other sites More sharing options...
simshaun Posted November 9, 2009 Share Posted November 9, 2009 Looking at this portion specifically: <p>Bedrooms: <select name="bedrooms" /> <option selected><?php echo $sel_subject['bedrooms']; ?></option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5+</option> </select> </p> <p>Type of Property: <select name="propType" /> <option><?php echo $sel_subject['propType']; ?></option> <option>House</option> <option>Bungalow</option> <option>Flat</option> <option>Detached</option> <option>Semi Detached</option> <option>Terraced</option> </select> </p> Make it look like the code I posted last. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954412 Share on other sites More sharing options...
j05hr Posted November 9, 2009 Author Share Posted November 9, 2009 It's still doing the same with your code Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954421 Share on other sites More sharing options...
simshaun Posted November 9, 2009 Share Posted November 9, 2009 Did you take out <option><?php echo $sel_subject['propType']; ?></option> ?? (You need to) Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954461 Share on other sites More sharing options...
j05hr Posted November 10, 2009 Author Share Posted November 10, 2009 I copy and pasted what you sent last time, is that wrong? Also for those lists, what should the type be in the database as it's saying Unknown column 'Bungalow' in 'field list' And You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' propType = 3 WHERE id = 53' at line 7 when I try to use 5+ bedrooms (assuming what I'm using doesn't like the plus sign as 1,2,3 and 4 bedrooms work but 5+ and none of the words work on type of property Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954475 Share on other sites More sharing options...
simshaun Posted November 10, 2009 Share Posted November 10, 2009 I assume that is when you are trying to update a property? Take a look at your UPDATE sql - propType is a string value so you need to wrap it with quotes in the SQL. If you are still having problems after fixing that, copy and paste your code once more. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954520 Share on other sites More sharing options...
j05hr Posted November 10, 2009 Author Share Posted November 10, 2009 Yeah that solved that, now is there anyway to make it so the one selected is just highlighted and not added to the top so it had two values? Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954731 Share on other sites More sharing options...
simshaun Posted November 10, 2009 Share Posted November 10, 2009 Yea. You need to use the method I showed you and remove the option that you added based on ThunderLee's response. Again, if it does not work, post the revised code. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-954914 Share on other sites More sharing options...
j05hr Posted November 10, 2009 Author Share Posted November 10, 2009 It doesn't work but I didn't think you knew what I meant. Here is the code I've used <select name="bedrooms"/> <option <?php echo $sel_subject == '1!' ? 'selected="selected"' : ''; ?>>1</option> <option <?php echo $sel_subject == '2!' ? 'selected="selected"' : ''; ?>>2</option> <option <?php echo $sel_subject == '3!' ? 'selected="selected"' : ''; ?>>3</option> <option <?php echo $sel_subject == '4!' ? 'selected="selected"' : ''; ?>>4</option> <option <?php echo $sel_subject == '5+!' ? 'selected="selected"' : ''; ?>>5+</option> </select> Say I've selected 2 and click submit, it saves it which is fine, if I came back to edit it. I want it to say 2 (the last thing you saved it as) but it just says the first option. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-955032 Share on other sites More sharing options...
simshaun Posted November 10, 2009 Share Posted November 10, 2009 Try $sel_subject['bedrooms'] instead of just $sel_subject. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-955040 Share on other sites More sharing options...
j05hr Posted November 10, 2009 Author Share Posted November 10, 2009 Still not working, was that a guess that might of made it work or it should of done? Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-955048 Share on other sites More sharing options...
simshaun Posted November 10, 2009 Share Posted November 10, 2009 No it was not a guess. Post your entire code and let me fix it for you. Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-955074 Share on other sites More sharing options...
j05hr Posted November 10, 2009 Author Share Posted November 10, 2009 <?php require_once("includes/session.php"); ?> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php confirm_logged_in(); ?> <?php if (intval($_GET['subj']) == 0) { redirect_to("content1.php"); } if (isset($_POST['submit'])) { $errors = array(); $required_fields = array('menu_name', 'position', 'visible', 'content', 'house_price', 'bedrooms', 'propType'); foreach($required_fields as $fieldname) { if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) { $errors[] = $fieldname; } } $fields_with_lengths = array('menu_name' => 30); foreach($fields_with_lengths as $fieldname => $maxlength ) { if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; } } if (empty($errors)) { // Perform Update $id = mysql_prep($_GET['subj']); $menu_name = mysql_prep($_POST['menu_name']); $position = mysql_prep($_POST['position']); $visible = mysql_prep($_POST['visible']); $content = mysql_prep($_POST['content']); $house_price = mysql_prep($_POST['house_price']); $bedrooms = mysql_prep($_POST['bedrooms']); $propType = mysql_prep($_POST['propType']); $query = "UPDATE subjects SET menu_name = '{$menu_name}', position = {$position}, visible = {$visible}, content = '{$content}', house_price = '{$house_price}', bedrooms = '{$bedrooms}', propType = '{$propType}' WHERE id = {$id}"; $result = mysql_query($query, $connection); if (mysql_affected_rows() == 1) { // Success $message = "The subject was successfully updated."; } else { // Failed $message = "The subject update failed."; $message .= "<br />". mysql_error(); } } else { // Errors occurred $message = "There were " . count($errors) . " errors in the form."; } } // end: if (isset($_POST['submit'])) ?> <?php find_selected_page();?> <?php include("includes/header.php"); ?> <div id="content"> <h2> Buying Edit Page</h2> <br /> <h5>Edit Subject: <?php echo $sel_subject ['menu_name']; ?></h5> <?php if (!empty($message)) { echo "<p class=\"messge\">" . $message . "</p>"; } ?> <?php // output a list of the fields that had errors if (!empty($errors)) { echo "<p class=\"errors\">"; echo "Please review the following fields:<br />"; foreach($errors as $error) { echo " - " . $error . "<br />"; } echo "</p>"; } ?> <form action="edit_subject.php?subj=<?php echo urlencode($sel_subject['id']);?>" method="post"> <p>Subject name: <input type="text" name="menu_name" value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" /> </p> <p>House Price: <input type="text" name="house_price" value="<?php echo $sel_subject['house_price']; ?>" id="house_price" /> </p> <p>Bedrooms: <select name="bedrooms"/> <option <?php echo $sel_subject['bedrooms'] == '1!' ? 'selected="selected"' : ''; ?>>1</option> <option <?php echo $sel_subject['bedrooms'] == '2!' ? 'selected="selected"' : ''; ?>>2</option> <option <?php echo $sel_subject['bedrooms'] == '3!' ? 'selected="selected"' : ''; ?>>3</option> <option <?php echo $sel_subject['bedrooms'] == '4!' ? 'selected="selected"' : ''; ?>>4</option> <option <?php echo $sel_subject['bedrooms'] == '5+!' ? 'selected="selected"' : ''; ?>>5+</option> </select> </p> <p>Type of Property: <select name="propType" /> <option <?php echo $sel_subject == 'House!' ? 'House"' : ''; ?>>House</option> <option <?php echo $sel_subject == 'Bungalow!' ? 'selected="selected"' : ''; ?>>Bungalow</option> <option <?php echo $sel_subject == 'Flat!' ? 'selected="selected"' : ''; ?>>Flat</option> <option <?php echo $sel_subject == 'Detatched!' ? 'selected="selected"' : ''; ?>>Detatched</option> <option <?php echo $sel_subject == 'Semi_detached!' ? 'selected="selected"' : ''; ?>>Semi_Detached</option> <option <?php echo $sel_subject == 'Terraced!' ? 'selected="selected"' : ''; ?>>Terraced</option> </select> </p> <p>Edit content: <textarea name="content" rows="5" cols="70"><?php echo $sel_subject['content']; ?> </textarea> </p> <p>Position: <select name="position"> <?php $subject_set = get_all_subjects(); $subject_count = mysql_num_rows($subject_set); // $subject_count + 1 b/c we are adding a subject for($count=1; $count <= $subject_count+1; $count++) { echo "<option value=\"{$count}\""; if ($sel_subject['position'] == $count) { echo " selected"; } echo ">{$count}</option>"; } ?> </select> </p> <p>Visible: <input type="radio" name="visible" value="0"<?php if ($sel_subject['visible'] == 0) { echo " checked"; } ?> /> No <input type="radio" name="visible" value="1"<?php if ($sel_subject['visible'] == 1) { echo " checked"; } ?> /> Yes </p> <input type="submit" name="submit" value="Update Subject" /> </p> <h5 id="link"><a href="delete_subject.php?subj=<?php echo urlencode($sel_subject['id']); ?>" onclick="return confirm('Are you sure?');">Delete Subject</a></h5> </form> <br /> <h5 id="link"><a href="edit_page.php?page=<?php echo urlencode($sel_subject['id']); ?>">Edit Page</a></h5> <h5 id="link"><a href="content1.php">Cancel</a></h5> <h5 id="link"><a href="new_page.php?subj=<?php echo $sel_subject['id']; ?>">+ Add a new page to this subject</a></h5> <?php ?> </div> <?php require("includes/footer.php"); ?> [code] Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-955145 Share on other sites More sharing options...
simshaun Posted November 10, 2009 Share Posted November 10, 2009 All I touched was the select boxes. <?php require_once("includes/session.php"); ?> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php confirm_logged_in(); ?> <?php if (intval($_GET['subj']) == 0) { redirect_to("content1.php"); } if (isset($_POST['submit'])) { $errors = array(); $required_fields = array('menu_name', 'position', 'visible', 'content', 'house_price', 'bedrooms', 'propType'); foreach($required_fields as $fieldname) { if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) { $errors[] = $fieldname; } } $fields_with_lengths = array('menu_name' => 30); foreach($fields_with_lengths as $fieldname => $maxlength ) { if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; } } if (empty($errors)) { // Perform Update $id = mysql_prep($_GET['subj']); $menu_name = mysql_prep($_POST['menu_name']); $position = mysql_prep($_POST['position']); $visible = mysql_prep($_POST['visible']); $content = mysql_prep($_POST['content']); $house_price = mysql_prep($_POST['house_price']); $bedrooms = mysql_prep($_POST['bedrooms']); $propType = mysql_prep($_POST['propType']); $query = "UPDATE subjects SET menu_name = '{$menu_name}', position = {$position}, visible = {$visible}, content = '{$content}', house_price = '{$house_price}', bedrooms = '{$bedrooms}', propType = '{$propType}' WHERE id = {$id}"; $result = mysql_query($query, $connection); if (mysql_affected_rows() == 1) { // Success $message = "The subject was successfully updated."; } else { // Failed $message = "The subject update failed."; $message .= "<br />". mysql_error(); } } else { // Errors occurred $message = "There were " . count($errors) . " errors in the form."; } } // end: if (isset($_POST['submit'])) ?> <?php find_selected_page();?> <?php include("includes/header.php"); ?> <div id="content"> <h2> Buying Edit Page</h2> <br /> <h5>Edit Subject: <?php echo $sel_subject ['menu_name']; ?></h5> <?php if (!empty($message)) { echo "<p class=\"messge\">" . $message . "</p>"; } ?> <?php // output a list of the fields that had errors if (!empty($errors)) { echo "<p class=\"errors\">"; echo "Please review the following fields:<br />"; foreach($errors as $error) { echo " - " . $error . "<br />"; } echo "</p>"; } ?> <form action="edit_subject.php?subj=<?php echo urlencode($sel_subject['id']);?>" method="post"> <p>Subject name: <input type="text" name="menu_name" value="<?php echo $sel_subject['menu_name']; ?>" id="menu_name" /> </p> <p>House Price: <input type="text" name="house_price" value="<?php echo $sel_subject['house_price']; ?>" id="house_price" /> </p> <p>Bedrooms: <select name="bedrooms"/> <option <?php echo $sel_subject['bedrooms'] == '1' ? 'selected="selected"' : ''; ?>>1</option> <option <?php echo $sel_subject['bedrooms'] == '2' ? 'selected="selected"' : ''; ?>>2</option> <option <?php echo $sel_subject['bedrooms'] == '3' ? 'selected="selected"' : ''; ?>>3</option> <option <?php echo $sel_subject['bedrooms'] == '4' ? 'selected="selected"' : ''; ?>>4</option> <option <?php echo $sel_subject['bedrooms'] == '5+' ? 'selected="selected"' : ''; ?>>5+</option> </select> </p> <p>Type of Property: <select name="propType" /> <option <?php echo $sel_subject['propType'] == 'House' ? 'House"' : ''; ?>>House</option> <option <?php echo $sel_subject['propType'] == 'Bungalow' ? 'selected="selected"' : ''; ?>>Bungalow</option> <option <?php echo $sel_subject['propType'] == 'Flat' ? 'selected="selected"' : ''; ?>>Flat</option> <option <?php echo $sel_subject['propType'] == 'Detatched' ? 'selected="selected"' : ''; ?>>Detatched</option> <option <?php echo $sel_subject['propType'] == 'Semi_Detached' ? 'selected="selected"' : ''; ?>>Semi_Detached</option> <option <?php echo $sel_subject['propType'] == 'Terraced' ? 'selected="selected"' : ''; ?>>Terraced</option> </select> </p> <p>Edit content: <textarea name="content" rows="5" cols="70"><?php echo $sel_subject['content']; ?> </textarea> </p> <p>Position: <select name="position"> <?php $subject_set = get_all_subjects(); $subject_count = mysql_num_rows($subject_set); // $subject_count + 1 b/c we are adding a subject for($count=1; $count <= $subject_count+1; $count++) { echo "<option value=\"{$count}\""; if ($sel_subject['position'] == $count) { echo " selected"; } echo ">{$count}</option>"; } ?> </select> </p> <p>Visible: <input type="radio" name="visible" value="0"<?php if ($sel_subject['visible'] == 0) { echo " checked"; } ?> /> No <input type="radio" name="visible" value="1"<?php if ($sel_subject['visible'] == 1) { echo " checked"; } ?> /> Yes </p> <input type="submit" name="submit" value="Update Subject" /> </p> <h5 id="link"><a href="delete_subject.php?subj=<?php echo urlencode($sel_subject['id']); ?>" onclick="return confirm('Are you sure?');">Delete Subject</a></h5> </form> <br /> <h5 id="link"><a href="edit_page.php?page=<?php echo urlencode($sel_subject['id']); ?>">Edit Page</a></h5> <h5 id="link"><a href="content1.php">Cancel</a></h5> <h5 id="link"><a href="new_page.php?subj=<?php echo $sel_subject['id']; ?>">+ Add a new page to this subject</a></h5> </div> <?php require("includes/footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/180894-listmenu-box/#findComment-955155 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.