Page 1 of 1

having problem Inserting Set data into mysql

Posted: Fri May 19, 2006 7:21 am
by paulng
Can any one please help...

I have a survey questionnaire, one section has checkbox which are suppose to be submitted into my database if checked individually but Im having trouble writing a query, at the moment it submitting everything but I want it to submit what is checked

here is my code
html

Code: Select all

<table width="" border="0" cellspacing="0" cellpadding="0">
                <tr>
               	    <td>Don&rsquo;t want to download any software on my PC</td>
                    <td><input type="checkbox" name="Question1a[]" value="Dont want"> </td>
                </tr>
                <tr>
                    <td>I couldn&rsquo;t download because my computer is slow </td>
                	<td><input type="checkbox" name="Question1a[]" value="I couldnt"> </td>
                </tr>
                <tr>
                    <td>I don&rsquo;t have enough memory on my PC </td>
                    <td><input type="checkbox" name="Question1a[]" value="I dont have"> </td>
                </tr>
                <tr>
                    <td>I&rsquo;m satisfied with range of games available on Instant Play Casino </td>
                    <td><input type="checkbox" name="Question1a[]" value="Im satsfied"> </td>
                </tr>
                <tr>
                    <td>I would like to have reassurance your software is safe</td>
                    <td><input type="checkbox" name="Question1a[]" value="I would like"> </td>
                </tr>
            </table>



Code: Select all

$username = $_POST['username'];
		$question1 = $_POST['Question1'];
		$question1a = $_POST['Question1a'];
		$question2 = $_POST['Question2'];
		$question3 = $_POST['Question3'];
		$question4 = $_POST['Question4'];
		$question5 = $_POST['Question5'];
		$question6 = $_POST['Question6'];
		$question6a = $_POST['Question6a'];
		$question6b = $_POST['Question6b'];
		$question6c = $_POST['Question6c'];
	              $question7 = $_POST['Question7'];
		$question8 = $_POST['Question8'];
		$submit_date = date("F j, Y, g:i a");
		
/******* Question1a variables **********/
		
        $question1a = $_POST['Dont want'];
        $question1a = $_POST['I couldnt'];
        $question1a = $_POST['I dont have'];
        $question1a = $_POST[' Im satsfied'];
        $question1a = $_POST['I would like']; 
    
        /****************************************/  

        Dont want,I couldnt,I dont have,Im satsfied,I woul...     		
		
			
	    $insquery = "INSERT INTO survey (username,Question1,Question2, Question3, Question4, Question5, Question6, Question6a, Question6b, Question6c, Question7, Question8, submit_date)	VALUES ('$username','$question1','$question2','$question3','$question4', '$question5', '$question6', '$question6a','$question6b','$question6c','$question7','$question8','$submit_date')";
	   // $insquery = "INSERT INTO survey SET Question1a = '1,2,3,4,5'";		
   	    $insquery = "INSERT INTO survey(Question1a) VALUES('Dont want,I couldnt,I dont have,Im satsfied,I would like')";
   	    $result = mysql_query($insquery) or die ("Invalid Insert Query");
help will be much appreciated...

Re: having problem Inserting Set data into mysql

Posted: Fri May 19, 2006 6:07 pm
by RobertGonzalez
Your HTML needs a little help first off...
html

Code: Select all

<table width="" border="0" cellspacing="0" cellpadding="0">
                <tr>
               	    <td>Don't want to download any software on my PC</td>
                    <td><input type="checkbox" name="Question1a[0]" />Don't Want</td>
                </tr>
                <tr>
                    <td>I couldn't download because my computer is slow </td>
                	<td><input type="checkbox" name="Question1a[1]" />I couldn't</td>
                </tr>
                <tr>
                    <td>I don&rsquo;t have enough memory on my PC </td>
                    <td><input type="checkbox" name="Question1a[2]" /> I Don't Have</td>
                </tr>
                <tr>
                    <td>I&rsquo;m satisfied with range of games available on Instant Play Casino </td>
                    <td><input type="checkbox" name="Question1a[3]" />I'm Satisfied</td>
                </tr>
                <tr>
                    <td>I would like to have reassurance your software is safe</td>
                    <td><input type="checkbox" name="Question1a[4]" />I would like</td>
                </tr>
            </table>
Now your PHP needs some help also...
php

Code: Select all

<?php
		$username = $_POST['username'];
		$question1 = $_POST['Question1'];
		$question1a = $_POST['Question1a'];
		$question2 = $_POST['Question2'];
		$question3 = $_POST['Question3'];
		$question4 = $_POST['Question4'];
		$question5 = $_POST['Question5'];
		$question6 = $_POST['Question6'];
		$question6a = $_POST['Question6a'];
		$question6b = $_POST['Question6b'];
		$question6c = $_POST['Question6c'];
		$question7 = $_POST['Question7'];
		$question8 = $_POST['Question8'];
		$submit_date = date("F j, Y, g:i a");
		
		/******* Question1a variables **********/
		
		if (is_array($question1a))
		{
			$q1a_count = count($question1a);
			for ($i = 0; $ < $q1a_count; $i++)
			{
				$delim = ( $i < $q1a_count - 1 ) ? ', ' : '';
				$q1a_insert .= ( isset($question1a[$i]) ) ? $i . $delim : '';
			}
		}
		else
		{
			$q1a_insert = $question1a;
		}
		/****************************************/  

			
	    $insquery = "INSERT INTO survey (username,Question1,Question1a,Question2, Question3, Question4, Question5, Question6, Question6a, Question6b, Question6c, Question7, Question8, submit_date)	VALUES ('$username','$question1','$q1a_insert','$question2','$question3','$question4', '$question5', '$question6', '$question6a','$question6b','$question6c','$question7','$question8','$submit_date')";
   	    $result = mysql_query($insquery) or die ("Invalid Insert Query");
// etc, etc
?>