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
https://forums.phpfreaks.com/topic/39377-whats-wrong-with-this-code/
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);

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.

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.

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.