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,024 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
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.

785 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