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,027 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
webwyzsystems earned 500 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

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…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
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.

738 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