0

Hi All,

I have the following code:

$requester_email = $_POST['requester_email'];
$requester_name = $_POST['requester_name'];
$todays_date = $_POST['todays_date'];
$Start_Date = $_POST['Start_Date'];
$End_Date = $_POST['End_Date'];
$Department = $_POST['Department'];
$No_Engineers_Required = $_POST['No_Engineers_Required'];
$Prefered_Engineers = $_POST['Prefered_Engineers'];
$Customer_Name = $_POST['Customer_Name'];
$Location = $_POST['Location'];
$Type_Of_Job = $_POST['Type_Of_Job'];
$Job_Ref_No = $_POST['Job_Ref_No'];
$Additional_info = $_POST['Additional_info'];

The help I need is the information for Prefered_Engineers comes from a collection of checkboxes.

This code is here:

<td>
<font color="#000000" size="2" face="Arial">
<input name="Prefered_Engineers[]" type="checkbox" value="GT" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="CT" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="GB" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="GK" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="MH" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="DR" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="JM" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="LL" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="CJ" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="NW" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="HG" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="DH" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="JW" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="JB" class="fieldstyle">
</font>
</td>

The value passed is 'Array'.

Can anyone help so that all of the selected checkbox values are passed.

Regards,

T

4
Contributors
15
Replies
17
Views
7 Years
Discussion Span
Last Post by feddie1984
Featured Replies
  • [QUOTE=feddie1984;1050627]Hi All, I have the following code: [CODE]$requester_email = $_POST['requester_email']; $requester_name = $_POST['requester_name']; $todays_date = $_POST['todays_date']; $Start_Date = $_POST['Start_Date']; $End_Date = $_POST['End_Date']; $Department = $_POST['Department']; $No_Engineers_Required = $_POST['No_Engineers_Required']; $Prefered_Engineers = $_POST['Prefered_Engineers']; $Customer_Name = $_POST['Customer_Name']; $Location = $_POST['Location']; $Type_Of_Job = $_POST['Type_Of_Job']; $Job_Ref_No = $_POST['Job_Ref_No']; $Additional_info = $_POST['Additional_info'];[/CODE] The help I need … Read More

  • [QUOTE=ShawnCplus;1050741]What he said, it's been a long day :)[/QUOTE] It happens to the best of us ;) Read More

  • 1

    [QUOTE=leviathan185;1050970]you could also make a function out of it [CODE=php] <?php function arrayToString($array) { $string = ''; foreach($array as $value) { $string .= "{$string}, {$value} "; } return $string; } echo arrayToString($_POST['Prefered_Engineers']); ?> [/CODE][/QUOTE] Or simply, [code]$string = implode(",",$_POST['Prefered_Engineers']); [/code] Read More

1

Hi All,

I have the following code:

$requester_email = $_POST['requester_email'];
$requester_name = $_POST['requester_name'];
$todays_date = $_POST['todays_date'];
$Start_Date = $_POST['Start_Date'];
$End_Date = $_POST['End_Date'];
$Department = $_POST['Department'];
$No_Engineers_Required = $_POST['No_Engineers_Required'];
$Prefered_Engineers = $_POST['Prefered_Engineers'];
$Customer_Name = $_POST['Customer_Name'];
$Location = $_POST['Location'];
$Type_Of_Job = $_POST['Type_Of_Job'];
$Job_Ref_No = $_POST['Job_Ref_No'];
$Additional_info = $_POST['Additional_info'];

The help I need is the information for Prefered_Engineers comes from a collection of checkboxes.

This code is here:

<td>
<font color="#000000" size="2" face="Arial">
<input name="Prefered_Engineers[]" type="checkbox" value="GT" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="CT" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="GB" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="GK" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="MH" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="DR" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="JM" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="LL" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="CJ" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="NW" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="HG" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="DH" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="JW" class="fieldstyle">
<br>
<input name="Prefered_Engineers[]" type="checkbox" value="JB" class="fieldstyle">
</font>
</td>

The value passed is 'Array'.

Can anyone help so that all of the selected checkbox values are passed.

Regards,

T

As much as I try and aviod overposting more experienced and respected posters, if you remove the [] that will only let you select 1 of the checkboxes and not multiple. If you want multiple You need to loop through them. Try

<?php
  $engineers = $_POST['Prefered_Engineers'];
  foreach($engineers as $engineer) {
     echo $engineer;
  }
?>

Hope that helps

Votes + Comments
good spot
0

As much as I try and aviod overposting more experienced and respected posters, if you remove the [] that will only let you select 1 of the checkboxes and not multiple. If you want multiple You need to loop through them. Try

<?php
  $engineers = $_POST['Prefered_Engineers'];
  foreach($engineers as $engineer) {
     echo $engineer;
  }
?>

Hope that helps

What he said, it's been a long day :)

Edited by ShawnCplus: n/a

0

Thank you both for your replies. Is there any way to pass the looped result into the variable $Prefered_Engineers? The out put I get now is the selected checkboxes printed on the screen but only the last selected checkbox being posted to Prefered_Engineers.

