Bullet Posted April 20, 2009 Share Posted April 20, 2009 $topic_info=mysql_fetch_object(mysql_query("SELECT * FROM topics WHERE id='$topic' AND forum='$forum'")); if ($topic_info->sticky == "1" || $topic_info->important == "1"){ $lastreplytime = $topic_info->lastreply; }elseif ($topic_info->sticky == "0" || $topic_info->important == "0"){ $lastreplytime = time(); } $date = gmdate('Y-m-d h:i:s'); mysql_query("INSERT INTO `replys` (`id`, `username`, `text`, `forum`, `idto`,`made`) VALUES ('', '$username', '$reply_text', '$forum', '$topic','$date');"); echo"You posted a reply in the topic titled: $topic_info->title."; } This is in a PHP document. The MySQL isn't posting the $lastreply. Anyone know why? Thanks. Link to comment https://forums.phpfreaks.com/topic/154845-solved-php-mysql-help/ Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 I don't know how picky MySQL can be when it comes to inserting dates & times but I'd change this line: $date = gmdate('Y-m-d H:i:s'); h doesn't add a leading zero whereas H does. I'd also try this: mysql_query("INSERT INTO `replys` (`username`, `text`, `forum`, `idto`,`made`) VALUES ('$username', '$reply_text', '$forum', '$topic','$date');"); I removed the ID field. If you've got it set to AUTO_INCREMENT sending an empty string ('') may confuse it - never tried it to be honest as I've either removed the ID (like I have here) or used NULL like this: mysql_query("INSERT INTO `replys` (`id`, `username`, `text`, `forum`, `idto`,`made`) VALUES (NULL, '$username', '$reply_text', '$forum', '$topic','$date');"); Link to comment https://forums.phpfreaks.com/topic/154845-solved-php-mysql-help/#findComment-814383 Share on other sites More sharing options...
Bullet Posted April 20, 2009 Author Share Posted April 20, 2009 Doesn't work, It inserts a row into the DB, but the $lastreply doesn't change. I think it's this bit: if(strip_tags($_POST['Submit']) && strip_tags($_POST['reply_text'])){ $reply_text = addslashes(strip_tags($_POST['reply_text'])); $topic_info=mysql_fetch_object(mysql_query("SELECT * FROM topics WHERE id='$topic' AND forum='$forum'")); if ($topic_info->sticky == "1" || $topic_info->important == "1"){ $lastreplytime = $topic_info->lastreply; }elseif ($topic_info->sticky == "0" || $topic_info->important == "0"){ $lastreplytime = time(); Any idea's? Link to comment https://forums.phpfreaks.com/topic/154845-solved-php-mysql-help/#findComment-814387 Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 Best thing to do is ECHO some data to the browser so you can see what's going on inside your queries a little easier. Second, if you post code inside [code] and [/code] you can help anyone trying to help you as it preserves formatting and color codes certain items. If your code doesn't contain <?php or ?> then you can use [php] and [/php] tags like this: <?php echo 'I can use CODE tags here'; ?> echo 'I can use PHP tags here'; Link to comment https://forums.phpfreaks.com/topic/154845-solved-php-mysql-help/#findComment-814389 Share on other sites More sharing options...
Bullet Posted April 20, 2009 Author Share Posted April 20, 2009 if(strip_tags($_POST['Submit']) && strip_tags($_POST['reply_text'])){ $reply_text = addslashes(strip_tags($_POST['reply_text'])); $topic_info=mysql_fetch_object(mysql_query("SELECT * FROM topics WHERE id='$topic' AND forum='$forum'")); if ($topic_info->sticky == "1" || $topic_info->important == "1"){ $lastreplytime = $topic_info->lastreply; }elseif ($topic_info->sticky == "0" || $topic_info->important == "0"){ $lastreplytime = time(); Theres something wrong with the $lastreply. I maybe the if ($topic_info->sticky == "1" || $topic_info->important == "1"){ Any help/idea's? Link to comment https://forums.phpfreaks.com/topic/154845-solved-php-mysql-help/#findComment-814393 Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 No idea as that's a small proportion of code and I'm leaving work very soon. As I mentioned earlier, place lots of ECHO statements throughout your code in tactical places to see what data is being handled. Link to comment https://forums.phpfreaks.com/topic/154845-solved-php-mysql-help/#findComment-814396 Share on other sites More sharing options...
Bullet Posted April 20, 2009 Author Share Posted April 20, 2009 I tried a longer way around it: if(strip_tags($_POST['Submit']) && strip_tags($_POST['reply_text'])){ $reply_text = addslashes(strip_tags($_POST['reply_text'])); $topic_info=mysql_fetch_object(mysql_query("SELECT * FROM topics WHERE id='$topic' AND forum='$forum'")); if ($topic_info->sticky == "1" || $topic_info->important == "1"){ $lastreplytime = $topic_info->lastreply; $date = gmdate('Y-m-d h:i:s'); mysql_query("INSERT INTO `replys` (`id`, `username`, `text`, `forum`, `idto`,`made`) VALUES (NULL, '$username', '$reply_text', '$forum', '$topic','$date');"); echo"You posted a reply in the topic titled: $topic_info->title."; }elseif ($topic_info->sticky == "0" || $topic_info->important == "0"){ $lastreplytime = time(); mysql_query("INSERT INTO `replys` (`id`, `username`, `text`, `forum`, `idto`,`made`) VALUES (NULL, '$username', '$reply_text', '$forum', '$topic','$date');"); echo"<center>You posted a reply in the topic titled: $topic_info->title."; Is this easier to work with and figure out whats wrong? Link to comment https://forums.phpfreaks.com/topic/154845-solved-php-mysql-help/#findComment-814404 Share on other sites More sharing options...
Bullet Posted April 20, 2009 Author Share Posted April 20, 2009 I got it, I missed out a MySQL. Lol sorry if I wasted your time. I didn't update the topic with the $lastreplytime Link to comment https://forums.phpfreaks.com/topic/154845-solved-php-mysql-help/#findComment-814409 Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 Certainly no waste of time - you got it fixed which is the main thing! Link to comment https://forums.phpfreaks.com/topic/154845-solved-php-mysql-help/#findComment-814411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.