Jump to content

php form


randyw

Recommended Posts

i have a php from collects the data from an array and places it in a database

 

the form has the different sections

shows_Selected

<input type="checkbox" name="shows_Selected[]" value="January 10, 2010  Seaport World Trade Center, Boston, MA" tabindex="5">

additional_Info

<input type="checkbox" name="additional_Info[]" value="Yes, I'd like to receive info on wedding related specials via "snail" mail." checked tabindex="150">

further_information

<input type="checkbox" name="further_information[]" value="Alterations">

 

form proccess

<?php

 

      include_once("include/dbc.php");

 

      // Verify that all form elements are completed

 

 

if (empty($_POST['first_name'])){

  //die ("ERROR: Please add your First Name..");

header("Location: form.php?msg=ERROR: Please add your First Name..");

exit();

}

if (empty($_POST['last_name'])){

//die ("ERROR: Please add your Last Name..");

header("Location: form.php?msg=ERROR: Please add your Last Name..");

exit();

 

 

}

 

if (empty($_POST['email_address'])){

//die ("ERROR: Please add your Email..");

header("Location: form.php?msg=ERROR: Please add your Email..");

exit();

 

 

}

 

if (empty($_POST['mailling_address'])){

//die ("ERROR: Please add your Address..");

header("Location: form.php?msg=ERROR: Please add your Address..");

exit();

 

 

}

 

 

if (empty($_POST['city'])){

//die ("ERROR: Please add your City..");

header("Location: form.php?msg=ERROR: Please add your City..");

exit();

 

 

}

 

 

if (empty($_POST['zip'])){

//die ("ERROR: Please add your City..");

header("Location: form.php?msg=ERROR: Please add your City..");

exit();

 

 

}

 

if (empty($_POST['home_phone'])){

//die ("ERROR: Please add your Home Phone..");

header("Location: form.php?msg=ERROR: Please add your Home Phone..");

exit();

 

 

}

 

if (empty($_POST['work_phone'])){

//die ("ERROR: Please add your WorkPhone..");

header("Location: form.php?msg=ERROR: Please add your WorkPhone..");

exit();

 

 

}

else{

 

$media_array = $_POST['shows_Selected'];

foreach ($media_array as $one_media) {

$source .= $one_media."<br>";

}

$shows_Selected = substr($source, 0, -4);

{

 

// Now process the Addition Information array from POST

$addlInfo_array = $_POST['additional_Info'];

foreach ($addlInfo_array as $one_addl) {

$addlInfo .= $one_addl."<br>";

}

$additional_Info = substr($addlInfo, 0, -4);

{

 

// Now process the Addition Information array from POST

$furtherInfo_array = $_POST['further_information'];

foreach ($furtherInfo_array as $one_futher) {

$furtherInfo .= $one_further."<br>";

}

$further_information = substr($furtherInfo, 0, -4);

{

 

// update data in mysql database

$sql = "INSERT INTO newportweddingExpoForm

(shows_Selected, additional_Info, further_information, first_name, last_name, Role, email_address, home_phone, work_phone, city, state, zip, mailling_address, apt_number, wedding_month, wedding_day, wedding_year, Wedding_Tentative, wedding_Region, wedding_city, wedding_state, budget, find_aboutUs)VALUES('$shows_Selected', '$additional_Info', '$further_information', '$first_name', '$last_name', '$role', '$email_address', '$home_phone', '$work_phone', '$city', '$state', '$zip', '$mailling_address', '$apt_number', '$wedding_month', '$wedding_day', '$wedding_year', '$Wedding_Tentative', '$wedding_Region', '$wedding_city', '$wedding_state', '$budget', '$find_aboutUs')";

$result = @mysql_query($sql);

}

if($result){

 

//die ("Your form information has been successfully sent..");

 

header("Location: form.php?msg=Your form information has been successfully sent..");

exit();

 

}

else {

//die ("Iam sorry there was a problem, duplicate form name allready sent..");

header("Location: form.php?msg=Iam sorry there was a problem, duplicate form name  allready sent..");

exit();

}

 

mysql_close();

?>

  <?php

}

?>

  <?php

}

?>

  <?php

}

