Jump to content

Inserting Checkbox values into my DB


craigtolputt

Recommended Posts

Hu Guys,

 

I have created a survey type form with 9 questions and multiple answers for each.  So the user can select as many answers that they want.

 

So i have the form and it stores the answers to a DB but instead of the actual words it just adds array to the table.

 

does anyone know how to make the actual value of the checkbox store in the db?

 

this is what i get

 


id	qone	qtwo	qthree	qfour	qfive	qsix	qseven	qeight	qnine
		2	Array	Array	Array	Array	Array	Array	test	Array	Array
		4	Array	Array	Array	Array	Array	Array	test	Array	Array

 

 

cheers

 

Craig

Link to comment
Share on other sites

Ok this is my index.php which has all the php in and the form i have used.

<?php
include "connect.php";

$tableName = "results";

$q1 = $_POST["q1"];
$q2 = $_POST["q2"];
$q3 = $_POST["q3"];
$q4 = $_POST["q4"];
$q5 = $_POST["q5"];
$q6 = $_POST["q6"];
$q7 = $_POST["q7"];
$q8 = $_POST["q8"];
$q9 = $_POST["q9"];

$insert = mysql_query("INSERT INTO $tableName (id,qone,qtwo,qthree,qfour,qfive,qsix,qseven,qeight,qnine) VALUES ('','$q1','$q2','$q3','$q4','$q5','$q6','$q7','$q8','$q9')") or die(mysql_error());

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Online Survey</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<link href="css/screen.css" rel="stylesheet" type="text/css" />
<script src="js/checkbox.js" type="text/javascript"></script>
<script src="js/jquery-1.2.6.js" type="text/javascript"></script>
</head>

<body>
<!-- **** Wrapper **** -->
<div id="wrap">

<!-- **** Logo **** -->
<h1 class="logo">
AloeVeraDrink.me, survey
</h1>
<!-- **** Logo **** -->

