I added 1 field to a PHP form, a checkbox and now the data no longer gets posted to the DB.
Here's the form code:
<form method="post" action="weeklynews_created.php" onsubmit="return validateForm()" name="createForm">
<p class="header-blue" style="margin-top:0px; margin-bottom:10px">
Create a weekly news entry:<br />
<span class="tburgundy">* required fields</span>
</p>
<b>Category*:</b><br />
<input name="category" type="radio" value="30"> News
<input name="category" type="radio" value="33"> Analysis
<input name="category" type="radio" value="34"> My Business
<input name="category" type="radio" value="35"> Product News
<input name="show" type="checkbox" checked> Show on web site
<table border="0" cellspacing="2" cellpadding="4">
<tr>
<td rowspan="2" valign="top" bgcolor="#99CCFF">
<b>Title*:</b><br />
<input type="Text" size="50" name="title" value=""><br />
<b>Summary*:</b><br />
<textarea name="description" rows="5" cols="48">
</textarea>
<br /><br />
<b>Body*:</b><br />
<textarea name="body" rows="20" cols="48">
</textarea>
</td>
<td valign="top" bgcolor="#eeeeee">
<b>Publish date*</b><br />
(Format YYYY-MM-DD):<br />
<input type="Text" size="10" name="date_archive" value="" maxlength="10">
<br />
<b>Rank:</b><br />
0 will be at the top, then 1, 2, etc.<br />
<input type="Text" size="10" name="page" value="" maxlength="10">
<br />
<b>Product Alert id:</b><br />
<input type="Text" size="10" name="id_ext" value="" maxlength="10">
</td>
</tr>
<tr>
<td valign="bottom" bgcolor="#CCCCCC">
<input type="Submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
Here's the processing code:
<?
include(CONNECTION SCRIPT");
include("template_topnl.inc");
$db = mysql_connect($host,$user,$password)
or die ( mysql_error() );
mysql_select_db($database,$db)
or die ( mysql_error() );
// escaping the quotes for insertion into DB
$st_title = addslashes($title);
$st_description = addslashes($description);
$st_body = addslashes($body);
if ($submit)
{
// creates a new entry
$sql = "INSERT INTO mag_toc
(title,description,body,category,date_archive,page,id_ext,type,show)
VALUES
('$st_title','$st_description','$st_body','$category','$date_archive','$page','$id_ext','nl','$show')";
// run SQL against the DB
$result = mysql_query($sql);
echo "<p class=\"header-blue\" style=\"margin-top:0px; margin-bottom:20px\">Record created!</p>".$sql;
}
include("template_bottom.inc");
?>
Here's the query:
INSERT INTO mag_toc (title,description,body,category,date_archive,page,id_ext,type,show) VALUES ('Test Yes','Test Yes','Test Yes','30','2005-10-17','','','nl','on')
And I get this error:
SQL query:
INSERT INTO mag_toc( title, description, body, category, date_archive, page, id_ext,
TYPE ,
SHOW ) VALUES (
'Test Yes', 'Test Yes', 'Test Yes', '30', '2005-10-17', '', '', 'nl', 'on'
)
MySQL said:
#1064 - You have an error in your SQL syntax near 'show) VALUES ('Test Yes','Test Yes','Test Yes','30','2005-10-17','','','nl','on'' at line 1
I really can't figure out where the problem comes from. Any help welcome.