I have most of my comment system done, but I am having problems with the posting to database for some reason. It keeps saying: Error: You have an error in yoru SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax use near " at line 1.
I think it is because of me trying to send nid. It doesnt seem to be posting it. If you would like to see for yourself try here: http://www.omniboggle.com/ then comment on the first post and just put in jibberish.
Here is the code for comments.php
<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
if (isset($_POST['submit'])){
if ($dbc = @mysql_connect ('localhost', '*****', '*****')){
if (!@mysql_select_db('omniboggle')){
die('<p>1. Error</p>');
}
} else {
die ('<p>2. Error</p>');
}
$query = "INSERT INTO comment (id, name, n_id, n_title, comment, date_entered)
VALUES (0, '{$_POST[name]}', '{$_POST[nid]}', '{$_POST['title']}', '{$_POST['comment']}', NOW())";
if (@mysql_query($query)){
$success = true;
} else {
$success = false;
echo "3Error: " . mysql_error() . "";
}
mysql_close();
echo "$success";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Justin Girdler's Portfolio :: Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="style/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="770" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="10"> </td>
<td colspan="2" valign="bottom" class="brdrtop"> </td>
<td width="10"> </td>
</tr>
<tr>
<td width="10" rowspan="3" class="brdrleft"> </td>
<td width="750" height="100" colspan="2" class="banner"> </td>
<td width="10" rowspan="3" class="brdrright"> </td>
</tr>
<tr>
<td colspan="2" class="navbox"><font class="navbox" id="nav"><a href="index.php">Home</a> :: <a href="portfolio.php">Portfolio</a> :: <a href="about.php">About</a> :: <a href="lab.php">Lab</a></font></td>
</tr>
<tr>
<td width="225" class="side">
<?php
require('side.php');
$nid = $_GET['nid'];
//echo "$nid";
?>
</td>
<td width="525" height="500" align="center" valign="top" class="contentarea">
<div class="contentholder">
<div class="contenttitle"><font id="title"><?php echo "" . gtitle($nid) . "";?>:</font></div>
<div class="content"><font id="content">
<form>
<input name="nid" type="hidden" value="<?php $nid; ?>">
<table width="384" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="70" height="29">Name:</td>
<td width="314" align="right">
<div align="center">
<input name="name" type="text" id="name" size="50">
</div></td>
</tr>
<tr>
<td height="32">Heading:</td>
<td align="right">
<div align="center">
<input name="title" type="text" id="title" size="50">
</div></td>
</tr>
<tr>
<td height="75">Comment:</td>
<td align="right">
<div align="center">
<textarea name="comment" cols="36" rows="3" id="comment"></textarea>
</div></td>
</tr>
<tr>
<td> </td>
<td align="right">
<div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
</form>
</font></div>
</div>
</td>
</tr>
<tr>
<td width="10"> </td>
<td colspan="2" class="brdrbottom"> </td>
<td width="10"> </td>
</tr>
</table>
</body>
</html>
Here is function gtitle()
function gtitle($nid)
{
error_reporting (E_ALL & ~E_NOTICE);
if ($dbc = @mysql_connect('localhost', '****', '****')){
if (!$dbc = @mysql_select_db('omniboggle')){
die('<p>Error: ' . mysql_error() . '</p>');
}
} else {
die('<p>Error: ' . mysql_error() . '</p>');
}
$query = "SELECT title FROM news WHERE id = $nid";
if ($r = mysql_query($query)){
while ($row = mysql_fetch_array($r)){
$title = $row['title'];
}
} else {
die('<p>Error: ' . mysql_error() . '</p>');
}
mysql_close();
return $title;
}
Thanks!