shag Posted October 4, 2010 Share Posted October 4, 2010 trying to be able to store client information in mysql db for reference later in an admin area. The code I have so far allows me to list the client names, but once I "select" the name I want it to show the rest of the database information stored for that user (email, height, weight, phone number, etc...) which it currently is not doing. Any and all help will be greatly appreciated, tired of struggling through this blindly. <? // Connect database mysql_connect("localhost","",""); mysql_select_db("mydb"); if(isset($select)&&$select!=""){ $select=$_GET['select']; } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <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; ?> "> Client Name : <select name="select"> <option value="">--- Select ---</option> <? // Get records from database (table "users"). $list=mysql_query("select * from users order by id asc"); 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> <? } ?> </select> <input type="submit" name="Submit" value="Select" /> </form> <hr> <p> <? if(isset($select)&&$select!=""){ // Get records from database (table "users"). $result=mysql_query("select * from users where id='$select'"); $row=mysql_fetch_assoc($result); ?> Information about <strong><? echo $row['name']; ?></strong> client...</p> <p><? echo $row['email']; ?><br> ........................................<br> ........................................ <? // End if statement. } // Close database connection. mysql_close(); ?> </p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/215155-dynamic-dropwdown-box/ Share on other sites More sharing options...
BlueSkyIS Posted October 4, 2010 Share Posted October 4, 2010 this is probably never true, and so always fails the if() if(isset($select)&&$select!=""){ Link to comment https://forums.phpfreaks.com/topic/215155-dynamic-dropwdown-box/#findComment-1119083 Share on other sites More sharing options...
Pikachu2000 Posted October 4, 2010 Share Posted October 4, 2010 Unless that script relies on register_globals = On (which is a bad idea), or there's more code than you've posted that goes with the script, $select is undefined. Link to comment https://forums.phpfreaks.com/topic/215155-dynamic-dropwdown-box/#findComment-1119102 Share on other sites More sharing options...
shag Posted October 5, 2010 Author Share Posted October 5, 2010 Unless that script relies on register_globals = On (which is a bad idea), or there's more code than you've posted that goes with the script, $select is undefined. This is the entire code, it shows the client names perfectly fine in the dropdown box, but it wont let me display all of the client info after hitting "select" that is the part i am stuck on if that makes sense. Link to comment https://forums.phpfreaks.com/topic/215155-dynamic-dropwdown-box/#findComment-1119127 Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2010 Share Posted October 5, 2010 this part doesn't make sense. $select will never be set using this logic: if(isset($select)&&$select!=""){ $select=$_GET['select']; } Link to comment https://forums.phpfreaks.com/topic/215155-dynamic-dropwdown-box/#findComment-1119128 Share on other sites More sharing options...
shag Posted October 5, 2010 Author Share Posted October 5, 2010 this part doesn't make sense. $select will never be set using this logic: if(isset($select)&&$select!=""){ $select=$_GET['select']; } isn't select set from the html form?? Link to comment https://forums.phpfreaks.com/topic/215155-dynamic-dropwdown-box/#findComment-1119132 Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2010 Share Posted October 5, 2010 isn't select set from the html form?? no. not unless you have register_globals = On, which you probably don't. in that case, the form value is $_GET['select']; the code says "if $select is set, then set $select". Since $select isn't set, $select will never be set. you probably want something more like $select = ''; if (isset($_GET['select'])) { $select = $_GET['select']; } Link to comment https://forums.phpfreaks.com/topic/215155-dynamic-dropwdown-box/#findComment-1119133 Share on other sites More sharing options...
shag Posted October 5, 2010 Author Share Posted October 5, 2010 isn't select set from the html form?? no. not unless you have register_globals = On, which you probably don't. in that case, the form value is $_GET['select']; the code says "if $select is set, then set $select". Since $select isn't set, $select will never be set. you probably want something more like $select = ''; if (isset($_GET['select'])) { $select = $_GET['select']; } DOH can't believe it was so simple, everything is working perfectly now! Greatly appreciate your assistance Link to comment https://forums.phpfreaks.com/topic/215155-dynamic-dropwdown-box/#findComment-1119136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.