Jump to content

[SOLVED] Best Way to Pass Extra Data


hoopplaya4

Recommended Posts

Hi all,

 

I've got a PHP form that has a "Multiple Select" box.  Now, here's the thing, I want to pass multiple values through the form based on which options are selected.

 

For example, here's my current code:

 

<form>
<select multiple style="width:300px; height:120px;" name="name[]" id="name">
     <?php

      $sql = "SELECT usrID, usrFirst, usrLast, usrEmail";
      $sql .= " FROM tblUsers";
      $sql .= " WHERE usrActive = '1'";
      $sql .= " ORDER BY usrFirst";

	require("connection.php");

   		$rs=mysql_db_query($DBname,$sql,$link);

     	 while ($row=mysql_fetch_array($rs)){

          print("<option value='" . $row["usrID"] . "'>");
  		  print("" . $row["usrFirst"] . " " . $row["usrLast"] . "</option>\n");
  		  } ?>
</select>
</form>

 

As you can see, the "value" that's being passed is usrID.  However, I'd also like to pass the field usrEmail (from my DB) as well.  What is the best way to achieve this?  Obviously, I don't want to make a separate "multiple select" box.  Would I have to create a "hidden field" or something?  Maybe this is something easy, and I'm overthinking.

 

Thanks in advance!

Link to comment
Share on other sites

Looks like you're not passing anything because your form does not have an action or method.  How do you want to decide what value of usrEmail to pass through?  Do you want to wait to see what option the user picks from the usrID SELECT menu first?

 

I think I'm just a little confused as to exactly what you're trying to accomplish...

 

 

 

Link to comment
Share on other sites

Thanks for the replies guys.  I'm sorry I was not specific enough:

 

@farewei: I know I need to user $row['usrEmail '], my question is where would I put it?

 

@Maq: First, I know I don't have the action (sorry for leaving it out, wanted to cut down the form). 

 

How do you want to decide what value of usrEmail to pass through?  Do you want to wait to see what option the user picks from the usrID SELECT menu first?

 

The answer to your second question is "Yes."  Every user that is selected from the "multiple select box" has a usrID and a usrEmail. Right now, the form ONLY passes the usrID of the persons selected.  However, I also want to pass the usrEmail of that selected person (option) as well.  So, I'd like to know how I can go about passing both the usrID (which is already being passed) AND usrEmail.

 

Should I separate it with a comma?

 

<?php print("<option value='" . $row["usrID"] . "," . $row["usrEmail"] . "'>");

And then split it up later?  Or is there just an easier way to pass the data as two separate fields?

 

Please let me know if I need to be more specific.

Link to comment
Share on other sites

you need a method= (get or post)

 

you can have all of $sql in one quote set

 

I would also personally use:

echo "<option value='$row[usrID]'>$row[usrFirst] $row[usrLast]</option>";

 

On the reception page you can do a bcc by doing a for each if multiple options are selected then query the e-mail address, and send it to the recipient.

Link to comment
Share on other sites

On the reception page you can do a bcc by doing a for each if multiple options are selected then query the e-mail address, and send it to the recipient.

 

Ok, thanks.  So, let's say I pass an array of three usrIDs (32, 35, and 36). (On the next page, it'd obviously be $_POST["name"]).

 

So, on the next page, what would my MySQL SELECT query look like to grab all email addresses from the array? 

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.