Jump to content

snailguy

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

snailguy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks! After a nights sleep and a consult with a friend, I figured it out over breakfast. Here is my solution: if (isset($_POST['volunteer'])) {$volunteer = $_POST['volunteer'];} else {$volunteer = '';} Jeff
  2. You might try adding: $result = mysql_query($sql) OR DIE("Your query failed: " .mysql_errno() . " " . mysql_error()); This way, if there is a problem with your query, you should see an error message that could help troubleshoot the problem. Also, have you tried the query directly on the DB, like through phpmyadmin? Also, try modifying your query to: $sql = "SELECT * FROM logins WHERE username = '$_POST['username']' AND password = '$_POST['password']'"; Alternatively, you might try: $username = $_POST['username']; $password = $_POST['password']; $sql = "SELECT * FROM logins WHERE username = '$username' AND password = '$password'";
  3. This code: echo "<p>ID's of trained volunteers:</p> <p>"; echo "volunteer array: "; print_r($_POST[volunteer]); echo "<br>trained = ".$trained."<br>"; $j = $trained-1; for ($i=0;$i<=$j;$i++) { echo "Volunteer #".$i.": ".$volunteer[$i]."<br>"; } echo "</p>"; Results in the following display: ID's of trained volunteers: volunteer array: Array ( [0] => 1 [1] => 12 [2] => 2 [3] => 11 [4] => 3 ) trained = 5 Volunteer #0: Volunteer #1: Volunteer #2: Volunteer #3: Volunteer #4:
  4. [volunteer] => Array ( [0] => 1 [1] => 12 [2] => 2 [3] => 11 [4] => 3 That's good news. The data is arriving at the second page intact. Perhaps a problem with the POST to PHP variable conversion?
  5. I have a working php page with an hmtl form where five names can be entered into five different text boxes. Like so: echo "<form name=\"formname\" action=\"form_review.php\" method=\"post\" enctype=\"multipart/form-data\"> <p>"; for ($i=0;$i<=4;$i++) { echo "First Name<input type=\"text\" name=\"firstnameT[".$i."]\" value=\"".($firstnameT[$i])."\" maxlength=\"15\"> "; echo "Last Name<input type=\"text\" name=\"lastnameT[".$i."]\" value=\"".($lastnameT[$i])."\" maxlength=\"15\"><br>"; } On the page form_review.php: //Convert POST variables to PHP if (isset($_POST['firstnameT[]'])) {$firstnameT[]=$_POST['firstnameT[]'];} else { $firstnameT[] = '';} if (isset($_POST['lastnameT[]'])) {$lastnameT[]=$_POST['lastnameT[]'];} else { $lastnameT[] = '';} //Display the submitted data for ($i=0;$i<=4;$i++) { echo "<p> $firstnameT[$i]." ".$lastnameT[$i]."<br>"; } echo "</p>"; So the problem I'm having is that I want to use <select><option> instead of <input type="text"> so users can select five names from five separate pull-down selectors, and display the selections on the next page, like so: $query = "SELECT users.user_id, users.first_name, users.last_name, users.city FROM users"; $result = mysql_query($query) OR DIE("Your query failed: " .mysql_errno() . " " . mysql_error()); echo "<form name=\"formname\" action=\"form_review.php\" method=\"post\" enctype=\"multipart/form-data\"> for ($i=0;$i<=4;$i++) { echo "<p><select name=\"volunteer[".$i."]\">"; echo "<option value=\"\">Choose a Volunteer</option>"; while($row = mysql_fetch_array($result)) { $vol_id = $row['user_id']; $first_name = $row['first_name']; $last_name = $row['last_name']; $city = $row['city']; echo "<option value=\"".$vol_id."\">".$last_name.", ".$first_name." (".$city.")</option>"; } //close WHILE echo "</select></p>"; mysql_data_seek($result,0); //reset the pointer in the result array for each FOR loop } //close FOR The above section of code works fine = the form displays properly, each pulldown has the full list of users, etc. I have even confirmed that the underlying html has unique values for each pulldown choice, and that each pulldown choice has a unique name like: <select name=volunteer[0]><option value="1">Last, First (city)</option><option value='2'>Last2, First2 (City2)</option></select> <select name=volunteer[1]><option value="1">Last, First (city)</option><option value='2'>Last2, First2 (City2)</option></select> But when I submit to review page, I can't get the selected names to display. Here's the pertinent code from "form_review.php": if (isset($_POST['volunteer[]'])) {$volunteer[]=$_POST['volunteer[]'];} else { $volunteer[] = '';} for ($i=0;$i<=4;$i++) { echo "Volunteer #".$i.": ".$volunteer[$i]."<br>"; } echo "</p>"; Unfortunately, nothing appears. I'm expecting to get the selected option value following "Volunteer #:", but I'm not. I've counted rows in the array passed to the second page and I consistently get numrows=1, and the value in that resulting array is obviously "". After five hours of trying a mind-numbing number of variations, I can't wrap my head around the solution. Is there something special/different about passing arrays generated from <select><option> versus arrays generated from <input type=text>??? TIA! snailguy
×
×
  • 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.