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
https://forums.phpfreaks.com/topic/194401-please-help-me/
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
https://forums.phpfreaks.com/topic/194401-please-help-me/#findComment-1022631
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
https://forums.phpfreaks.com/topic/194401-please-help-me/#findComment-1022634
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.