Jump to content

ABOUT INSERTING DATA USING RADIO BUTTONS


giba

Recommended Posts

Hi, Freak Addicted!

 

I have a form to input data into my database, and recently wanted to add a radio button to improve service, but now I can't add anything to my database.

 

(I'd like to make clear that other variables used before were working fine.

 

I am trying to use these radio buttons to insert yes/no to a new field of my database (client):

 

                      Client:<input name="client" type="radio" value="yes" />

                      Non-client:<input name="client" type="radio" value="no" />

                   

And I have this code into my insertion page: (I summarized taking away other fields keeping just the new one here)

 

<?php

mysql_connect($conn);

$cliente=$_POST['client'];

mysql_select_db($database) or die( "Your are not connected to database!");

$query = "INSERT INTO form VALUE ('$client')";

mysql_close();

?>

 

I read a lot of explanations about this but none helped!

 

Please, someone could help me!? :)

Link to comment
https://forums.phpfreaks.com/topic/39641-about-inserting-data-using-radio-buttons/
Share on other sites

Might be working but unless the form table has only one field in it, this line is wrong

 

$query = "INSERT INTO form VALUE ('$client')";

 

The query will insert that into the first field of the table. Possibly going into the wrong field

 

use this

$query = "INSERT INTO form (`fieldname`) VALUES ('$client')";

 

change fieldname to the field you want to insert it into

 

Ray

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.