I am attempting to send the data from a set of radio buttons to my MySQL Database so that I am able to get people to review the site.
When I did my initial test with a single radio button in a test database all went well, however when I added more I am getting an unusual error. It works when I comment out the other values and leave only one to be inserted into the database, but unless that happens I get the errors.

My HTML is:

<form action='../Action/Improv.php' method='POST'>
				<table>
				<tr>
				<td> First Impressions: </td>
				<td>
1<input type='radio' name='Impressions' value = "1" >
2<input type='radio' name='Impressions' value = "2" >
3<input type='radio' name='Impressions' value = "3" >
4<input type='radio' name='Impressions' value = "4" >
5<input type='radio' name='Impressions' value = "5" > <br><br>
				</tr>
				<tr>
				<td> Appearance: </td>
				<td>
1<input type='radio' name='Appearance' value = "1" >
2<input type='radio' name='Appearance' value = "2" >
3<input type='radio' name='Appearance' value = "3" >
4<input type='radio' name='Appearance' value = "4" >
5<input type='radio' name='Appearance' value = "5" > <br><br>
				</tr>
				<tr>
				<td> Ease of Use: </td>
				<td>
1<input type='radio' name='Use' value = "1" >
2<input type='radio' name='Use' value = "2" >
3<input type='radio' name='Use' value = "3" >
4<input type='radio' name='Use' value = "4" >
5<input type='radio' name='Use' value = "5" > <br><br>
				</tr>

				<td> Content: </td>
				<td>
1<input type='radio' name='Content' value = "1" >
2<input type='radio' name='Content' value = "2" >
3<input type='radio' name='Content' value = "3" >
4<input type='radio' name='Content' value = "4" >
5<input type='radio' name='Content' value = "5" > <br><br>
				</tr>
				
				<tr>
				<td> Other Comments: </td>
				<td>
<textarea rows = "15" cols = "50" input type='text' name='Comments' maxlength = "1000" ></textarea></td>
				</tr>
				
				<tr>
				<td id = "Repeat"> Repeat: </td>
				<td id = "Repeat"> <input type ='text' name='Repeat' >
				</tr>
				</table>

				<br><br><input type='submit' name = "Submit" value='Submit'> <br><br>
			</form>

And my PHP Code is:

<?php

	//Collect User Input from Form

	$Impressions = $_POST['Impressions'];

	$Appearance = $_POST['Appearance'];

	$Use = $_POST['Use'];

	$Content = $_POST['Content'];

	$UComments = $_POST['Comments'];

	$Repeat = $_POST['Repeat'];

	$Date = date("Y/m/d H:i:s");


		//If Repeat Is Filled - BOT WARNING

		if ($Repeat) {

			die ("BOT WARNING - ACCESS DENIED");

		} else {

			//Replace Non-Accepted Characters

			$CComments = preg_replace('/[^a-zA-Z0-9\,\.\@\!\?\s  ]/','*',$UComments);

			//Connect to the Database
		
			mysql_connect("localhost", "root", "pass") or die("Error Connecting to SQL");
			mysql_select_db("myDB") or die("Error Connecting to the Database");

			//Prevent Code From Executing
		
			$Comments = mysql_real_escape_string($CComments);

			//Enter Data Into Database

			$query = mysql_query("INSERT INTO Improv (ID, Impressions, Appearance, Use, Content, Comments, Date) VALUES 
			('NULL','$Impressions','$Appearance','$Use','$Content','$Comments','$Date')") or die (mysql_error());
	
	} 
?>

The error I recieve is when I tell PHP to display the problem at

$query = mysql_query("INSERT INTO Improv (ID, Impressions, Appearance, Use, Content, Comments, Date) VALUES 
			('NULL','$Impressions','$Appearance','$Use','$Content','$Comments','$Date')") or die (mysql_error());
	
	}

And the error is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Use, Content, Comments, Date) VALUES ('NULL','5','4','3','2','The design is ' at line 1

I am rather new to PHP and I am slightly confused about this, could someone please point me as to what the error means and how I would fix it? Thank you.

Use is a mysql reserved word, use backticks.

Try using mysql_real_escape_string. You may be inserting a special character that messes up your PHP code. Try

$query = mysql_query('INSERT INTO Improv (
ID, 
Impressions, 
Appearance, 
Use, 
Content, 
Comments, 
Date
) VALUES (
NULL, 
"' . mysql_real_escape_string($Impressions) . '",
"' . mysql_real_escape_string($Appearance',
"'  mysql_real_escape_string($Use) . '",
"' . mysql_real_escape_string($Content) . '",
"' . mysql_real_escape_string($Comments) . '",
"' . mysql_real_escape_string($Date) . '"
)') or die (mysql_error());

Or maybe it's what pritaeas says ^^. // Edit: damn I'm a newb, must be what he says :).

Use is a mysql reserved word, use backticks.

So simple, thanks for pointing out the error. I need to watch out for those more often! Rapid reply as well!

Or maybe it's what pritaeas says ^^. // Edit: damn I'm a newb, must be what he says :).

Have more knowledge than me :P

New problem, the original error has gone and the rest of the data goes into it however that column in my database (new name of it is Test, for testing) won't accept any data. I have changed all the occurances of the original name in the database to the new name and I have even rebuilt the table in my database.

It just won't add any data to it! Any ideas?

New problem, the original error has gone and the rest of the data goes into it however that column in my database (new name of it is Test, for testing) won't accept any data. I have changed all the occurances of the original name in the database to the new name and I have even rebuilt the table in my database.

It just won't add any data to it! Any ideas?

Ok, this one was more my stupidity, missed out the <td> on my HTML Form... all works now!
Thanks for all the help, really appreciated.

This thread is officially solved!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.