nimzrocks Posted March 7, 2010 Share Posted March 7, 2010 Hello my friends I need to build a email questionnaire form. I need to use some radio buttons as well. As a example I have this php code and form but I do not know how to send radio button data to my database. So I did like this, but radio button data is saving as "0" Can you please how to do this properly? this is my form <form action="insert.php" method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <table width="100%" border="1"> <tr> <td>What is your First Car ?</td> <td> <p> <label> <input type="radio" name="q3" value="Honda" id="q3_0" /> Honda</label> <br /> <label> <input type="radio" name="q3" value="Sunny" id="q3_1" /> Sunny</label> <br /> <label> <input type="radio" name="q3" value="Bluebird" id="q3_2" /> Bluebird</label> <br /> </p></td> </tr> </table> <input type="submit" /> </form> and this my insert page <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydatabase", $con); $sql="INSERT INTO emailquestionnaire (FirstName, LastName, Age, q3) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]','$_POST[q3]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Thank you Quote Link to comment https://forums.phpfreaks.com/topic/194401-please-help-me/ Share on other sites More sharing options...
wildteen88 Posted March 7, 2010 Share Posted March 7, 2010 How have you setup your database schema? Your code is fine, although placing raw _POST data into your query is not recommended, as it can lead to sql injection attacks. You should look into sanitizing your users input before adding it to your database. Quote Link to comment https://forums.phpfreaks.com/topic/194401-please-help-me/#findComment-1022631 Share on other sites More sharing options...
nimzrocks Posted March 7, 2010 Author Share Posted March 7, 2010 Thank for your reply this is my table code CREATE TABLE `database`.`emailquestionnaire` ( `id` INT NOT NULL AUTO_INCREMENT , `firstname` INT( 30 ) NOT NULL , `lastname` INT( 30 ) NOT NULL , `age` INT NOT NULL , `q3` INT NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = MYISAM ; Quote Link to comment https://forums.phpfreaks.com/topic/194401-please-help-me/#findComment-1022634 Share on other sites More sharing options...
wildteen88 Posted March 7, 2010 Share Posted March 7, 2010 You've setup your q3 field as INT. You'll want to set it to VARCHAR instead. To change the type run this query ALTER TABLE `database`.`emailquestionnaire` MODIFY `q3` VARCHAR(100) Quote Link to comment https://forums.phpfreaks.com/topic/194401-please-help-me/#findComment-1022635 Share on other sites More sharing options...
nimzrocks Posted March 7, 2010 Author Share Posted March 7, 2010 Thank you very much bro, now its working There will be 25 questions and I'm going to add (q1,q2,q3,.....q25) to every question. Is it all right ? Quote Link to comment https://forums.phpfreaks.com/topic/194401-please-help-me/#findComment-1022638 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.