<!-- **** Scroll Window **** -->
<div id="scrollwindow">
<form action="<?php echo $PHP_SELF;?>" method="post">
        <!-- **** Container **** -->
        <div id="container">

                <!-- **** Screen One **** -->
                <div id="s1" class="screen">
                      
        		<p>
                Thank you for taking the time to answer this quick questionnaire.<br />
                It should take you about 5 minutes to fill in.<br /><br />
                
                It’s designed to help us find out what you think about our new Aloe Vera Drinks.<br /><br />
                Before you start:
                <ul>
                <li>You can skip any question you don’t want to answer by using the ‘next’ button.</li>
                <li>You can return to a question later using the ‘back’ button if you want to change your answer.</li>
                </ul>
                <a href="#s2">Click here to start the questionnaire.</a>
                </p>
                
                </div>
                <!-- **** Screen One **** -->
                
                <!-- **** Screen Two **** -->
                <div id="s2" class="screen">
        
        		<h2>1.	Which flavour(s) did you try?</h2>
                
                <div class="qarea1">
                <label>Aloe Vera Lime (dark green)</label><input name="q1[]" type="checkbox" class="check" value="Lime" />
                <label>Aloe Vera White Grape (pale green)</label><input name="q1[]" type="checkbox" class="check" value="Grape" />
                <label>Aloe Vera Apple (white)</label><input name="q1[]" type="checkbox" class="check" value="Apple" />
                </div>
                
                <!-- **** NEXT/PREV **** -->
                <div id="butts">
        
                <a href="#s1" class="prev">PREV</a>
                
                <a href="#s1" class="numbers" rel="panel" style="margin-left:110px;">start</a>
                <a href="#s2" class="numbers" rel="panel">1</a>
                <a href="#s3" class="numbers" rel="panel">2</a>
                <a href="#s4" class="numbers" rel="panel">3</a>
                <a href="#s5" class="numbers" rel="panel">4</a>
                <a href="#s6" class="numbers" rel="panel">5</a>
                <a href="#s7" class="numbers" rel="panel">6</a>
                <a href="#s8" class="numbers" rel="panel">7</a>
                <a href="#s9" class="numbers" rel="panel">8</a>
                <a href="#s10" class="numbers" rel="panel">9</a>
                
                <a href="#s3" class="next">NEXT</a>
                
                </div>
                <!-- **** NEXT/PREV **** -->

                </div>
                <!-- **** Screen Two **** -->
                
                <!-- **** Screen Three **** -->
                <div id="s3" class="screen">
        
        		<h2>2.	Please rate the following (1-5):</h2>
                
                <p class="opt1">Strongly Dislike</p>
                <p class="opt2">Dislike</p>
                <p class="opt3">Neither Dislike or Like</p>
                <p class="opt4">Like</p>
                <p class="opt5">Like Alot</p>
                
                <div class="qarea2">
                <label>Packaging</label><input name="q2[]" type="checkbox" class="check2" value="Packaging - Strongly Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Packaging - Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Packaging - Neither" /><input name="q2[]" type="checkbox" class="check2" value="Packaging - Like" /><input name="q2[]" type="checkbox" class="check2" value="Packaging - Like Alot" />
                <label>Flavour</label><input name="q2[]" type="checkbox" class="check2" value="Flavour - Strongly Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Flavour - Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Flavour - Neither" /><input name="q2[]" type="checkbox" class="check2" value="Flavour - Like" /><input name="q2[]" type="checkbox" class="check2" value="Flavour - Like Alot" />
                <label>Aloe Vera Pieces</label><input name="q2[]" type="checkbox" class="check2" value="Pieces - Strongly Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Pieces - Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Pieces - Neither" /><input name="q2[]" type="checkbox" class="check2" value="Pieces - Like" /><input name="q2[]" type="checkbox" class="check2" value="Pieces - Like Alot" />
                <label>How the drink looks</label><input name="q2[]" type="checkbox" class="check2" value="Looks - Strongly Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Looks - Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Looks - Neither" /><input name="q2[]" type="checkbox" class="check2" value="Looks - Like" /><input name="q2[]" type="checkbox" class="check2" value="Looks - Like Alot" />
                </div>
                
                <!-- **** NEXT/PREV **** -->
                <div id="butts">
        
                <a href="#s2" class="prev">PREV</a>
                
                <a href="#s1" class="numbers" rel="panel" style="margin-left:110px;">start</a>
                <a href="#s2" class="numbers" rel="panel">1</a>
                <a href="#s3" class="numbers" rel="panel">2</a>
                <a href="#s4" class="numbers" rel="panel">3</a>
                <a href="#s5" class="numbers" rel="panel">4</a>
                <a href="#s6" class="numbers" rel="panel">5</a>
                <a href="#s7" class="numbers" rel="panel">6</a>
                <a href="#s8" class="numbers" rel="panel">7</a>
                <a href="#s9" class="numbers" rel="panel">8</a>
                <a href="#s10" class="numbers" rel="panel">9</a>
                
                <a href="#s4" class="next">NEXT</a>
                
                </div>
                <!-- **** NEXT/PREV **** -->
                
                </div>
                <!-- **** Screen Three **** -->
                
                <!-- **** Screen Four **** -->
                <div id="s4" class="screen">
        
        		<h2>3.	Which of the following words do you think describe this drink? (Tick as many as you agree with.)</h2>
                
                <div class="qarea3">
                <label>Refreshing</label><input name="q3[]" type="checkbox" class="check3" value="Refreshing" />
                <label>Fruity</label><input name="q3[]" type="checkbox" class="check3" value="Fruity" />
                <label>Lumpy</label><input name="q3[]" type="checkbox" class="check3" value="Lumpy" />
                <label>Juicy</label><input name="q3[]" type="checkbox" class="check3" value="Juicy" />
                <label>Light</label><input name="q3[]" type="checkbox" class="check3" value="Light" />
                <label>Fresh</label><input name="q3[]" type="checkbox" class="check3" value="Fresh" />
                </div>
                <div class="qarea3a">
                <label>Healthy</label><input name="q3[]" type="checkbox" class="check3" value="Healthy" />
                <label>Cooling</label><input name="q3[]" type="checkbox" class="check3" value="Cooling" />
                <label>Unusual</label><input name="q3[]" type="checkbox" class="check3" value="Unusual" />
                <label>Chewy</label><input name="q3[]" type="checkbox" class="check3" value="Chewy" />
                <label>Don't Know</label><input name="q3[]" type="checkbox" class="check3" value="Dont Know" />
                <label>Other</label><input name="q3[]" type="checkbox" class="check3" value="Other" />
                </div>
                
                <!-- **** NEXT/PREV **** -->
                <div id="butts">
        
                <a href="#s3" class="prev">PREV</a>
                
                <a href="#s1" class="numbers" rel="panel" style="margin-left:110px;">start</a>
                <a href="#s2" class="numbers" rel="panel">1</a>
                <a href="#s3" class="numbers" rel="panel">2</a>
                <a href="#s4" class="numbers" rel="panel">3</a>
                <a href="#s5" class="numbers" rel="panel">4</a>
                <a href="#s6" class="numbers" rel="panel">5</a>
                <a href="#s7" class="numbers" rel="panel">6</a>
                <a href="#s8" class="numbers" rel="panel">7</a>
                <a href="#s9" class="numbers" rel="panel">8</a>
                <a href="#s10" class="numbers" rel="panel">9</a>
                
                <a href="#s5" class="next">NEXT</a>
                
                </div>
                <!-- **** NEXT/PREV **** -->
                
                </div>
                <!-- **** Screen Four **** -->
                
                <!-- **** Screen Five **** -->
                <div id="s5" class="screen">
        
        		<h2>4.	Would you buy this drink?</h2>
                
                <div class="qarea4">
                <label>Yes</label><input name="q4[]" type="checkbox" class="check" value="Yes" />
                <label>Maybe</label><input name="q4[]" type="checkbox" class="check" value="Maybe" />
                <label>No</label><input name="q4[]" type="checkbox" class="check" value="No" />
                <label>Don't Know</label><input name="q4[]" type="checkbox" class="check" value="Dont Know" />
                </div>
                
                <!-- **** NEXT/PREV **** -->
                <div id="butts">
        
                <a href="#s4" class="prev">PREV</a>
                
                <a href="#s1" class="numbers" rel="panel" style="margin-left:110px;">start</a>
                <a href="#s2" class="numbers" rel="panel">1</a>
                <a href="#s3" class="numbers" rel="panel">2</a>
                <a href="#s4" class="numbers" rel="panel">3</a>
                <a href="#s5" class="numbers" rel="panel">4</a>
                <a href="#s6" class="numbers" rel="panel">5</a>
                <a href="#s7" class="numbers" rel="panel">6</a>
                <a href="#s8" class="numbers" rel="panel">7</a>
                <a href="#s9" class="numbers" rel="panel">8</a>
                <a href="#s10" class="numbers" rel="panel">9</a>
                
                <a href="#s6" class="next">NEXT</a>
                
                </div>
                <!-- **** NEXT/PREV **** -->
                
                </div>
                <!-- **** Screen Five **** -->
                
                <!-- **** Screen Six **** -->
                <div id="s6" class="screen">
        
        		<h2>5.	If yes, what would be your reasons for buying this drink? (Tick as many as you agree with.)</h2>
                
                <div class="qarea5">
                <label>It's refreshing</label><input name="q5[]" type="checkbox" class="check3" value="Its refreshing" />
                <label>It's healthy</label><input name="q5[]" type="checkbox" class="check3" value="Its healthy" />
                <label>Aloe vera cotents</label><input name="q5[]" type="checkbox" class="check3" value="Aloe vera cotents" />
                <label>Low in sugar</label><input name="q5[]" type="checkbox" class="check3" value="Low in sugar" />
                </div>
                <div class="qarea5a">
                <label>I like the taste</label><input name="q5[]" type="checkbox" class="check3" value="I like the taste" />
                <label>It’s different</label><input name="q5[]" type="checkbox" class="check3" value="Its different" />
                <label>It’s new</label><input name="q5[]" type="checkbox" class="check3" value="Its new" />
                </div>
                
                <!-- **** NEXT/PREV **** -->
                <div id="butts">
        
                <a href="#s5" class="prev">PREV</a>
                
                <a href="#s1" class="numbers" rel="panel" style="margin-left:110px;">start</a>
                <a href="#s2" class="numbers" rel="panel">1</a>
                <a href="#s3" class="numbers" rel="panel">2</a>
                <a href="#s4" class="numbers" rel="panel">3</a>
                <a href="#s5" class="numbers" rel="panel">4</a>
                <a href="#s6" class="numbers" rel="panel">5</a>
                <a href="#s7" class="numbers" rel="panel">6</a>
                <a href="#s8" class="numbers" rel="panel">7</a>
                <a href="#s9" class="numbers" rel="panel">8</a>
                <a href="#s10" class="numbers" rel="panel">9</a>
                
                <a href="#s7" class="next">NEXT</a>
                
                </div>
                <!-- **** NEXT/PREV **** -->
                
                </div>
                <!-- **** Screen Six **** -->
                
                <!-- **** Screen Seven **** -->
                <div id="s7" class="screen">
        
        		<h2>6.	Would you recommend this drink to people<br />you know?</h2>
                
                <div class="qarea4">
                <label>Yes</label><input name="q6[]" type="checkbox" class="check" value="Yes" />
                <label>Maybe</label><input name="q6[]" type="checkbox" class="check" value="Maybe" />
                <label>No</label><input name="q6[]" type="checkbox" class="check" value="No" />
                <label>Don't Know</label><input name="q6[]" type="checkbox" class="check" value="Dont Know" />
                </div>
                
                <!-- **** NEXT/PREV **** -->
                <div id="butts">
        
                <a href="#s6" class="prev">PREV</a>
                
                <a href="#s1" class="numbers" rel="panel" style="margin-left:110px;">start</a>
                <a href="#s2" class="numbers" rel="panel">1</a>
                <a href="#s3" class="numbers" rel="panel">2</a>
                <a href="#s4" class="numbers" rel="panel">3</a>
                <a href="#s5" class="numbers" rel="panel">4</a>
                <a href="#s6" class="numbers" rel="panel">5</a>
                <a href="#s7" class="numbers" rel="panel">6</a>
                <a href="#s8" class="numbers" rel="panel">7</a>
                <a href="#s9" class="numbers" rel="panel">8</a>
                <a href="#s10" class="numbers" rel="panel">9</a>
                
                <a href="#s8" class="next">NEXT</a>
                
                </div>
                <!-- **** NEXT/PREV **** -->
                
                </div>
                <!-- **** Screen Seven **** -->
                
                <!-- **** Screen Eight **** -->
                <div id="s8" class="screen">
        
        		<h2>7.	Do you have any other feedback about<br />this product?</h2>
                <textarea cols="" rows="" name="q7" wrap="physical"></textarea>
                
                <!-- **** NEXT/PREV **** -->
                <div id="butts">
        
                <a href="#s7" class="prev">PREV</a>
                
                <a href="#s1" class="numbers" rel="panel" style="margin-left:110px;">start</a>
                <a href="#s2" class="numbers" rel="panel">1</a>
                <a href="#s3" class="numbers" rel="panel">2</a>
                <a href="#s4" class="numbers" rel="panel">3</a>
                <a href="#s5" class="numbers" rel="panel">4</a>
                <a href="#s6" class="numbers" rel="panel">5</a>
                <a href="#s7" class="numbers" rel="panel">6</a>
                <a href="#s8" class="numbers" rel="panel">7</a>
                <a href="#s9" class="numbers" rel="panel">8</a>
                <a href="#s10" class="numbers" rel="panel">9</a>
                
                <a href="#s9" class="next">NEXT</a>
                
                </div>
                <!-- **** NEXT/PREV **** -->
                
                </div>
                <!-- **** Screen Eight **** -->
                
                <!-- **** Screen Nine **** -->
                <div id="s9" class="screen">
        
        		<h2>8.	How old are you?</h2>
                
                <div class="qarea4">
                <label>0-16</label><input name="q8[]" type="checkbox" class="check" value="0 to 16" />
                <label>17-25</label><input name="q8[]" type="checkbox" class="check" value="17 to 25" />
                <label>26-35</label><input name="q8[]" type="checkbox" class="check" value="26 to 35" />
                <label>36-49</label><input name="q8[]" type="checkbox" class="check" value="36 to 49" />
                <label>50-Over</label><input name="q8[]" type="checkbox" class="check" value="50 and Over" />
                </div>
                
                <!-- **** NEXT/PREV **** -->
                <div id="butts">
        
                <a href="#s8" class="prev">PREV</a>
                
                <a href="#s1" class="numbers" rel="panel" style="margin-left:110px;">start</a>
                <a href="#s2" class="numbers" rel="panel">1</a>
                <a href="#s3" class="numbers" rel="panel">2</a>
                <a href="#s4" class="numbers" rel="panel">3</a>
                <a href="#s5" class="numbers" rel="panel">4</a>
                <a href="#s6" class="numbers" rel="panel">5</a>
                <a href="#s7" class="numbers" rel="panel">6</a>
                <a href="#s8" class="numbers" rel="panel">7</a>
                <a href="#s9" class="numbers" rel="panel">8</a>
                <a href="#s10" class="numbers" rel="panel">9</a>
                
                <a href="#s10" class="next">NEXT</a>
                
                </div>
                <!-- **** NEXT/PREV **** -->
                
                </div>
                <!-- **** Screen Nine **** -->
                
                <!-- **** Screen Ten **** -->
                <div id="s10" class="screen">
                <!-- Show Message for AJAX response -->
			<div id="insert_response"></div>
        
        		<h2>9.	Are you?</h2>
                
                <div class="qarea4">
                <label>Male</label><input name="q9[]" type="checkbox" class="check" value="Male" />
                <label>Female</label><input name="q9[]" type="checkbox" class="check" value="Female" />
                </div>
                
                <input type="submit" name="submit" value="Submit Survey" class="complete"/>
                
                <!-- **** NEXT/PREV **** -->
                <div id="butts">
        
                <a href="#s9" class="prev">PREV</a>
                
                <a href="#s1" class="numbers" rel="panel" style="margin-left:110px;">start</a>
                <a href="#s2" class="numbers" rel="panel">1</a>
                <a href="#s3" class="numbers" rel="panel">2</a>
                <a href="#s4" class="numbers" rel="panel">3</a>
                <a href="#s5" class="numbers" rel="panel">4</a>
                <a href="#s6" class="numbers" rel="panel">5</a>
                <a href="#s7" class="numbers" rel="panel">6</a>
                <a href="#s8" class="numbers" rel="panel">7</a>
                <a href="#s9" class="numbers" rel="panel">8</a>
                <a href="#s10" class="numbers" rel="panel">9</a>
                
                <a href="#" class="next">NEXT</a>
                
                </div>
                <!-- **** NEXT/PREV **** -->
                
                </div>
                <!-- **** Screen Ten **** -->
        
        </div>
        <!-- **** Container **** -->
        </form>

