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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
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.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

792 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