samedi 24 janvier 2015

check box values from retrieved from database table checked and transferred to another table within the same database

I am trying to do something important right now - i've got a checkbox list - the values of the checkbox list were retrieved from a database - so its not manually inputted - I am trying to select a random set of values from the list which I have to tick - but the problem am having is that i am not able to insert them values into a mysql database - so i'll provide a screen shot of the table with the checkbox list and then copy and paste the necessary code(s) below =


[IMG]http://ift.tt/1xOBYq5]


the code for retrieving the data for the two columned table is pasted below:



<table border="1" cellspacing="0" style="margin-top:12px width="900"">
<colgroup>
<col span="1">
</colgroup>
<tr><td>Engineering Services
</td>
<td>Information Technologies
</td>
<tr>
<td valign="top">
<?php

$list = "SELECT * FROM specifications WHERE category='Engineering' ORDER BY specifications ASC";
//$list = "SELECT * FROM specifications ";
//$list1 = "SELECT * FROM specifications ORDER BY category ASC Limit 2";
$listAHI = $dbs ->prepare($list);
$listAHI -> execute();

//while($row1 = $listAHI1 ->fetch(PDO::FETCH_ASSOC)){
while($row = $listAHI ->fetch(PDO::FETCH_ASSOC))
{
$specifications = $row["specifications"];
$category = $row["category"];
echo "
<input type='checkbox' name='$specifications'[] value='$specifications'> $specifications<br>

";


}

?>
</td>
<td valign="top">
<?php
$list = "SELECT * FROM specifications WHERE category='Information' ORDER BY specifications ASC";
//$list = "SELECT * FROM specifications ";
//$list1 = "SELECT * FROM specifications ORDER BY category ASC Limit 2";
$listAHI = $dbs ->prepare($list);
$listAHI -> execute();

//while($row1 = $listAHI1 ->fetch(PDO::FETCH_ASSOC)){
while($row = $listAHI ->fetch(PDO::FETCH_ASSOC))
{
$specifications = $row["specifications"];
$category = $row["category"];

echo "
<input type='checkbox' name='$specifications'[] value='$specifications'> $specifications<br>

";
}

?>
</td>
</tr>
</table>


the code to insert the checkboxes into the database is also pasted below:



<?php
//session_start();
include('dbcategory.php');
//include('insertdata3.php');
error_reporting(0);
error_reporting(E_ERROR | E_PARSE);

$first_name = $middle_name = $last_name = $street = $unit = $city = $region = $postalcode = $specifications="";
$businessnumbercountry = $businessnumbercode = $businessnumber = $phone = $phonecountry = $cellphonearea = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$id = $_POST["id"];
$first_name = $_POST["first_name"];
$middle_names = $_POST["middle_names"];
$last_name = $_POST["last_name"];
$street = $_POST["street"];
$unit = $_POST["unit"];
$city = $_POST["city"];
$region = $_POST["region"];
$postalcode = $_POST["postalcode"];
$country = $_POST["country"];
$email = $_POST["email"];

$businessnumber = $_POST["businessnumber"];
$businessnumbercountry = $_POST["businessnumbercountry"];
$businessnumberarea = $_POST["businessnumberarea"];

$phone = $_POST["phone"];
$phonearea = $_POST["phonearea"];
$phonecountry = $_POST["phonecountry"];
$cellphonecountry = $_POST["cellphonecountry"];
$cellphonearea = $_POST["cellphonearea"];

$cellphone = $_POST["cellphone"];
//$specifications = $_POST["specifications"];
//$specifications = implode(",",$_POST['specifications']);
echo $specifications;
}


if (isset($_POST["submitd"]) && $_POST["submitd"] == "Apply" ){
$specifications = implode(",",$_POST['specifications']);
echo $specifications;
$query567="INSERT into emprecords(id, first_name, middle_names, last_name, street, unit, city, region, postalcode, country, email, businessnumbercountry, businessnumberarea, businessnumber, phonecountry, phonearea, phone, cellphonecountry, cellphonearea, cellphone, specifications) VALUES('$id', '$first_name', '$middle_names', '$last_name', '$street', '$unit', '$city', '$region', '$postalcode', '$country', '$email', '$businessnumbercountry','$businessnumberarea','$businessnumber', '$phonecountry', '$phonearea', '$phone', '$cellphonecountry', '$cellphonearea','$cellphone','$specifications');";
$vttvk = $dbs -> prepare($query567);
$vttvk -> execute(array(':id'=>$id,':first_name'=>$first_name,':middle_names'=>$middle_names,':last_name'=>$last_name,':street'=>$street,':unit'=>$unit,':city'=>$city,':region'=>$region,':postalcode'=>$postalcode,':country'=>$country,':email'=>$email, ':businessnumbercountry'=>$businessnumbercountry, ':businessnumberarea'=>$businessnumberarea, ':businessnumber'=>$businessnumber,':phonecountry'=>$phonecountry, ':phonearea'=>$phonearea, ':phone'=>$phone, ':cellphonecountry'=>$cellphonecountry, ':cellphonearea'=>$cellphonearea, ':cellphone'=>$cellphone, ':specifications'=>$specifications));

}
?>


please help me figure out how to insert the multiple checkbox values into the mysql database using php - thnx a mill!!! i've already got an array for printing out the database which i retrieved from the table and then imploding the arrays when i tried to insert it into another mysql table...where'd i go wrong?





Aucun commentaire:

Enregistrer un commentaire