PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 14th, 2007, 04:32 PM
leev3 leev3 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 32 leev3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 9 sec
Reputation Power: 12
Drop down list

I have found several examples of how to populate a drop down list from a MySql DB, but the light bulb is not coming on when it comes to having the drop down list items do something. I am trying to populate a query result from the drop down list selection, here is my dropdown code:
mysql_select_db("glen_rest", $con);


$query = mysql_query("SELECT name FROM emer_rest");
echo "<form action=result.php method=POST><select name=users>";
while ($row = mysql_fetch_array($query))
{
$user = $row["name"];
echo "<option value=$user>$user</option>";
}
echo "</select>";
?>

I tried creating a result.php and $_Post[user] to populate a query, but no luck. What am I not understanding?

Reply With Quote
  #2  
Old March 15th, 2007, 03:08 AM
Humanetainit's Avatar
Humanetainit Humanetainit is offline
Beyond help
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: The Netherlands
Posts: 222 Humanetainit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 32 m 30 sec
Reputation Power: 12
"user" as in $_Post[user] is a constant, you want the variable: $_POST['user'] (with quotes).

And always use uppercase for globals like _POST
__________________
One World... Humanetainit | Program secure

Reply With Quote
  #3  
Old March 15th, 2007, 08:09 AM
leev3 leev3 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 32 leev3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 9 sec
Reputation Power: 12
Thanks, $_POST['user'] is the actual syntax in my script, but it doesn't populate the result.php file. Is the result.php strictly an internal function of this page, and if so how do I make it jump the the next page to populate all information. This one only has 4 elements now, but when I pick one I want it to go to "xxxxx.php" to do this:

