Solved

how can i insert multiple check box values into my single database field ? using php and mysql

Posted on 2009-05-04
2
1,023 Views
Last Modified: 2012-08-13
<html>
<body>
<table>

<form name="registration" method="post" action="registration.php5">  
      <table align="center" class="style1">
          <tr>
              <td class="style2">
                  Email</td>
              <td class="style2">
                  :</td>
              <td>
                  <input id="Text1" type="text" name="email" /></td>
          </tr>
          <tr>
              <td class="style2">
                  Name</td>
              <td class="style2">
                  :</td>
              <td>
                  <input id="Text2" type="text" name="name" /></td>
          </tr>
          <tr>
              <td class="style2">
                  Department</td>
              <td class="style2">
                  :</td>
              <td>
                  <input id="Text3" type="text" name="department" /></td>
          </tr>
          <tr>
              <td class="style2">
                  Office Phone</td>
              <td class="style2">
                  :</td>
              <td>
                  <input id="Text4" type="text" name="phone"/></td>
          </tr>
          <tr>
              <td class="style2">
                  Alternate Phone</td>
              <td class="style2">
                  :</td>
              <td>
                  <input id="Text5" type="text" name="altphone"/></td>
          </tr>
          <tr>
              <td class="style2">
                  &nbsp;</td>
              <td class="style2">
                  &nbsp;</td>
              <td>
                  &nbsp;</td>
          </tr>
          <tr>
              <td class="style2">
                  &nbsp;</td>
              <td class="style2">
                  &nbsp;</td>
              <td>
                  <input id="submit" type="submit" value="Submit" /></td>
          </tr>
         
      </table>

     
     
     
     

     
     
     
     
     
      <br />
      <table align="center" class="style3">
          <tr>
              <td class="style4">
                  May 12th 11:30am</td>
              <td class="style5">
                 
                  <input  type="checkbox" name="media[]" value="winba" /></td>
              <td class="style6"><a href="http://www.spsu.edu/asc/knowledgebase/workshops/index.html#8">Advanced Digital Campus Leadership Institute </a></td>
                 
              <td>
                  H-312</td>
          </tr>
          <tr>
              <td class="style4">
                  June 12th 10:30am</td>
                        <td class="style5">
                            <input  type="checkbox" name="media[]" value="vista8" /></td>
                        <td class="style6">
                            <a href="http://www.spsu.edu/asc/knowledgebase/workshops/index.html#8">Orientation to GeorgiaVIEW Vista 8 </a></td>
                        <td>
                            H-321</td>
                    </tr>
                </table>
                         </form>
    </td>
  <td rowspan="5">&nbsp;</td>
</tr>


<tr>
  <td bgcolor="#000000" class="subnav">&nbsp;</td>
  </tr>
<tr>
  <td bgcolor="#000000" class="subnav">&nbsp;</td>
  </tr>
 
 
 
 
<!-- Start footer -->
</table>
</body>
</html>
<?PHP
 

//Database Information
 

$dbhost = "localhost";

$dbname = "spsu";

$dbuser = "root";

$dbpass = "";
 

//Connect to database
 

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());

mysql_select_db($dbname) or die(mysql_error());

           $result = mysql_query($query);          

    

$email = $_POST['email'];

$name = $_POST['name'];    

$department = $_POST['department'];

$phone = $_POST['phone'];

$altphone = $_POST['altphone'];

$workshop= $_POST['workshop'] ;
 

                      
 
 

          $media_array = $_POST['media'];
 
 

            mysql_select_db("registration");

             

              
 

foreach ($media_array as $one_media) 

$source .= $one_media.", ";
 

 $media = substr($source, 0, -2);
 
 

$query = "INSERT INTO registration (email,name,department,phone,altphone,media)

VALUES('$email','$name','$department','$phone','$altphone','$media')";
 

                        $result = mysql_query($query);       
 
 

mysql_query($query) or die(mysql_error());

mysql_close();
 

echo "You have successfully Registered";

?>

Open in new window

0
Comment
Question by:siddharthkool
2 Comments
 
LVL 10

Accepted Solution

by:
webwyzsystems earned 500 total points
Comment Utility
Try writing out the contents of $source in your query, rather than the variable $media.
0
 

Author Comment

by:siddharthkool
Comment Utility
thanks it worked...
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction (All good things must come to an end (http://en.wikipedia.org/wiki/All_Good_Things...)) The original MySQL API (http://php.net/manual/en/book.mysql.php) has gone away, deprecated by PHP in Version 5.5, and removed from PHP in all curre…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now