$requester_email = $_POST['requester_email'];
$requester_name = $_POST['requester_name'];
$todays_date = $_POST['todays_date'];
$Start_Date = $_POST['Start_Date'];
$End_Date = $_POST['End_Date'];
$Department = $_POST['Department'];
$No_Engineers_Required = $_POST['No_Engineers_Required'];
$Prefered_Engineers = $_POST['Prefered_Engineers'];
foreach($Prefered_Engineers as $Prefered_Engineers) {
echo $Prefered_Engineers;
}
$Customer_Name = $_POST['Customer_Name'];
$Location = $_POST['Location'];
$Type_Of_Job = $_POST['Type_Of_Job'];
$Job_Ref_No = $_POST['Job_Ref_No'];
$Additional_info = $_POST['Additional_info'];

What I am doing is displaying the information on the webpage, sending and e-mail and inserting the info into a database. Everything else works apart from the checkboxes. I got it to work like this:

$Prefered_Engineers = serialize($_POST['Prefered_Engineers']);

but the output is:

Prefered Engineers: a:3:{i:0;s:2:"GK";i:1;s:2:"DR";i:2;s:2:"LL";}

Is there a way to display and store it as GK, DR, LL?

0

Thank you both for your replies. Is there any way to pass the looped result into the variable $Prefered_Engineers? The out put I get now is the selected checkboxes printed on the screen but only the last selected checkbox being posted to Prefered_Engineers.

$requester_email = $_POST['requester_email'];
$requester_name = $_POST['requester_name'];
$todays_date = $_POST['todays_date'];
$Start_Date = $_POST['Start_Date'];
$End_Date = $_POST['End_Date'];
$Department = $_POST['Department'];
$No_Engineers_Required = $_POST['No_Engineers_Required'];
$Prefered_Engineers = $_POST['Prefered_Engineers'];
foreach($Prefered_Engineers as $Prefered_Engineers) {
echo $Prefered_Engineers;
}
$Customer_Name = $_POST['Customer_Name'];
$Location = $_POST['Location'];
$Type_Of_Job = $_POST['Type_Of_Job'];
$Job_Ref_No = $_POST['Job_Ref_No'];
$Additional_info = $_POST['Additional_info'];

What I am doing is displaying the information on the webpage, sending and e-mail and inserting the info into a database. Everything else works apart from the checkboxes. I got it to work like this:

$Prefered_Engineers = serialize($_POST['Prefered_Engineers']);

but the output is:

Prefered Engineers: a:3:{i:0;s:2:"GK";i:1;s:2:"DR";i:2;s:2:"LL";}

Is there a way to display and store it as GK, DR, LL?

apologies the function was a demonstration of how to access the the values in the array. you can use the same function to perform other actions, such as send the values to the data base. It will depend on your database structure as to how you would insert the values.

I am not too sure what you mean about the GK, DR, LL

0

Sorry that was an eample of how I would like the information stored in the field. This is my script for php:

<?php


include("socomecdbinfo.inc.php");


$requester_email = $_POST['requester_email'];
$requester_name = $_POST['requester_name'];
$todays_date = $_POST['todays_date'];
$Start_Date = $_POST['Start_Date'];
$End_Date = $_POST['End_Date'];
$Department = $_POST['Department'];
$No_Engineers_Required = $_POST['No_Engineers_Required'];
$Prefered_Engineers = serialize($_POST['Prefered_Engineers']);
$Customer_Name = $_POST['Customer_Name'];
$Location = $_POST['Location'];
$Type_Of_Job = $_POST['Type_Of_Job'];
$Job_Ref_No = $_POST['Job_Ref_No'];
$Additional_info = $_POST['Additional_info'];


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO DateRequest VALUES ('','$requester_email','$requester_name','$todays_date','$Start_Date','$End_Date','$Department','$No_Engineers_Required','$Prefered_Engineers','$Customer_Name','$Location','$Type_Of_Job','$Job_Ref_No','$Additional_info')";
mysql_query($query);
mysql_close();

$message = " $todays_date \n
Requester: $requester_name \n
Start Date: $Start_Date \n
End Date: $End_Date \n
No Engineers Reqired: $No_Engineers_Required \n
Prefered Engineers: $Prefered_Engineers \n
Customer Name: $Customer_Name \n
Location: $Location \n
Type of Job: $Type_Of_Job \n
Job Ref No: $Job_Ref_No \n
Additional Info: $Additional_info \n
";

$from = "From: $requester_email\r\n";

mail("test@btinternet.com", "Date Request", $message, $from);

?>

<p align="center">
Date: <?php echo $todays_date ?>
<br />
Thank You : <?php echo $requester_name ?>
<br />
Message:<br />
<?php echo $message ?>

So instead of Prefered_Engineers = a:3:{i:0;s:2:"GK";i:1;s:2:"DR";i:2;s:2:"LL";}
I would like it to equal: GK, DR, LL

0

Sorry that was an eample of how I would like the information stored in the field. This is my script for php:

<?php


include("socomecdbinfo.inc.php");


