Ruth Posted March 28, 2008 Share Posted March 28, 2008 I'm tying to perform an edit and add page regarding movies. My form has a text field for the actors name and two drop down menus to display if that person is an actor or director. I'm having a hard time with the drop down menus. I get the actor menu to display but when it comes to editing the if statement does not work. <?php require_once ('dbconnection.php'); $query = "SELECT * FROM people"; $result = mysql_query($query) or die (mysql_error()); //compare id to name //array of id and names while ($row = mysql_fetch_array($result)) { $people[$row['people_id']] = $row ['people_fullname']; } //either populate fields from db or display empty fields switch ($_GET['action']) { case "edit": $q = "SELECT * FROM people WHERE people_id = '".$_GET['id']."'"; $r = mysql_query($q) or die (mysql_error()); $row1 = mysql_fetch_array($r); $people_fullname = $row1['people_fullname']; $people_isactor = $row1['people_isactor']; $people_isdirector = $row1['people_isdirector']; break; default: $people_fullname = ""; $people_isactor = ""; $people_isdirector = ""; break; } ?> <html> <head> <title><?php echo $_GET['action'];?>people</title> <style type = "text/css"> TD{color:#353535; font-family:verdana} TR{color:#FFFFFF; font-family:verdana; background-color:#336699} </style> </head> <body> <center>1 = yes 0 = No</center> <form action="commit.php?action= <?php echo $_GET['action'];?>&type=people&id= <?php echo $_GET['id'];?>" method ="post"> <table border="0" width="750" cellspacing="1" cellpadding="3" bgcolor="#353535" align="center"> <tr> <td bgcolor="#FFFFFF" width="30%">Person Name</td> <td bgcolor="#FFFFFF" width="70%"> <input type="text" name="people_fullname" value="<?php echo $people_fullname ?>"> </td> </tr> <tr> <td bgcolor="#FFFFFF">Actor</td> <td bgcolor="#FFFFFF"> <select name="people_isactor" style="width:150px"> <?php if ($_POST['people_isactor'] == "yes") { $isactor = 1; } else } $isactor = 0; } the database hold actor as 1 if they are an actor and director as 0 if they are not a director. I need to be able to perform an update query on this. Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/ Share on other sites More sharing options...
Ruth Posted March 28, 2008 Author Share Posted March 28, 2008 sorry forgot to add the options for the select statement <select name="people_isactor" style="width:150px"> <option value="yes">yes</option> <option value ="no">No</option> Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503246 Share on other sites More sharing options...
Ruth Posted March 28, 2008 Author Share Posted March 28, 2008 Is anyone out there? I really need help I can't seem to find anything on the net and I've been trying to figure this out for a few days. Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503278 Share on other sites More sharing options...
discomatt Posted March 28, 2008 Share Posted March 28, 2008 One: enclose everything [ code ] [ /code ] to make it easier to navigate. Two: What 'if' isn't working? Why would $_POST be populated it a submit button hadn't been hit? I think you need to learn to walk before you run... play around with this script a bit. <?php if ($_POST['submit']) { echo '<pre>Variable dump for $_POST' . "\n"; print_r($_POST); echo '</pre>'; } else { echo 'Submit button has not been pressed!<br /><br /><br />'; } ?> <form action="" method="post"> <input type="text" name="textbox_sample" /><br /> <br /> <input type="password" name="password_sample" /><br /> <br /> <input type="radio" name="radio_sample" value="val1" />Value 1<br /> <input type="radio" name="radio_sample" value="val2" />Value 2<br /> <input type="radio" name="radio_sample" value="val3" />Value 3<br /> <br /> <input type="checkbox" name="check_sample[]" value="chk1" />Check 1<br /> <input type="checkbox" name="check_sample[]" value="chk2" />Check 2<br /> <input type="checkbox" name="check_sample[]" value="chk3" />Check 3<br /> <br /> <textarea name="textarea_sample"></textarea><br /> <br /> <select name="selectbox_sample"> <option value="sel1">Select 1</option> <option value="sel2">Select 2</option> <option value="sel3">Select 3</option> </select><br /> <br /> <input type="submit" name="submit" /> </form> <br /><br /><br /> <a href="<?php echo $_SERVER['SCRIPT_NAME']; ?>">Reset</a> It will help you better understand how forms work with php Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503292 Share on other sites More sharing options...
Ruth Posted March 28, 2008 Author Share Posted March 28, 2008 The landing page has a table that shows all the titles and people. Beside each movie title and person there is a link for edit or delete. Above the group is a link for add. What I'm showing you in this post is the middle page. An id is passed from the landing page to this one. I'm having a hard time getting that if statement below the select statment to work. The page I posted on the first post is showing the edit form populated with data. Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503301 Share on other sites More sharing options...
discomatt Posted March 28, 2008 Share Posted March 28, 2008 I really don't see an if statement after a select statement. Are you referring to the select element? The logic is really hard to follow in your code. Perhaps comments saying what you are trying to do in your actual code will help out. Im not sure if you're aware, but the form must be submitted via POST before PHP will populate the $_POST superglobal Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503311 Share on other sites More sharing options...
Ruth Posted March 28, 2008 Author Share Posted March 28, 2008 There is a post in there. Its after all the php in the form tag. <?php require_once ('dbconnection.php'); $query = "SELECT * FROM people"; $result = mysql_query($query) or die (mysql_error()); //compare id to name //array of id and names while ($row = mysql_fetch_array($result)) { $people[$row['people_id']] = $row ['people_fullname']; } //either populate fields from db or display empty fields switch ($_GET['action']) { case "edit": $q = "SELECT * FROM people WHERE people_id = '".$_GET['id']."'"; $r = mysql_query($q) or die (mysql_error()); $row1 = mysql_fetch_array($r); $people_fullname = $row1['people_fullname']; $people_isactor = $row1['people_isactor']; $people_isdirector = $row1['people_isdirector']; break; default: $people_fullname = ""; $people_isactor = ""; $people_isdirector = ""; break; } ?> <html> <head> <title><?php echo $_GET['action'];?>people</title> <style type = "text/css"> TD{color:#353535; font-family:verdana} TR{color:#FFFFFF; font-family:verdana; background-color:#336699} </style> </head> <body> <center>1 = yes 0 = No</center> <form action="commit.php?action= <?php echo $_GET['action'];?>&type=people&id= <?php echo $_GET['id'];?>" method ="post"> <table border="0" width="750" cellspacing="1" cellpadding="3" bgcolor="#353535" align="center"> <tr> <td bgcolor="#FFFFFF" width="30%">Person Name</td> <td bgcolor="#FFFFFF" width="70%"> <input type="text" name="people_fullname" value="<?php echo $people_fullname ?>"> </td> </tr> <tr> <td bgcolor="#FFFFFF">Actor</td> <td bgcolor="#FFFFFF"> <select name="people_isactor" style="width:150px"> <option value="yes">yes</option> <option value="no">no</option> <?php if ($_POST['people_isactor'] == "yes") { $isactor = 1; } else } $isactor = 0; } ?> </select> </td> </tr> <tr> <td bgcolor="#FFFFFF" colspan="2" align="center"> <input type="submit" name="SUBMIT" value="<?php echo $_GET['action'];?>"> </td> </tr> </table> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503313 Share on other sites More sharing options...
Ruth Posted March 28, 2008 Author Share Posted March 28, 2008 if ($_POST['people_isactor'] == "yes") { $isactor = 1; } else } $isactor = 0; } This is what I"m having trouble with. It will always read false regardless of what is selected in the drop down menu Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503314 Share on other sites More sharing options...
Ruth Posted March 28, 2008 Author Share Posted March 28, 2008 Thanks for all your wonderul help. Sit on this bloody forum for 6 hrs and nothing thanks for everything. Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503328 Share on other sites More sharing options...
timmy0320 Posted March 28, 2008 Share Posted March 28, 2008 Thanks for all your wonderul help. Sit on this bloody forum for 6 hrs and nothing thanks for everything. You've probably just lost all help from that. You should place your code in [.code] tags so people can read it better and do a little debugging variables along your code to see where the error is happening also. Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503330 Share on other sites More sharing options...
redarrow Posted March 28, 2008 Share Posted March 28, 2008 trie this as an example ok.......... does work.............. ps. where here to help those helping there self aswell ,so please read the web site guide lines ok. <?php $people_isactor="no"; if ($_POST['people_isactor'] == "yes"){ $isactor = 1; }else{ $isactor = 0; } echo $isactor; ?> Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503344 Share on other sites More sharing options...
redarrow Posted March 28, 2008 Share Posted March 28, 2008 Here a 1 min example ok... redesign your code CLUE ($_POST) <?php if($_POST['submit']){ $people_isactor=$_POST['people_isactor']; if ($people_isactor == "yes"){ $isactor = 1; }else{ $isactor = 0; } echo $isactor; } ?> <form method="POST" action=""> <select name="people_isactor" style="width:150px"> <option value="yes">yes</option> <option value="no">no</option> <input type="submit" name="submit" value="Send"> </select> </form> Link to comment https://forums.phpfreaks.com/topic/98332-drop-down-menu/#findComment-503350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.