</div>
<!-- **** Scroll Window **** -->

</div>
<!-- **** Wrapper **** -->
</body>
</html>

 

thanks

 

Craig

 

Link to comment
Share on other sites

<form action="<?php echo $PHP_SELF;?>" method="post">
        
        		<h2>1.	Which flavour(s) did you try?</h2>
                
                <div class="qarea1">
                <input type="checkbox" class="styled" />
                <input type="checkbox" class="styled" />
                <input type="checkbox" class="styled" />
                <input type="checkbox" class="styled" />
                <label>Aloe Vera Lime (dark green)</label><input name="q1[]" type="checkbox" class="check" value="Lime" />
                <label>Aloe Vera White Grape (pale green)</label><input name="q1[]" type="checkbox" class="check" value="Grape" />
                <label>Aloe Vera Apple (white)</label><input name="q1[]" type="checkbox" class="check" value="Apple" />
                </div>
        
        		<h2>2.	Please rate the following (1-5):</h2>
                
                <p class="opt1">Strongly Dislike</p>
                <p class="opt2">Dislike</p>
                <p class="opt3">Neither Dislike or Like</p>
                <p class="opt4">Like</p>
                <p class="opt5">Like Alot</p>
                
                <div class="qarea2">
                <label>Packaging</label><input name="q2[]" type="checkbox" class="check2" value="Packaging - Strongly Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Packaging - Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Packaging - Neither" /><input name="q2[]" type="checkbox" class="check2" value="Packaging - Like" /><input name="q2[]" type="checkbox" class="check2" value="Packaging - Like Alot" />
                <label>Flavour</label><input name="q2[]" type="checkbox" class="check2" value="Flavour - Strongly Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Flavour - Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Flavour - Neither" /><input name="q2[]" type="checkbox" class="check2" value="Flavour - Like" /><input name="q2[]" type="checkbox" class="check2" value="Flavour - Like Alot" />
                <label>Aloe Vera Pieces</label><input name="q2[]" type="checkbox" class="check2" value="Pieces - Strongly Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Pieces - Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Pieces - Neither" /><input name="q2[]" type="checkbox" class="check2" value="Pieces - Like" /><input name="q2[]" type="checkbox" class="check2" value="Pieces - Like Alot" />
                <label>How the drink looks</label><input name="q2[]" type="checkbox" class="check2" value="Looks - Strongly Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Looks - Dislike" /><input name="q2[]" type="checkbox" class="check2" value="Looks - Neither" /><input name="q2[]" type="checkbox" class="check2" value="Looks - Like" /><input name="q2[]" type="checkbox" class="check2" value="Looks - Like Alot" />
                </div>
        
        		<h2>3.	Which of the following words do you think describe this drink? (Tick as many as you agree with.)</h2>
                
                <div class="qarea3">
                <label>Refreshing</label><input name="q3[]" type="checkbox" class="check3" value="Refreshing" />
                <label>Fruity</label><input name="q3[]" type="checkbox" class="check3" value="Fruity" />
                <label>Lumpy</label><input name="q3[]" type="checkbox" class="check3" value="Lumpy" />
                <label>Juicy</label><input name="q3[]" type="checkbox" class="check3" value="Juicy" />
                <label>Light</label><input name="q3[]" type="checkbox" class="check3" value="Light" />
                <label>Fresh</label><input name="q3[]" type="checkbox" class="check3" value="Fresh" />
                </div>
                <div class="qarea3a">
                <label>Healthy</label><input name="q3[]" type="checkbox" class="check3" value="Healthy" />
                <label>Cooling</label><input name="q3[]" type="checkbox" class="check3" value="Cooling" />
                <label>Unusual</label><input name="q3[]" type="checkbox" class="check3" value="Unusual" />
                <label>Chewy</label><input name="q3[]" type="checkbox" class="check3" value="Chewy" />
                <label>Don't Know</label><input name="q3[]" type="checkbox" class="check3" value="Dont Know" />
                <label>Other</label><input name="q3[]" type="checkbox" class="check3" value="Other" />
                </div>
        
        		<h2>4.	Would you buy this drink?</h2>
                
                <div class="qarea4">
                <label>Yes</label><input name="q4[]" type="checkbox" class="check" value="Yes" />
                <label>Maybe</label><input name="q4[]" type="checkbox" class="check" value="Maybe" />
                <label>No</label><input name="q4[]" type="checkbox" class="check" value="No" />
                <label>Don't Know</label><input name="q4[]" type="checkbox" class="check" value="Dont Know" />
                </div>
        
        		<h2>5.	If yes, what would be your reasons for buying this drink? (Tick as many as you agree with.)</h2>
                
                <div class="qarea5">
                <label>It's refreshing</label><input name="q5[]" type="checkbox" class="check3" value="Its refreshing" />
                <label>It's healthy</label><input name="q5[]" type="checkbox" class="check3" value="Its healthy" />
                <label>Aloe vera cotents</label><input name="q5[]" type="checkbox" class="check3" value="Aloe vera cotents" />
                <label>Low in sugar</label><input name="q5[]" type="checkbox" class="check3" value="Low in sugar" />
                </div>
                <div class="qarea5a">
                <label>I like the taste</label><input name="q5[]" type="checkbox" class="check3" value="I like the taste" />
                <label>It’s different</label><input name="q5[]" type="checkbox" class="check3" value="Its different" />
                <label>It’s new</label><input name="q5[]" type="checkbox" class="check3" value="Its new" />
                </div>
        
        		<h2>6.	Would you recommend this drink to people<br />you know?</h2>
                
                <div class="qarea4">
                <label>Yes</label><input name="q6[]" type="checkbox" class="check" value="Yes" />
                <label>Maybe</label><input name="q6[]" type="checkbox" class="check" value="Maybe" />
                <label>No</label><input name="q6[]" type="checkbox" class="check" value="No" />
                <label>Don't Know</label><input name="q6[]" type="checkbox" class="check" value="Dont Know" />
                </div>
        
        		<h2>7.	Do you have any other feedback about<br />this product?</h2>
                <textarea cols="" rows="" name="q7" wrap="physical"></textarea>
        
        		<h2>8.	How old are you?</h2>
                
                <div class="qarea4">
                <label>0-16</label><input name="q8[]" type="checkbox" class="check" value="0 to 16" />
                <label>17-25</label><input name="q8[]" type="checkbox" class="check" value="17 to 25" />
                <label>26-35</label><input name="q8[]" type="checkbox" class="check" value="26 to 35" />
                <label>36-49</label><input name="q8[]" type="checkbox" class="check" value="36 to 49" />
                <label>50-Over</label><input name="q8[]" type="checkbox" class="check" value="50 and Over" />
                </div>
        
        		<h2>9.	Are you?</h2>
                
                <div class="qarea4">
                <label>Male</label><input name="q9[]" type="checkbox" class="check" value="Male" />
                <label>Female</label><input name="q9[]" type="checkbox" class="check" value="Female" />
                </div>
                
                <input type="submit" name="submit" value="Submit Survey" class="complete"/>
                
                </form>

