aztec Posted February 14, 2008 Share Posted February 14, 2008 Hello This is some code I have been working on for some while. The first part works fine and puts up the select box, allows you to select and to submit. After pressing submit the page refreshes and put the ?select=XX&select=submit into the URL. The first select in the URL is equal to the ID from the database of the selected person. The second isset is returning nothing so the second part is never being executed even after the select button is pressed. I think I have an error in the second isset code. Any help would be appreciated Kind Regards <? // Connect database mysql_connect("localhost","XXXX",""); mysql_select_db("YYY"); // If submitted, check the value of "select". If its not blank value, get the value and put it into $select. if(isset($select)&&$select!=""){ $select=$_GET['select']; } ?> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> "> PERSON : <select name="select"> <option value="">--- Select ---</option> <? // Get records from database (table "name_list"). $list=mysql_query("select * from name_list order by id asc"); // Show records by while loop. while($row_list=mysql_fetch_assoc($list)){ ?> <option value="<? echo $row_list['id']; ?>" <? if($row_list['id']==$select){ echo "selected"; } ?>><? echo $row_list['name']; ?></option> <? // End while loop. } ?> </select> <input type="submit" name="Submit" value="Select" /> </form> <hr> <p> <? // If you have selected from list box. if(isset($select)&&$select!="") { // Get records from database (table "name_list"). $result=mysql_query("select * from name_list where id='$select'"); $row=mysql_fetch_assoc($result); ?> Information about <strong><? echo $row['name']; ?></strong> FAMILY...</p> <p>........................................<br> ........................................<br> ........................................ <? // End if statement. } // Close database connection. mysql_close(); ?> </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/91125-possible-isset-coding-error/ Share on other sites More sharing options...
wildteen88 Posted February 14, 2008 Share Posted February 14, 2008 $select should be $_GET['select'] Your code is dependent on register_globals being enabled. register_globals has since been depreciated and is being removed in PHP6. The reason for this is because it can lead to security exploits within your code. Try to update your code to the newer superglobals Quote Link to comment https://forums.phpfreaks.com/topic/91125-possible-isset-coding-error/#findComment-467029 Share on other sites More sharing options...
aztec Posted February 14, 2008 Author Share Posted February 14, 2008 Hello Thanks for your response but if you look at the seventh line of the code it is set to $_Get, or are you referring to somewhere else in the code. I have take on board your comments about updating the code to superglobals once I get it working. Regards Quote Link to comment https://forums.phpfreaks.com/topic/91125-possible-isset-coding-error/#findComment-467056 Share on other sites More sharing options...
wildteen88 Posted February 14, 2008 Share Posted February 14, 2008 Tidied up your code a bit, try: <?php // Connect database mysql_connect("localhost","XXXX",""); mysql_select_db("YYY"); if(isset($_GET['select']) && !empty($_GET['select'])) { $select = $_GET['select']; // Get records from database (table "name_list"). $result = mysql_query("select * from name_list where id='$select'"); $row = mysql_fetch_assoc($result); $content = 'Information about <strong>' . $row['name'] . '</strong> FAMILY...</p> <p>........................................<br> ........................................<br> ........................................'; } else { $content = 'No Name Selected'; } ?> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <form id="form1" name="form1" method="get" action="<? echo $_SERVER['PHP_SELF']; ?> "> PERSON : <select name="select"> <option value="">--- Select ---</option> <?php // Get records from database (table "name_list"). $list = mysql_query("select * from name_list order by id asc"); // Show records by while loop. while($row_list = mysql_fetch_assoc($list)) { $opt = '<option value="' .$row_list['id'] . '"'; if($row_list['id'] == $select) { $opt .= ' selected="selected"'; } $opt .= '>' . $row_list['name'] . "</option>\n"; echo $opt; } ?> </select> <input type="submit" name="Submit" value="Select" /> </form> <hr> <p><?php echo $conent; ?></p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/91125-possible-isset-coding-error/#findComment-467062 Share on other sites More sharing options...
aztec Posted February 14, 2008 Author Share Posted February 14, 2008 Thanks Wildteen88 The code you gave produces exactly the same results as the original code. Regards Quote Link to comment https://forums.phpfreaks.com/topic/91125-possible-isset-coding-error/#findComment-467073 Share on other sites More sharing options...
aztec Posted February 14, 2008 Author Share Posted February 14, 2008 Hello I have tried to modify the new code provided by Widteen88 but to no avail, it still produces the same results that was described in my first post. Any help would be appreciated. Regards Quote Link to comment https://forums.phpfreaks.com/topic/91125-possible-isset-coding-error/#findComment-467117 Share on other sites More sharing options...
aztec Posted February 14, 2008 Author Share Posted February 14, 2008 Hello I have finally got wildtenn88's code to work. There are still some associated problems that I am working on. But for now I will mark this topic as solved. BUT THE SOLVED TAG AS DISAPPEARED Many thanks to wildteen88 for the help provided. Kind Regards Quote Link to comment https://forums.phpfreaks.com/topic/91125-possible-isset-coding-error/#findComment-467168 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.