We help IT Professionals succeed at work.

Trying to insert radio button value into mysql database

mnoel76 asked
Last Modified: 2013-12-12

I am trying to insert the value of a radio button into mysql database.  I thought it would be rather easy but I am running into an error.  I have attached snippets of the code from my form and from mysql insert statement into my database.  When I click the 'Create Account' button I am getting the following errors dependent on the radio button selected.  

Unknown column 'realtor' in 'field list'
Unknown column 'renter' in 'field list'

This should be a rather easy fix but I am stuck. Your help is appreciated.  If you need some other information please let me know.  

here is the structure of the field 'acctype'
acctype  varchar(15)   Yes  NULL    
code within the form
<tr valign="baseline"> 
<td align="right" valign="middle" nowrap class="colText">* Type of Account:</td>
<td class="rowText">
     <input type="radio" name="acctype"  value="realtor" /> Realtor/Property Manager/Owner<br />
    <input type="radio" name="acctype"  value="renter" /> Buyer/Renter</td>
////Mysql insert statement
$insertSQL = sprintf("INSERT INTO members (name, address, city, `state`, zip, active, email, password, `acctype`, phone, fax, created, companyname, companywebsite) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, DATE_ADD(NOW(),INTERVAL 0 DAY), %s, %s)",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['address'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['state'], "text"),
                       GetSQLValueString($_POST['zip'], "text"),
                       GetSQLValueString($_POST['active'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['acctype'], "radio"),
                       GetSQLValueString($_POST['phone'], "text"),
					   GetSQLValueString($_POST['fax'], "text"),
					   GetSQLValueString(date("Y-m-d"), "date"),
					   GetSQLValueString($_POST['companyname'], "text"),
					   GetSQLValueString($_POST['companywebsite'], "text"));
  mysql_select_db($database_myconn, $myconn);
  $Result1 = mysql_query($insertSQL, $myconn) or die(mysql_error());

Open in new window

Watch Question

Top Expert 2004

Unless GetSQLValueString puts quotes around text elements, you may need to put quotes around all %s in your query.


I don't follow your comment.  Initially I did not have `acctype` in the mysql statement.  I originally had acctype.  But still can you explain your suggestion.  The insert statement was working before I added the radio button to the statement and form.

Thanks for your input.
Top Expert 2004
This one is on us!
(Get your first solution completely free - no credit card required)
This one is on us!
(Get your first solution completely free - no credit card required)
Top Expert 2004

The other thing you can do is echo $insertSQL after it is set. That should give you an idea if quotes are your problem.



I had "text" initially in the mysql statement and it did not work or at least I thought it did not.  I did as you suggested and changed it back to "text" and it is working...weird.  thanks!  I am going to award points accordingly.  

Thank you to both for your quick replies.  Stay tuned to some more questions.


thank you both for your input.  Zyloch I think you were on the right direction however pmessana beat you to it.  thanks again

In the future, the quickest and easiest way to solve these issues is to do the following:

echo $insertSQL;

Then take that query and attempt to run it in mySQL.  It will help you to see the syntax issues and solve them quicker without having to give up your points ;)

Thanks for the points!


I generally do troubleshoot by printing it to the screen.  But for some reason I did not this time, I think I was a little distracted and tired.  Thanks for the input!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.