Jump to content

whats wrong with this code?


corillo181

Recommended Posts

<?
if(isset($_POST['Submit'])){
// insertint the comment
$insert=mysql_query("INSERT INTO tra_pcomment(photo_id,user_id,userpic_id,album_id,comment,datetime,name)VALUES('$foto_id','$user_id','$userpic_id','".$_GET['a']."','".$_POST['pcoment']."','$date','".$_POST['name']."')")or die(mysql_error());
if($insert){
$udcount=mysql_query("UPDATE tra_comment_count SET count=(count+1) WHERE photo_id=$foto_id");
if(!$udcount){
$cc=mysql_query("INSERT INTO tra_comment_count(photo_id,album_id,path,count)VALUES('$foto_id','".$_GET['a']."','1')")or die("Error inserting count of comment");
header('Location:'.$back);
}
}
}

?>

 

it doesn't insert the new row if there is not previous count on the picture..

the $cc query never happenes..

Link to comment
Share on other sites

because your not actually running the query you are just storing the sql in a variable.

change it to:

mysql_query("INSERT INTO tra_comment_count(photo_id,album_id,path,count)VALUES('$foto_id','".$_GET['a']."','1')")or die("Error inserting count of comment");
header('Location:'.$back);

Link to comment
Share on other sites

i got a picture wich people can comment on it..

 

what the code has to do, is once the comment is insert it, update the count ..wich would be +1.. there for giving me the number of how many comment a single picture has when ever i want to check on it

 

now if the is not count to update+1

 

i want a new row for that picture to be set with a coutn of 1.

Link to comment
Share on other sites

You need to proofread before posting.

"now if the is not count to update+1"

What?

 

Why don't you just store the comment count as a field in the picture table, and start it at zero, then just update it when one is made. Then you don't have to check anything.

Link to comment
Share on other sites

  • 2 weeks later...
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.