?>

this works great

 

however if the dont check any of the boxes i get this error

 

Warning: Invalid argument supplied for foreach() in /home/va010021/public_html/newportweddingExpo/form_procces.php on line 73

Link to comment
Share on other sites

there are multiple foreach statements. which line is line 73. also wrap your code in code tags next time, especially if you have that much.

 

also, the following area of code


if (empty($_POST['work_phone'])){
   //die ("ERROR: Please add your WorkPhone..");
         header("Location: form.php?msg=ERROR: Please add your WorkPhone..");
         exit();


}
else{

 

might not be doing what you think its doing. That else statement is only connected to the if statement above it, and is not connected to any other if statement in that code. If you want it to be connected to the rest, you have to use else if statements. This won't make a huge difference, or really any difference the way your code is now, but may cause some problems in the future.

Link to comment
Share on other sites

i have a php from collects the data from an array and places it in a database

 

the form has the different sections

shows_Selected

<input type="checkbox" name="shows_Selected[]" value="January 10, 2010  Seaport World Trade Center, Boston, MA" tabindex="5">

additional_Info

<input type="checkbox" name="additional_Info[]" value="Yes, I'd like to receive info on wedding related specials via "snail" mail." checked tabindex="150">

further_information

<input type="checkbox" name="further_information[]" value="Alterations">

 

form proccess

<?php

 

      include_once("include/dbc.php");

 

      // Verify that all form elements are completed

 

 

if (empty($_POST['first_name'])){

  //die ("ERROR: Please add your First Name..");

header("Location: form.php?msg=ERROR: Please add your First Name..");

exit();

}

if (empty($_POST['last_name'])){

//die ("ERROR: Please add your Last Name..");

header("Location: form.php?msg=ERROR: Please add your Last Name..");

exit();

 

 

}

 

if (empty($_POST['email_address'])){

//die ("ERROR: Please add your Email..");

header("Location: form.php?msg=ERROR: Please add your Email..");

exit();

 

 

}

 

if (empty($_POST['mailling_address'])){

//die ("ERROR: Please add your Address..");

header("Location: form.php?msg=ERROR: Please add your Address..");

exit();

 

 

}

 

 

if (empty($_POST['city'])){

//die ("ERROR: Please add your City..");

header("Location: form.php?msg=ERROR: Please add your City..");

exit();

 

 

}

 

 

if (empty($_POST['zip'])){

//die ("ERROR: Please add your City..");

header("Location: form.php?msg=ERROR: Please add your City..");

exit();

 

 

}

 

if (empty($_POST['home_phone'])){

//die ("ERROR: Please add your Home Phone..");

header("Location: form.php?msg=ERROR: Please add your Home Phone..");

exit();

 

 

}

 

if (empty($_POST['work_phone'])){

//die ("ERROR: Please add your WorkPhone..");

header("Location: form.php?msg=ERROR: Please add your WorkPhone..");

exit();

 

 

}

else{

 

this is line 73

 

$media_array = $_POST['shows_Selected'];

foreach ($media_array as $one_media) {

$source .= $one_media."<br>";

}

$shows_Selected = substr($source, 0, -4);

{

 

// Now process the Addition Information array from POST

$addlInfo_array = $_POST['additional_Info'];

foreach ($addlInfo_array as $one_addl) {

$addlInfo .= $one_addl."<br>";

}

$additional_Info = substr($addlInfo, 0, -4);

{

 

// Now process the Addition Information array from POST

$furtherInfo_array = $_POST['further_information'];

foreach ($furtherInfo_array as $one_futher) {

$furtherInfo .= $one_further."<br>";

}

$further_information = substr($furtherInfo, 0, -4);

{

 

// update data in mysql database

$sql = "INSERT INTO newportweddingExpoForm

(shows_Selected, additional_Info, further_information, first_name, last_name, Role, email_address, home_phone, work_phone, city, state, zip, mailling_address, apt_number, wedding_month, wedding_day, wedding_year, Wedding_Tentative, wedding_Region, wedding_city, wedding_state, budget, find_aboutUs)VALUES('$shows_Selected', '$additional_Info', '$further_information', '$first_name', '$last_name', '$role', '$email_address', '$home_phone', '$work_phone', '$city', '$state', '$zip', '$mailling_address', '$apt_number', '$wedding_month', '$wedding_day', '$wedding_year', '$Wedding_Tentative', '$wedding_Region', '$wedding_city', '$wedding_state', '$budget', '$find_aboutUs')";

$result = @mysql_query($sql);

}

if($result){

 

//die ("Your form information has been successfully sent..");

 

header("Location: form.php?msg=Your form information has been successfully sent..");

exit();

 

}

else {

//die ("Iam sorry there was a problem, duplicate form name allready sent..");

header("Location: form.php?msg=Iam sorry there was a problem, duplicate form name  allready sent..");

exit();

}

 

mysql_close();

?>

  <?php

}

?>

  <?php

}

?>

  <?php

}

?>

this works great

 

however if the dont check any of the boxes i get this error

 

Warning: Invalid argument supplied for foreach() in /home/va010021/public_html/newportweddingExpo/form_procces.php on line 73

Link to comment
Share on other sites

... thats not how you wrap code in code tags but whatever...

 

so line 73 is an empty line? I still don't quite understand. Is like 73 the one below where you indicated?

 

ill assume that line 73 is the foreach two lines below where you indicated.

 

do a print_r on the $media_array variable and see what you get

Link to comment
Share on other sites

there is a function called print_r().

 

print_r($media_array);

 

what happens when you run that

 

i got this

Warning: Invalid argument supplied for foreach() in /home/va010021/public_html/newportweddingExpo/form_procces.php on line 73

 

Warning: Invalid argument supplied for foreach() in /home/va010021/public_html/newportweddingExpo/form_procces.php on line 82

 

Warning: Invalid argument supplied for foreach() in /home/va010021/public_html/newportweddingExpo/form_procces.php on line 90

 

Warning: Cannot modify header information - headers already sent by (output started at /home/va010021/public_html/newportweddingExpo/form_procces.php:73) in /home/va010021/public_html/newportweddingExpo/form_procces.php on line 111

Link to comment
Share on other sites

none of those errors have anything to do with the print_r function. it is clear that none of the foreach statements have an array as their supplied argument. It appears that the post data is not an array.

 

post the part of the form that shows the checkboxes. if you only have 1 check box.. then it won't be an array.

Link to comment
Share on other sites

none of those errors have anything to do with the print_r function. it is clear that none of the foreach statements have an array as their supplied argument. It appears that the post data is not an array.

 

post the part of the form that shows the checkboxes. if you only have 1 check box.. then it won't be an array.

<table width="100%" border="0" cellspacing="1" id="table5">

                      <tr>

                        <td colspan="2" align=""><strong>

                          <input type="hidden" name="VTI-GROUP" value="0">

                          <h1>Select the show(s) of your choice:</h1>

</strong></td>

                      </tr>

                      <tr>

                        <td width="41"></td>

                        <td width="565"></td>

                      </tr>

                      <tr>

                        <td colspan="2"><h3> <strong>Fall Shows</strong></h3></td>

                        </tr>

                      <tr>

                        <td> <font color="#666666">      </font></td>

                        <td width="565"><font color="#666666">

                         

                          <input type="checkbox" name="shows_Selected[]" value="October 25, 2009  Westin Boston Waterfront, Boston, MA" tabindex="1">

      October 25, 2009 – Westin Boston Waterfront, Boston, MA </font></td>

                      </tr>

                      <tr>

                        <td colspan="2"><font color="#666666"> </font><font color="#666666">

                          <h3><strong>Winter Shows</strong></h3>

                        </font></td>

                        </tr>

                      <tr>

                        <td height="166"> <font color="#666666">

                          <!--input type="checkbox" name="Event17" value="Yes" tabindex="35">

 

 

 

February 22, 2009 - Burlington Marriott, MA-->

                        </font></td>

                        <td><font color="#666666">

                          <input type="checkbox" name="shows_Selected[]" value="January 10, 2010  Seaport World Trade Center, Boston, MA" tabindex="5">

      January 10, 2010 - Seaport World Trade Center, Boston, MA <br>

 

<input type="checkbox" name="shows_Selected[]" value="January 17, 2010  Wyndham Andover, MA" tabindex="5">

      January 17, 2010 - Wyndham Andover, MA<br>

 

<input type="checkbox" name="shows_Selected[]" value="January 24, 2010  Granite Links Golf Club, Quincy, MA" tabindex="10">

      January 24, 2010 - Granite Links Golf Club, Quincy, MA<br>

 

<input type="checkbox" name="shows_Selected[]" value="January 31, 2010  Sheraton Ferncroft, Danvers, MA" tabindex="15">

      January 31, 2010 - Sheraton Ferncroft, Danvers, MA<br>

 

<input type="checkbox" name="shows_Selected[]" value="February 7, 2010  Crowne Plaza, Natick, MA" tabindex="20">

      February 7, 2010 - Crowne Plaza, Natick, MA<br>

 

<input type="checkbox" name="shows_Selected[]" value="February 14, 2010  Indian Pond Country Club, Kingston, MA" tabindex="25">

      February 14, 2010 - Indian Pond Country Club, Kingston, MA<br>

 

<input type="checkbox" name="shows_Selected[]" value="February 21, 2010  Burlington Marriott, MA" tabindex="30">

      February 21, 2010 - Burlington Marriott, MA</font> <font color="#666666"><br>

      </font></td>

                      </tr>

                    </table>

i have multiple check boxes

Link to comment
Share on other sites

What do you have for the method in your form tag? Are you sure it's post and not get?

 

Oh I see...

You are making sure that you have something selected right?

This:

however if the dont check any of the boxes i get this error

 

Warning: Invalid argument supplied for foreach() in /home/va010021/public_html/newportweddingExpo/form_procces.php on line 73

Link to comment
Share on other sites

ok so it is an array. Again, WRAP YOUR CODE IN CODE TAGS.

 

now before you go into any of the foreach statements, write print_r($_POST['shows_Selected'])

 

and see what it says. You are making sure that you have something selected right?

i have post

this is the error

Parse error: syntax error, unexpected T_VARIABLE in /home/va010021/public_html/newportweddingExpo/form_procces.php on line 72

this is line 72

$source .= $one_media."<br>";

Link to comment
Share on other sites

@randyw:

Change this:

$media_array = $_POST['shows_Selected'];
foreach ($media_array as $one_media) {
$source .= $one_media."<br>";
}

 

To this:

if (is_array($_POST['shows_Selected'])) {
   $media_array = $_POST['shows_Selected'];
   foreach ($media_array as $one_media) {
      $source .= $one_media."<br>";
   }
}

 

That will check first if they checked 1 of the boxes, if they didn't, it will skip over the foreach.

Link to comment
Share on other sites

 

<?php

 

      include_once("include/dbc.php");

 

      // Verify that all form elements are completed

 

 

if (empty($_POST['first_name'])){

  //die ("ERROR: Please add your First Name..");

header("Location: form.php?msg=ERROR: Please add your First Name..");

exit();

}

if (empty($_POST['last_name'])){

//die ("ERROR: Please add your Last Name..");

header("Location: form.php?msg=ERROR: Please add your Last Name..");

exit();

 

 

}

 

if (empty($_POST['email_address'])){

//die ("ERROR: Please add your Email..");

header("Location: form.php?msg=ERROR: Please add your Email..");

exit();

 

 

}

 

if (empty($_POST['mailling_address'])){

//die ("ERROR: Please add your Address..");

header("Location: form.php?msg=ERROR: Please add your Address..");

exit();

 

 

}

 

 

if (empty($_POST['city'])){

//die ("ERROR: Please add your City..");

header("Location: form.php?msg=ERROR: Please add your City..");

exit();

 

 

}

 

 

if (empty($_POST['zip'])){

//die ("ERROR: Please add your City..");

header("Location: form.php?msg=ERROR: Please add your City..");

exit();

 

 

}

 

if (empty($_POST['home_phone'])){

//die ("ERROR: Please add your Home Phone..");

header("Location: form.php?msg=ERROR: Please add your Home Phone..");

exit();

 

 

}

 

if (empty($_POST['work_phone'])){

//die ("ERROR: Please add your WorkPhone..");

header("Location: form.php?msg=ERROR: Please add your WorkPhone..");

exit();

 

 

}

if (is_array($_POST['shows_Selected'])) {

  $media_array = $_POST['shows_Selected'];

  foreach ($media_array as $one_media) {

      $source .= $one_media."<br>";

  }

 

// Now process the Addition Information array from POST

if (is_array($_POST['additional_Info'])) {

$addlInfo_array = $_POST['additional_Info'];

foreach ($addlInfo_array as $one_addl) {

$addlInfo .= $one_addl."<br>";

}

$additional_Info = substr($addlInfo, 0, -4);

 

 

// Now process the Addition Information array from POST

if (is_array($_POST['further_information'])) {

$furtherInfo_array = $_POST['further_information'];

foreach ($furtherInfo_array as $one_futher) {

$furtherInfo .= $one_further."<br>";

}

$further_information = substr($furtherInfo, 0, -4);

{

 

// update data in mysql database

$sql = "INSERT INTO newportweddingExpoForm

(shows_Selected, additional_Info, further_information, first_name, last_name, Role, email_address, home_phone, work_phone, city, state, zip, mailling_address, apt_number, wedding_month, wedding_day, wedding_year, Wedding_Tentative, wedding_Region, wedding_city, wedding_state, budget, find_aboutUs)VALUES('$shows_Selected', '$additional_Info', '$further_information', '$first_name', '$last_name', '$role', '$email_address', '$home_phone', '$work_phone', '$city', '$state', '$zip', '$mailling_address', '$apt_number', '$wedding_month', '$wedding_day', '$wedding_year', '$Wedding_Tentative', '$wedding_Region', '$wedding_city', '$wedding_state', '$budget', '$find_aboutUs')";

$result = @mysql_query($sql);

}

if($result){

 

//die ("Your form information has been successfully sent..");

 

header("Location: form.php?msg=Your form information has been successfully sent..");

exit();

 

}

else {

//die ("Iam sorry there was a problem, duplicate form name allready sent..");

header("Location: form.php?msg=Iam sorry there was a problem, duplicate form name  allready sent..");

 

}

 

mysql_close();

?>

 

    <?php

}

?>

    <?php

}

?>

    <?php

}

 

 

 

this is still not doing anything i thought it looked right

if (is_array($_POST['shows_Selected'])) {

  $media_array = $_POST['shows_Selected'];

  foreach ($media_array as $one_media) {

      $source .= $one_media."<br>";

  }

 

// Now process the Addition Information array from POST

if (is_array($_POST['additional_Info'])) {

$addlInfo_array = $_POST['additional_Info'];

foreach ($addlInfo_array as $one_addl) {

$addlInfo .= $one_addl."<br>";

}

$additional_Info = substr($addlInfo, 0, -4);

 

 

// Now process the Addition Information array from POST

if (is_array($_POST['further_information'])) {

$furtherInfo_array = $_POST['further_information'];

foreach ($furtherInfo_array as $one_futher) {

$furtherInfo .= $one_further."<br>";

}

$further_information = substr($furtherInfo, 0, -4);

{

 

// update data in mysql database

$sql = "INSERT INTO newportweddingExpoForm

(shows_Selected, additional_Info, further_information, first_name, last_name, Role, email_address, home_phone, work_phone, city, state, zip, mailling_address, apt_number, wedding_month, wedding_day, wedding_year, Wedding_Tentative, wedding_Region, wedding_city, wedding_state, budget, find_aboutUs)VALUES('$shows_Selected', '$additional_Info', '$further_information', '$first_name', '$last_name', '$role', '$email_address', '$home_phone', '$work_phone', '$city', '$state', '$zip', '$mailling_address', '$apt_number', '$wedding_month', '$wedding_day', '$wedding_year', '$Wedding_Tentative', '$wedding_Region', '$wedding_city', '$wedding_state', '$budget', '$find_aboutUs')";

$result = @mysql_query($sql);

}

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.