$requester_email = $_POST['requester_email'];
$requester_name = $_POST['requester_name'];
$todays_date = $_POST['todays_date'];
$Start_Date = $_POST['Start_Date'];
$End_Date = $_POST['End_Date'];
$Department = $_POST['Department'];
$No_Engineers_Required = $_POST['No_Engineers_Required'];
$Prefered_Engineers = serialize($_POST['Prefered_Engineers']);
$Customer_Name = $_POST['Customer_Name'];
$Location = $_POST['Location'];
$Type_Of_Job = $_POST['Type_Of_Job'];
$Job_Ref_No = $_POST['Job_Ref_No'];
$Additional_info = $_POST['Additional_info'];


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO DateRequest VALUES ('','$requester_email','$requester_name','$todays_date','$Start_Date','$End_Date','$Department','$No_Engineers_Required','$Prefered_Engineers','$Customer_Name','$Location','$Type_Of_Job','$Job_Ref_No','$Additional_info')";
mysql_query($query);
mysql_close();

$message = " $todays_date \n
Requester: $requester_name \n
Start Date: $Start_Date \n
End Date: $End_Date \n
No Engineers Reqired: $No_Engineers_Required \n
Prefered Engineers: $Prefered_Engineers \n
Customer Name: $Customer_Name \n
Location: $Location \n
Type of Job: $Type_Of_Job \n
Job Ref No: $Job_Ref_No \n
Additional Info: $Additional_info \n
";

$from = "From: $requester_email\r\n";

mail("test@btinternet.com", "Date Request", $message, $from);

?>

<p align="center">
Date: <?php echo $todays_date ?>
<br />
Thank You : <?php echo $requester_name ?>
<br />
Message:<br />
<?php echo $message ?>

So instead of Prefered_Engineers = a:3:{i:0;s:2:"GK";i:1;s:2:"DR";i:2;s:2:"LL";}
I would like it to equal: GK, DR, LL

Oh i see...

<?php
   $string = '';
   $engineers = $_POST['Prefered_Engineers'];
   foreach($engineers as $engineer) {
      $string .= "{$string}, {$engineer} ";  
   }
?>

That will put all the engineers in to 1 string seperated by commas

Edited by leviathan185: better example

0

you could also make a function out of it

<?php
   function arrayToString($array) {
      $string = '';
      foreach($array as $value) {
         $string .= "{$string}, {$value} ";
      }
      return $string;
   }

   echo arrayToString($_POST['Prefered_Engineers']);
?>
1

you could also make a function out of it

<?php
   function arrayToString($array) {
      $string = '';
      foreach($array as $value) {
         $string .= "{$string}, {$value} ";
      }
      return $string;
   }

   echo arrayToString($_POST['Prefered_Engineers']);
?>

Or simply,

$string = implode(",",$_POST['Prefered_Engineers']);
Votes + Comments
Turned many lines of ordinary code into 1 line of magic
0

Thanks for all your replies, I will test them when I get home and then mark as solved.

0

Could I change $string to $Prefered_Engineers?

Like This:

<?php  


include("socomecdbinfo.inc.php");  


$requester_email = $_POST['requester_email'];
$requester_name = $_POST['requester_name'];
$todays_date = $_POST['todays_date'];
$Start_Date = $_POST['Start_Date'];
$End_Date = $_POST['End_Date'];
$Department = $_POST['Department'];
$No_Engineers_Required = $_POST['No_Engineers_Required'];
$Prefered_Engineers = implode(",",$_POST['Prefered_Engineers']);
$Customer_Name = $_POST['Customer_Name'];
$Location = $_POST['Location'];
$Type_Of_Job = $_POST['Type_Of_Job'];
$Job_Ref_No = $_POST['Job_Ref_No'];
$Additional_info = $_POST['Additional_info'];  


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO DateRequest VALUES ('','$requester_email','$requester_name','$todays_date','$Start_Date','$End_Date','$Department','$No_Engineers_Required','$Prefered_Engineers','$Customer_Name','$Location','$Type_Of_Job','$Job_Ref_No','$Additional_info')";
mysql_query($query);
mysql_close();

$message = " $todays_date \n
Requester: $requester_name \n
Start Date: $Start_Date \n
End Date: $End_Date \n
No Engineers Reqired: $No_Engineers_Required \n
Prefered Engineers: $Prefered_Engineers \n
Customer Name: $Customer_Name \n
Location: $Location \n
Type of Job: $Type_Of_Job \n
Job Ref No: $Job_Ref_No \n
Additional Info: $Additional_info \n";

$from = "From: $requester_email\r\n";

mail("test@btinternet.com", "Date Request", $message, $from);

?>

<p align="center">Date: <?php echo $todays_date ?>
<br />
Thank You : <?php echo $requester_name ?>
<br />
Message:<br />
<?php echo $message ?>

Edited by feddie1984: missed a word out

0

Yeah, ofcourse. :) $string is just a variable name. You can give any name to a variable.
See Php naming convention here .

0

All sotrted and working just great. Thanks everyone for your help!

T

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.