2

i try to store the booking booths into database based on user selection, there are 10 check boxes for each booths and user can choose which day they want to reserve booths. For each check box has it own field in database, if user choose booth A01, D1 and D2, when he press reserve button, it will insert value into D1 and D2. But I dont know how to get the checked checkbox value to store in database

my booth interface https://i.stack.imgur.com/YB8wB.gif

my table structure https://i.stack.imgur.com/Y6Ix7.gif

My coding

<?php
session_start();
if ( !isset($_SESSION['AUTHORIZED_USERNAME']) || empty($_SESSION['AUTHORIZED_USERNAME']) )  {
header("location:index.php");
}else{
$user=$_SESSION['AUTHORIZED_USERNAME'];

}
include('db.php');

if($_REQUEST){

$id     = $_REQUEST['search_category_id'];
$query2 = mysql_query("SELECT filenameBig, filename, url FROM eventinfo where eventID ='$id'");
  $row = mysql_fetch_array($query2, MYSQL_ASSOC);

if($id == -1)
{ 
  echo "<style type='text/css'>#btn_submit{visibility:hidden}</style>";
}

else{



      /*echo "<a href='{$row['url']}'>Click me!</a>";*/
      echo "<p><br><img src='{$row['filename']}' alt='' /></p>";
      echo "<p></p>";
      echo "<p align='right'><a href='$row[filenameBig]' target='_blank'>Click to view large image</a></p>";
      echo "<hr size='1'>";
      echo "<div style='padding-left:4px;' align='left'><strong>Booths Listing</strong>";
      echo "<p></p>";




$query = "select boothAlias, totalDay from booths, eventinfo where booths.eventID=eventinfo.eventID && booths.eventID = ".$id."";

$_SESSION['EVENT_ID']=$id;
$result = mysql_query($query);
$result2= mysql_query($query);


echo "<table border='0' style='width:400px;table-layout:fixed' >";


$rows2 = mysql_fetch_array($result);
$Day=$rows2['totalDay'];
echo "<table>";
for ($day = 0; $day <= $Day; ++$day) {
 if($day==0){
    echo "<th>Booth</th>";
}else{
         echo "<th>D".$day."</th>";
    }
}

while($rows = mysql_fetch_array($result2)){
    $boothAlias=$rows['boothAlias'];
    $totalDay=$rows['totalDay'];


         echo "<tr><td>$boothAlias</td>";
             for ($day2 = 1; $day2 <= $totalDay; ++$day2) {
                 echo "<td><input name='day2[]' type='checkbox' value='$day2' /></td>";
             }
        echo "</tr>";
}

echo "</table>";
}
}
?>
mcheng
  • 153
  • 7
  • 21
  • 3
    Reference thread - http://stackoverflow.com/questions/3362116/php-reformat-multidimensional-array-to-insert-into-mysql – KV Prajapati Oct 21 '11 at 08:31
  • Yeah well that thread says it all. Look at foreach() loops which allow you to loop through your array and then you can deal with it as you wish. – DarkMantis Oct 21 '11 at 08:50
  • 1
    Please fix those SQL injection hols, see: http://stackoverflow.com/questions/332365/xkcd-sql-injection-please-explain – Johan Oct 21 '11 at 12:11
  • possible duplicate of [array in MySQL](http://stackoverflow.com/questions/896485/array-in-mysql), [How to store an array into mysql?](http://stackoverflow.com/questions/3413291/how-to-store-an-array-into-mysql) – outis Oct 23 '11 at 11:54

1 Answers1

0

I think that SET type would be good solution for this.

http://dev.mysql.com/doc/refman/5.0/en/set.html

grongor
  • 1,305
  • 1
  • 13
  • 26