Jump to content

[SOLVED] PHP MYSQL help


Bullet

Recommended Posts

$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

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');");

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?

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';

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?

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?

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.