Jump to content

PHP Help with Select Form


hank9481

Recommended Posts

Hey guys,

 

I'm very much a novice when it comes to PHP, but I'm learning it and trying to implement it on my site. I've run into an issue that I hoping someone can help me to fix rather quickly.

 

I have a submission form which I am attempting to use. At the top of the page, you will notice the dropdown which I have managed to successfully populate with data from my SQL table. However, I have two problems.

 

First, I would like for the dropdown population to only represent the players in the team dropdown lower on the page. For example, if I select Boston from the teams dropdown, I only want players on Boston to appear in the top dropdown. I also am planning to move the top dropdown below the others but have yet to do so.

 

Second, I have the form setup to email the results to my server email using the recipient command; however, it is only submitting part of the information. Here is a copy of the line of code:

 

print "<select name=winter id=player class=list style='width:500px'>";

  $result = mysql_query("SELECT P.last_name, P.first_name, P.position, T.name FROM players P, teams T WHERE P.experience=0 AND T.team_id=P.organization_id ORDER BY organization_id ASC, last_name ASC") or die(mysql_error());;

  while ($row = @mysql_fetch_array($result,MYSQL_ASSOC)) {

print "<option value=".$row{'last_name'}.", ".$row{'first_name'}.", ".$row{'position'}."-- ".$row{'name'}.">".$row{'last_name'}.", ".$row{'first_name'}.", ".$row{'position'}."-- ".$row{'name'}."</option>";

  }

            print "</select>";

For whatever reason, the only thing getting to me via email is the last_name. I assume it is some form of syntax error, but I cannot figure out why I can't receive the rest of the information such as first_name, position, and team.

 

Any help would be appreciated!

 

 

Link to comment
https://forums.phpfreaks.com/topic/103169-php-help-with-select-form/
Share on other sites

For the first part, you would need a JavaScript code to achieve this.  Try looking at the following:

 

http://www.weberdev.com/get_example-4578.html

 

If that doesn't help, try the JavaScript forums on this very board!  ;)

 

If you don't want to use JavaScript, I've done something similar in the past where the first option box is on one page.  Once that is submitted, it takes you to a second page.  The second page would do something like this:

 

$teamLimit=$_POST["teamSelected"];

//use this query in the code for your option box
$result=mysql_query("SELECT whatever,values,you,want FROM tablename ORDER BY whatever WHERE teamID = (' . $teamLimit . ')");

 

As for the second part, I'm not too great with that sort of syntax myself, as I am still learning.  I wonder if this may help:

 

When I had an option box for which i needed $row[FirstName] and $row[LastName], I found that it was ignoring the second item when I used commas.  The solution was:

 

echo"<option value='$row[iD]'>$row[FirstName] $row[LastName]</option>";

...so a space seperating the strings, no commas.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.