Jump to content

Recommended Posts

Ok so I have kind of a mess on my hands that I almost have working.

 

I need to make it very clear that I really have no idea what I am doing, please keep any help you give me simple.

 

I have a page set up that returns the result of a search, it will return between one and five names. It needs to list names it returns in a form and when they select there answer and submit, it needs to email me the names and the answers.

 

Below is the awful mess I have come up with. It doesn't work and even if it did, I don't think it would properly send the name along with the answer in the email. It may at least give you an idea of what I am trying to accomplish.

 

Thank you for any help you can give me.

 

$data = mysql_query("SELECT * FROM Invites WHERE num = " . $_POST['moo'] . "")
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
?>
<form method="post" action="send.php">

<table cellspacing='16' cellpadding='0' border='0'  >
<?

print "
<tr>
	<td class="form_field" valign='top' align='right'> " . $info['name'] . " </td><td width='10'  aligh='right' valign='top'> <font size='2' color='#ff0000'>*</font> </td>

	<td class="form_text">
<select name="ATTEND"  class='form_text' >
<option value=''>- Select -</option>
<option  value="Will be attending"   > Will be attending
<option  value="Will not be attending"   >Will not be attending
</select>

	</td>
</tr>
";

?>
<tr><td colspan=3 align='center'><input type='submit' value='Submit'>    <input type='button' value='Cancel' onclick="location.href='/';"></td></tr>
</table>

</form>
<?

}
?> 

 

Just a little more background on what this is... I am getting married and I am trying to create a system for the RSVP's. The guest goes to the page rsvp.php and enters a code that was on the invite. That returns all the names connected to that code on the next page, confirm.php. I have everything working up until there. They should see all those names returned with an option of attending next to each one. They should then be able to click submit and it should send me an email with the names and what they selected.

 

Like I said any help you can give me I would appreciate it. I think this is more stressful then getting married.

Link to comment
https://forums.phpfreaks.com/topic/169572-retreive-mysql-data-then-email-a-form/
Share on other sites

Ok so I know this thing is still a mess but I am at least making progress... it basically works now. It returns all the guests in the group, allow you to select options for them and email me the option selected for the last user.

 

Does anyone know how I can get it to email me the options for all the  guests in the group? There may be up to 5 people in the group and it will only email me the option selected for the last one.

 

Below is the code I use to display the options for the guests. Below that is the code I use to send the email to me.

 

$data = mysql_query("SELECT * FROM Invites WHERE num = " . $_POST['moo'] . "")
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
?>
<form method="post" action="send.php">

<table cellspacing='16' cellpadding='0' border='0'  >

<?
print ("	
<tr>
<td class='form_field' valign='top' align='right'>" . $info['name'] . " </td>


	<td>
<select name='ATTEND'>
<option value=''>- Select -</option>
<option  value='" . $info['name'] . "  - Will be attending'   > Will be attending
<option  value='" . $info['name'] . "  - Will not be attending'   >Will not be attending
</select>

	</td>
</tr>
");

}
?> 

<tr><td colspan=3 align='center'><input type='submit' value='Submit'>    <input type='button' value='Cancel' onclick="location.href='/';"></td></tr>
</table>

</form>

 

<?php
  $message = $_REQUEST['ATTEND'] ;

  mail( "xxxx@xxxx", "[WEDDING RSVP]",
    $message, "From: xxxxxx@xxxxxxx.net" );
  header( "Location: http://wedding.xxxxxx.net/confirmed.html" );
?>

 

 

Thank you

Does your invites table have a primary (auto-incrementing) key? Or some key that is unique for each record, then modify 'id' to 'yourUniqueColumn'?

 

<select name="attend[<?php print $info['id']; ?>]" ..

 

$_POST['attend'] is now an array where the key represents the record

 

<option  value="1">Will be attending</option>

<option  value="0">Will not be attending</option>

 

foreach ($_POST['attend'] as $pk => $willornot) {

    if (true == $willornot) {

        //assuming attending BOOLEAN NOT NULL DEFAULT FALSE

        $query = 'UPDATE invites SET attending = TRUE WHERE yourUniqueColumn = ' . $pk;

        //..

    }

}

right now there is no unique number per guest. The only unique number is for a group of guests, however I can certainly add a number for each one in addition to the grouping.

 

I can kind of see where you are getting at with that script but I am in a little to far over my head to fully grasp it.

 

Thanks

Ok I got the first part of that done, they now have a unique id. Can you help me out with the second part of what you posted?

 

This is what I have now ... you will notice I had to modify what you gave me... for some reason stuff that seems like it should be working is throwing up errors, thats what I had to do to get it to work, no doubt it is from how I have butchered the rest of the code.

 

$data = mysql_query("SELECT * FROM Invites WHERE num = " . $_POST['moo'] . "")
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
?>
<form method="post" action="send.php">

<table cellspacing='16' cellpadding='0' border='0'  >

<?
print ("	
<tr>
<td class='form_field' valign='top' align='right'>" . $info['name'] . " </td>


	<td>
<select name='ATTEND" . $info['id'] . "'>
<option value=''>- Select -</option>
<option  value='" . $info['name'] . "  - Will be attending'   > Will be attending
<option  value='" . $info['name'] . "  - Will not be attending'   >Will not be attending
</select>

	</td>
</tr>
");

}
?> 

<tr><td colspan=3 align='center'><input type='submit' value='Submit'>    <input type='button' value='Cancel' onclick="location.href='/';"></td></tr>
</table>

</form>

It is now showing up correctly as ATTEND1, ATTEND10, ATTEND3, etc...

 

Thanks

<select name='ATTEND" . $info['id'] . "'>

 

Is not what I told you to use:

 

<select name='attend[" . $info['id'] . "]'>

 

This will create:

 

<select name='attend[1]'>

<select name='attend[10]'>

<select name='attend[3]'>

 

and can be accessed in php as:

 

$_POST['attend'][1];

$_POST['attend'][10];

$_POST['attend'][3];

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.