Jump to content

Mysql Help Needed (haha, once again, this time serious)


Recommended Posts

Project: Comment System.
Problem: Will not post comment, had some errors before but fixed, now I just get a mysql_error().

Code:

[code]
<? ob_start(); ?>
<? include('header.php'); ?>
<?php
$id = $_GET[id];
$act = $_POST[action];
include('smiley.func.php');

if(!$id && !$act){
echo "Sorry, you did not specify an ID";
}else
if($act == add){
$name = $_POST[name];
$mess = $_POST[message];
$neid = $_POST[id];
$time = $_POST[time];
$date = $_POST[date];
if(empty($name) || empty($mess)){
echo "Please fill in all the fields";
}else {
smileys();
$cam = "SELECT camount FROM `news` WHERE id =$neid";
$car = mysql_query($cam) or die(mysql_error());
$cas = mysql_fetch_assoc($car);
$amc = $cas[camount];
$nac = "$amc + 1";

$adC = "INSERT INTO `comments` (`poster`,`message`,`time`,`date`,`newsid`) VALUES('$name','$message','$time','$date','$neid')";
$adR = mysql_query($adC) or die(mysql_error());
$upCa= "UPDATE `news` SET camount =$nac WHERE id =$neid";
$upCr= mysql_query($upCa) or die(mysql_error());
echo "Your comment has been successfully added, <a href=comments.php?id=$neid>click here</a> to return to the comments";
};
}else {

//check if news id exists
$cheID = "SELECT * FROM `news` WHERE id =$id";
$cheRes = mysql_query($cheID);
$cheNum = mysql_numrows($cheRes);
$cheAsc = mysql_fetch_assoc($cheRes);
$comAlv = $cheAsc[comments];
if($cheNum > 0){

//will echo comments if they exist
$com = "SELECT * FROM `comments` WHERE newsid =$id";
$res = mysql_query($com);
$cnm = mysql_numrows($res);
if($comAlv == 2){
echo "Comments have been disabled for this news article";
}else
if($cnm == 0){
echo "No comments for this news article you can add one below";
}else if($cnm > 0 && $comAlv == 1){
while ($row1 = mysql_fetch_assoc($res, MYSQL_BOTH)){
print "<table border=0 cellspacing=2 cellpadding=1>";
print "<tr><td align=left>Posted by $row1[poster] on $row1[date] at $row1[time]";
print "<tr><td colspan=2 align=left valign=top>$row1[message]";
}
mysql_free_result($res);
}
}else {
echo "The ID specified does not exist";
};
if($comAlv == 1){
//echo out comment add table
echo "<br><br>";
echo "<table border=0 cellspacing=2 cellpadding=2>";
echo "<form action=$_SERVER[PHP_SELF] name=add method=post>";
echo "<tr><td colspan=2 align=right><h3>Add A Comment";
echo "<tr><td>Name:<td><input type=text name=name>";
echo "<tr><td>Smileys:<td><a href=".'javascript:openwindow()'.">Open</a>";
echo "<tr><td>Message:<td><textarea name=message rows=4 cols=17></textarea>";
echo "<tr><td colspan=2 align=left><input type=hidden name=action value=add><input type=hidden name=newsid value=$id>";
echo "<input type=submit value='Add Comment'>";
echo "</form></table>";
}




};

?>
<? require('footer.php'); ?>
<? ob_end_flush(); ?>
[/code]


mysql_error():

[code]
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 '' at line 1
[/code]
one of your post or get variables is somehow not being passed. therefore, in your query, it is doing like

"select * from table where blah="

sql is looking at that and wondering what blah equal to.  echo out all your get and posted variables.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.