<?
$con = mysql_connect("*****","*****","*****");
mysql_select_db("glen_rest", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");

// Get post info from dba_search_php form


$sql = "SELECT * FROM emer_rest where '$_POST['name']' ";
// the third parameter of execute() is optional
$result = $nav->execute($sql, $db, "mysql");
$pow = mysql_fetch_assoc($result);

?>

<html> blah
echo " database info based on name query"

blah </html>

Reply With Quote
  #4  
Old March 15th, 2007, 08:17 AM
Humanetainit's Avatar
Humanetainit Humanetainit is offline
Beyond help
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: The Netherlands
Posts: 222 Humanetainit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 32 m 30 sec
Reputation Power: 12
Try
$sql = "SELECT * FROM emer_rest WHERE '" . $_POST['name'] . "'";

Reply With Quote
  #5  
Old March 15th, 2007, 08:24 AM
leev3 leev3 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 32 leev3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 9 sec
Reputation Power: 12
Still does nothing except show what I picked in the drop down menu

Reply With Quote
  #6  
Old March 15th, 2007, 08:34 AM
Humanetainit's Avatar
Humanetainit Humanetainit is offline
Beyond help
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: The Netherlands
Posts: 222 Humanetainit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 32 m 30 sec
Reputation Power: 12
I expect you have more code than this? Do you need to instantiate the class?

Reply With Quote
  #7  
Old March 15th, 2007, 09:03 AM
leev3 leev3 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 32 leev3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 9 sec
Reputation Power: 12
The original post is the complete code for emer_rest_look.php, I created result.php that looks like the following: but I am thinking the way emer_rest_look.php is set up it never jumps to a seperate script named result.php.

mysql_select_db("glen_rest", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");

// Get post info from emer_rest_look form


$sql = "SELECT * FROM emer_rest where '" . $_POST['name']. "'";
// the third parameter of execute() is optional
$result = $nav->execute($sql, $db, "mysql");
$pow = mysql_fetch_assoc($result);

?>

<html>
<head>
<style type="text/css">
table.mid {width:90%; text-align: center; font-variant:small-caps; color:F8F8FF}
td.mid {text-align: center; font-variant: small-caps; font-size: 20pt; color: black; padding-bottom: 1cm}
table.data {width:90%; text-align: left; font-variant:small-caps; font-size:16; font-family: times}
body {background-color: F8F8FF}
td.name {font-variant: small-caps; font-size: 18pt; color: black;}
td.sub {text-align: center; font-size:18; color:red}
</style>
<script type="text/javascript">
<!--
function ExpandWindowTrigger(){
if (document.all || document.layers) {
self.moveTo(0,0); self.resizeTo(screen.availWidth,screen.availHeight )
}
}
//-->
</script>
</head>
<body onload="javascript:ExpandWindowTrigger();">
<?

echo "<center>";
echo "<table class='mid'>";
echo "<tr>";
echo "<td class='mid'><b>Auto Attendant Emergency Restoration Information </b></td>";
echo "</tr>";
echo "</table>";
echo "<table class='data'>";
echo "<tr>";
echo "<td colspan='3' class='sub'><b>Entry Submitted</b></td>";
echo "</tr>";
echo "<tr>";
echo "<tr>";
echo "<tr>";
echo "<td class='name' colspan='3' ><b>Name: <b/>". $pow['name'] ."<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Address: </b>". $pow['address'] ."<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>City: </b>". $pow['city'] ."</td>" . "<td><b>State: </b>" .$pow['state'] ."<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Platform: </b>". $pow['platform'] ."<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;<br/></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3' align='center'><b>IN THE EVENT OF A SYSTEM OUTAGE THE FOLOWING NUMBERS WILL BE ROUTED TO:</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3' align='center'><b>" . $pow[routingnum] ."</b><br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;<br/></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>1.</b> ". $pow['mainnum'] ."<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>2.</b> ". $pow['num2'] ."<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>3.</b> ". $pow['num3'] ."<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>4.</b> ". $pow['num4'] ."<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>5.</b> ". $pow['num5'] ."<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Contact:</b> ". $pow['contact'] . "<td><b> Contact Number: </b>" .$pow['contactnum'] . "<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>DBA: </b>". $pow['dba'] . "</td>" . "<td><b> DBA Number: </b>" . $pow['dbanum'] . "<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>CSA: </b>". $pow['csa'] . "</td>" . "<td><b> CSA Number: </b>" . $pow['csanum'] . "<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Assigner: </b>". $pow['assign'] . "</td>" . "<td><b> Assigner Number: </b>" . $pow['assignnum'] . "<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Local Supervisor: </b>". $pow['locsup'] . "</td>" . "<td><b> Local Supervisor Number: </b>" . $pow['locsupnum'] . "<br /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Area Director: </b>". $pow['dir'] . "</td>" . "<td><b> Area Director Number: </b>" . $pow['dirnum'] . "<br /></td>";
echo "</tr>";
echo "</table>";
echo "</center>";
echo "<center>";
echo "<table>";
echo "<tr>";
echo "<td>.<FORM METHOD='LINK' ACTION='http://localhost:8080/Work/emergency_rest.php'>" . "<INPUT TYPE='submit' VALUE='New Entry' size='6'>" . "</form></td>";
echo "<TD>&nbsp;<br><INPUT TYPE=BUTTON onclick='window.print();' VALUE='Print Entry' size='6'></TD>";
echo "<td>.<FORM METHOD='LINK' ACTION='(URL address blocked: See forum rules)=2'>" . "<INPUT TYPE='submit' VALUE=' Exit ' size='10'>" . "</form></td>";
echo "</tr>";


echo "</table>";
echo "</center>";
?>

</body></html>
</TR>
</TABLE>

Reply With Quote
  #8  
Old March 15th, 2007, 09:26 AM
Humanetainit's Avatar
Humanetainit Humanetainit is offline
Beyond help
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: The Netherlands
Posts: 222 Humanetainit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 32 m 30 sec
Reputation Power: 12
I won't check the entire code, but $result = $nav->execute($sql, $db, "mysql"); cannot work because it depends on a class called nav.

replace it with:
$result = mysql_query($sql) or die($query);
and dee what happens.

Reply With Quote
  #9  
Old March 15th, 2007, 12:10 PM
alicats12345 alicats12345 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: Mars
Posts: 67 alicats12345 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 36 m 52 sec
Reputation Power: 0
Quote:
Originally Posted by Humanetainit
I won't check the entire code, but $result = $nav->execute($sql, $db, "mysql"); cannot work because it depends on a class called nav.

replace it with:
$result = mysql_query($sql) or die($query);
and dee what happens.

or try using:
var_dump($pow);

Reply With Quote
  #10  
Old March 15th, 2007, 12:11 PM
leev3 leev3 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 32 leev3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 9 sec
Reputation Power: 12
I had no "submit", duh. Is there a way to make it submit when the drop down element is selected, without a separate button?

Reply With Quote
  #11  
Old March 15th, 2007, 12:18 PM
alicats12345 alicats12345 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: Mars
Posts: 67 alicats12345 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 36 m 52 sec
Reputation Power: 0
Quote:
Originally Posted by leev3
I had no "submit", duh. Is there a way to make it submit when the drop down element is selected, without a separate button?

Code:
<form name="form1">
<select onChange="javascript:submit_form('form1');">
//your select items here
</select>
</form>

<script>
<!--
function submit_form(formname)
{
  document.formname.form.submit();
}
-->
</script>

try that code

Reply With Quote
  #12  
Old March 15th, 2007, 12:20 PM
leev3 leev3 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 32 leev3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 9 sec
Reputation Power: 12
ah well the submit didn't work, it got me to the right output form, but my query results didn't populate the fields, like I thought. I'll have to work on my query. Thanks all

Reply With Quote
  #13  
Old March 15th, 2007, 02:13 PM
leev3 leev3 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 32 leev3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 9 sec
Reputation Power: 12
Alright back to the beginning I've confused myself:


$query = mysql_query("SELECT name FROM emer_rest");
echo "<form action=result.php method=POST><select name=users>";
while ($row = mysql_fetch_array($query))
{
$user = $row["name"];
echo "<option value=$user>$user</option>";
}
echo "</select>";
?>

The post value is $user correct? so in result.php my query should look like :

$sql = "SELECT * FROM emer_rest where name = '" . $_POST['$user']. "'";

Sorry for dragging this out

Reply With Quote
  #14  
Old March 15th, 2007, 03:17 PM
leev3 leev3 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 32 leev3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 9 sec
Reputation Power: 12
looking at I'm wondering am I even passing a variable?

Reply With Quote
  #15  
Old March 15th, 2007, 03:52 PM
leev3 leev3 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 32 leev3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 26 m 9 sec
Reputation Power: 12
finally got it, in 1st php :
$query = mysql_query("SELECT name FROM emer_rest");
echo "<form action=result.php method=POST><select name='name'>";
while ($row = mysql_fetch_array($query))
{
$user = $row['name'];
echo "<option value='$user'>$user</option>";
}
echo "</select>";
echo "<input type='hidden' name='$user' value='submitted' />";
?>
<html><head></head>
<input type="submit" value="Submit" size="6" />
</html>

In result.php:

$sql = "SELECT * FROM emer_rest WHERE name='" .$_POST['name'] ."'";
$result = mysql_query($sql) ;
$pow = mysql_fetch_assoc($result);

Thanks for ALL the help, now I'll try to incorporate the javascript to pick

Reply With Quote
  #16  
Old March 16th, 2007, 03:07 AM
Humanetainit's Avatar
Humanetainit Humanetainit is offline
Beyond help
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: The Netherlands
Posts: 222 Humanetainit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 32 m 30 sec
Reputation Power: 12
I use this to submit:

<select name="name" onchange="javascript:form.submit();">

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Drop down list


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap