Jump to content

dynamic dropwdown box


shag

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.