corillo181 Posted February 20, 2007 Share Posted February 20, 2007 <? 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.. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 20, 2007 Share Posted February 20, 2007 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); Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 20, 2007 Author Share Posted February 20, 2007 thats not it.. it make sno difference.. it just dont go to put the new row if there isn't one to update. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 20, 2007 Share Posted February 20, 2007 mysql_query() will always return a result unless there was an error, so you will always have an $insert. What are you trying to do? It's a little unclear. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 20, 2007 Author Share Posted February 20, 2007 yeah the insert part works fine.. is the update query wich i'm trying to make it work.. so how can i make it so if the row is not updated a ne wone is inserted? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 20, 2007 Share Posted February 20, 2007 With the code you have it will always be inserted, so just don't do the update. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 20, 2007 Author Share Posted February 20, 2007 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 20, 2007 Share Posted February 20, 2007 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. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted February 21, 2007 Author Share Posted February 21, 2007 becasue i need the count to put it in different pages, but i think i got a idea that can work.. i will check to see if the id of the picture is in mysql if not insert it, if it is update it.. mysql_count_row should work for that. Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 its not mysql_count_row but its mysql_num_rows Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.