Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-04
2
Medium Priority
?
1,032 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 2000 total points
ID: 24300565
Try writing out the contents of $source in your query, rather than the variable $media.
0
 

Author Comment

by:siddharthkool
ID: 24301425
thanks it worked...
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
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.
Suggested Courses
Course of the Month11 days, 23 hours left to enroll

916 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