Jump to content

Radio Button Values Won't Post to SQL DB


laticca8

Recommended Posts

Hello, all. I have a form with radio buttons. I typically don't use them and thought I would take the time to figure them out this time. The values won't post to the database. Please let me know what I'm doing wrong here. The joint field is a yes/no question with 2 radio buttons:

 

My form has this code:

<table border="0" width="100%" id="table13">

<tr>

<td>Is this a joint application (more than one borrower)?</td>

<td>

<input id="j1" type="radio" value="yes" name="joint" tabindex="2">

Yes <input id="j2" type="radio" value="no" name="joint">

No</td>

</tr>

</table>

 

My action file has this code (upon user clicking submit):

 

<?php

if ($_POST["sent"] == "Submit")

{

$DBhost = "localhost";

$DBuser = "user";

$DBpass = "pwod";

$DBName = "test";

$table = "apply";

$id = $_POST['id'];

$referral=$_POST['referral'];

$joint=array('yes','no');

$joint=$_POST['joint'];

 

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

 

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

 

$sqlquery = "INSERT INTO $table VALUES('$id','$referral','$joint',NOW())";

 

$results = mysql_query($sqlquery);

 

mysql_close();

}

?>

 

My SQL table has the following fields:

 

id

referral

joint

date

 

Thanks for your help!

Link to comment
Share on other sites

Did you forget to include your form tags and your submit button when you posted, or are they missing altogether?

 

The other thing you should do is check mysql_query() for errors.

 

$results = mysql_query($sqlquery) or die("Query failed: $sqlquery\n" . mysql_error()); 

Link to comment
Share on other sites

thanks for your response.  yes, if have the form tag and submit.  i've done forms several times in php, but i always avoided radio buttons because of the headache.  i may just have to change them over to the checkbox.  there are just so many of them that i would rather figure out how to fix it.  ok, i'll add the error check.

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.