Link to comment
Share on other sites

If you want the answers seperated by commas

$q1 = mysql_real_escape_string(implode(' ',',',$_POST["q1"]));
$q2 = mysql_real_escape_string(implode(' ',',',$_POST["q2"]));
$q3 = mysql_real_escape_string(implode(' ',',',$_POST["q3"]));
$q4 = mysql_real_escape_string(implode(' ',',',$_POST["q4"]));
$q5 = mysql_real_escape_string(implode(' ',',',$_POST["q5"]));
$q6 = mysql_real_escape_string(implode(' ',',',$_POST["q6"]));
$q7 = mysql_real_escape_string(implode(' ',',',$_POST["q7"]));
$q8 = mysql_real_escape_string(implode(' ',',',$_POST["q8"]));
$q9 = mysql_real_escape_string(implode(' ',',',$_POST["q9"]));

Link to comment
Share on other sites

Hi Sorry,

 

Im a newbie to submitting to DB's and cant figure out what i need at the top of my page so that it actually sends my form...

 

this is what i have at the minute but i just get a qhite page

 


<?php
if(isset($_GET['submit']))

include "connect.php";

$tableName = "results";

$q1 = mysql_real_escape_string(implode(' ',',',$_GET["q1"]));
$q2 = mysql_real_escape_string(implode(' ',',',$_GET["q2"]));
$q3 = mysql_real_escape_string(implode(' ',',',$_GET["q3"]));
$q4 = mysql_real_escape_string(implode(' ',',',$_GET["q4"]));
$q5 = mysql_real_escape_string(implode(' ',',',$_GET["q5"]));
$q6 = mysql_real_escape_string(implode(' ',',',$_GET["q6"]));
$q7 = mysql_real_escape_string(implode(' ',',',$_GET["q7"]));
$q8 = mysql_real_escape_string(implode(' ',',',$_GET["q8"]));
$q9 = mysql_real_escape_string(implode(' ',',',$_GET["q9"]));

