Jump to content

Please Help me


nimzrocks

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ;

 

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.