mnoel76
asked on
Trying to insert radio button value into mysql database
Hello,
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
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>
</tr>
////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());
Unless GetSQLValueString puts quotes around text elements, you may need to put quotes around all %s in your query.
ASKER
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.
Thanks for your input.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The other thing you can do is echo $insertSQL after it is set. That should give you an idea if quotes are your problem.
ASKER
pmessana,
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.
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.
ASKER
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;
exit();
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!
echo $insertSQL;
exit();
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!
ASKER
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!