$add_all = "INSERT INTO $tableName (id,qone,qtwo,qthree,qfour,qfive,qsix,qseven,qeight,qnine) VALUES ('','$q1','$q2','$q3','$q4','$q5','$q6','$q7','$q8','$q9')");
mysql_query($add_all) or die(mysql_error());

?>

 

Link to comment
Share on other sites

Hi, change this >>>

 

<?php
include "connect.php";
$tableName = "results";
$q1 = $_POST["q1"];
$q2 = $_POST["q2"];
$q3 = $_POST["q3"];
$q4 = $_POST["q4"];
$q5 = $_POST["q5"];
$q6 = $_POST["q6"];
$q7 = $_POST["q7"];
$q8 = $_POST["q8"];
$q9 = $_POST["q9"];
$insert = mysql_query("INSERT INTO $tableName (id,qone,qtwo,qthree,qfour,qfive,qsix,qseven,qeight,qnine)
VALUES ('','$q1','$q2','$q3','$q4','$q5','$q6','$q7','$q8','$q9')") or die(mysql_error());
?>

 

to >>>

<?php
include "connect.php";
function showMyResults($a) {
  $array = $_POST["$a"];
  $count = count($_POST["$a"]);
   $i = 0;
   $v = 0;
   while($i<$count)
     {
     if ($i == 0)
      $output .= $array[$i];
      else
      $output .= ", ".$array[$i];
      $i++;
      }
      return $output;      }
$tableName = "results";
$q1 = showMyResults(q1);
$q2 = showMyResults(q2);
$q3 = showMyResults(q3);
$q4 = showMyResults(q4);
$q5 = showMyResults(q5);
$q6 = showMyResults(q6);
$q7 = $_POST["q7"];
$q8 = showMyResults(q8);
$q9 = showMyResults(q9);
if (isset($_GET["submit"]))
$insert = mysql_query("INSERT INTO $tableName (qone,qtwo,qthree,qfour,qfive,qsix,qseven,qeight,qnine)
VALUES ('$q1','$q2','$q3','$q4','$q5','$q6','$q7','$q8','$q9')") or die(mysql_error());
?>

 

Also Change >>>

<form action="<?php echo $PHP_SELF;?>" method="post">

To >>>

<form action="<?php echo $PHP_SELF;?>?submit" method="post">

This will stop the script trying to insert rows when it doesn't have any data.

 

I would also suggest changing some of your check boxes to radio buttons else you will have multiple answers when only one is necessary.

How I have currently changed your code will show multiple selections e.g Male and Female in the DB if both boxes are checked.

 

Alex

Link to comment
Share on other sites

$q6 = showMyResults(q6); // -> this calls the funtion that converts arrays (multiple options e.g checkboxes) into a string
$q7 = $_POST["q7"]; // -> this calls the result directly

 

Radio buttons can only have 1 option selected so you would call for the result directly using

$q7 = $_POST["q7"];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.