Search
Left Quote    Maybe this world is another planet's Hell.
- Aldous Huxley    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: $post is not working for Comment Script
  This user is online  Guest
  Subject: "$post is not working for Comment Sc..." Posted: @ 9:17 pm on Sep 13 2005   
Unregistered
the page just refreshs after i enter in code, but the URl doesnt have #comments at the end, and the comments do not appear... my code is below... can you help?

I also found that the info fromt he form is not being posting into my sql table - it is currently empty even after i try to submit. thanks in advance. if you need any more info, post here or email me at ccagle8 (at) yahoo dot com

example of where i am trying to implement this:
http://pghsourc e.cagintranet.c om/directory/de tails.php?c=694


Code:
<?
//connect to your database
include("c onfig.php"< img src=/forums/ima ges/smilies/win k.gif border=0>;
mysql_connect($ mysql_hostname, $mysql_user, $mysql_password );
@mysql_select_d b($mysql_databa se) or die( "Unable to select database";

//query comments for this page of this article
$inf = "SELECT * FROM `comments` WHERE page = '".stripsl ashes($_SERVER[ 'REQUEST_URI']) ."' ORDER BY time ASC";
$info = mysql_query($in f);
if(!$info) die(mysql_error ());

$info_rows = mysql_num_rows( $info);
if($info_rows > 0) {
echo '<h5>Comm ents:</h5> ;';
echo '<table width="95% ">';

while($info2 = mysql_fetch_obj ect($info)) {
echo '<tr>';
echo '<td>&quo t;'.stripslashe s($info2->su bject).'" by: <a

href="'.$i nfo2->contac t.'">'. stripslashes($i nfo2->userna me).'</a> </td> <td><d iv align="rig ht"> @ '.date('h:i:s a',

$info2->time ).' on '.$info2->da te.'</div> ;</td>';
echo '</tr>< ;tr>';
echo '<td colspan="2 "> '.stripslashes( $info2->comm ent).' </td>';
echo '</tr>';
}//end while
echo '</table> ';
echo '<hr width="95% " noshade>';
} else echo 'No comments for this page. Feel free to be the first <br><b r>';

if(isset($_POST ['submit'])) {
if(!addslashes( $_POST['usernam e'])) die('<u>E RROR:</u> you must enter a username to add a comment.');
if(!addslashes( $_POST['contact '])) die('<u>E RROR:</u> enter contact method in contact field.');
if(!addslashes( $_POST['subject '])) die('<u>E RROR:</u> enter a subject to your comment.');
if(!addslashes( $_POST['comment '])) die('<u>E RROR:</u> cannot add comment if you do not enter one!?');


//this is for a valid contact
if(substr($_POS T['contact'],0, 7) != 'mailto:' && !strstr($_POST[ 'contact'],'//' )) {
if(strstr($_POS T['contact'],'@ '))
$_POST['contact '] = "mailto:&q uot;.$_POST['co ntact']."& quot;;
else
$_POST['contact '] = "http://&q uot;.$_POST['co ntact']."& quot;;
} //end valid contact

//try to prevent multiple posts and flooding...
$c = "SELECT * from `comments` WHERE ip = '".$_SERVE R['REMOTE_ADDR' ]."'" ;
$c2 = mysql_query($c) ;
while($c3 = mysql_fetch_obj ect($c2)) {
$difference = time() - $c3->time;
if($difference < 300) die('<u>A LERT:</u> '.$c3->usern ame.', You have already commented earlier; if you have a

question, try the forums!<BR&g t;');
} //end while

//add comment
$q ="INSERT INTO `comments` (article_id, page, date, time, username, ip, contact, subject, comment) VALUES

('".$_GET[ 'id']."', '".$_POST[ 'page']."' , '".$_POST[ 'date']."' , '".$_POST[ 'time']."' ,

'".addslas hes(htmlspecial chars($_POST['u sername'])).&qu ot;', '".$_SERVE R['REMOTE_ADDR' ]."',

'".addslas hes(htmlspecial chars($_POST['c ontact'])).&quo t;', '".addslas hes(htmlspecial chars($_POST['s ubject'])).&quo t;',

'".addslas hes(htmlspecial chars(nl2br($_P OST['comment']) ))."')&quo t;;

$q2 = mysql_query($q) ;
if(!$q2) die(mysql_error ());

//refresh page so they can see new comment
header('Locatio n: http://' . $_SERVER['HTTP_ HOST'] . $_POST['page'] . "#comments ";

} else { //display form
?>
<form name="comm ents" action="&l t;? $_SERVER['PHP_S ELF']; ?>" method="po st">

<input type="hidd en" name="page " value="< ;? echo($_SERVER[' REQUEST_URI']); ?>">
<input type="hidd en" name="date " value="< ;? echo(date(" ;F j, Y."); ?>">
<input type="hidd en" name="time " value="< ;? echo(time()); ?>">

<table width="76% " border="0& quot; cellspacing=&qu ot;0" cellpadding=&qu ot;0">
<tr>
<td><i nput name="user name" type="text " size="45&q uot; value="&qu ot; style="fon t-size: 8pt; font-family: Verdana"&g t;<font

size="1&qu ot;>
Username</ font></td >
</tr>
<tr>
<td><i nput type="text " name="subj ect" size="45&q uot; value="&qu ot; style="fon t-size: 8pt; font-family: Verdana"&g t;<font

size="1&qu ot;>
Subject</fo nt></td&g t;
</tr>
<tr>
<td><t extarea name="comm ent" style="fon t-size: 8pt; font-family: Verdana" cols="44&q uot; rows="8&qu ot;

wrap="VIRT UAL">&l t;/textarea> <font size="1&qu ot;>
Comment</f ont></td& gt;
</tr>
<tr>
<td><i nput type="hidd en" name="cont act" size="30&q uot; value="htt p://www.cagintr anet.com"& gt;</td>
</tr>
<tr>
<td><i nput type="subm it" name="subm it" value="Sub mit Review"> ; <input type="rese t" value="Cle ar">< ;/td>
</tr>
</table>
</form>
<?
} // end else
?>



    Viewed: 9,267 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: $post is not working for Commen..." Posted: @ 1:32 am on Sep 13 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

I think I found a problem. It has to do with ob_start(); or "output before headers error".
in the script to which you're displaying comments (details.php) in your case, make sure the very first line of this script is: ob_start(); Of couse, open with <? for php code. But right after that, put ob_start(); because look:

http://pghsour ce.cagintranet. com/directory/c omment.php

it might fix the problems but if not post back again. Because even if you dont enter anything, its not tripping errors for blank fields.




-bs0d | AllSyntax.com

    Viewed: 9,218 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: $post is not working for Commen..." Posted: @ 2:00 am on Sep 13 2005    
Unregistered

Thanks! but sorry, that code addition didnt work. below is the code of my details.php page. Do you think it may be because i am calling information from two different tables in the same database? Thanks for taking your time here... I know it shoddy code, but i am moving everything around to try and make it work... i will clean it up when i get everything working correctly. If this works, it is a great script... easily the best mysql comments script out there. Thanks!

Chris



Edited at 03:22:23 am on 09/16/05

    Viewed: 9,214 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: $post is not working for Commen..." Posted: @ 2:12 am on Sep 13 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

The comment script itself is working. go to :

http://pghsour ce.cagintranet. com/directory/c omment.php and post a test comment, works flawlessly.

This tells me, the problem is outside the comments script.

This might not have anything to do with it, but I notice at the beginning of your script:


Code:


<?
ob_start();
include(" config.php&quo t;;
mysql_connect($ mysql_hostname, $mysql_user, $mysql_password );
@mysql_select_d b($mysql_databa se) or die( "Unable to select database" ;
$query="S ELECT * FROM dir_pages WHERE id='$c'" ;;
$result=mysql_q uery($query);
$num=mysql_numr ows($result);
mysql_close();



In your query, you have WHERE id ='$c' .... but prior to that, $c is not set. $c should = $_GET['c']; right?

Edit: Great news, looks like you've got it working- I tested it on the page, and it works.



Edited at 11:28:47 pm on 09/14/05


-bs0d | AllSyntax.com

    Viewed: 9,211 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: $post is not working for Commen..." Posted: @ 1:20 am on Sep 15 2005    
Unregistered

bsod,

Thanks for your help... but i found what the problem was. I was doing an include <? include(" http://www.cagi ntranet.com/pgh source/director y/comment.php& quot; ?> and it wasnt working.

I replaced the include with the code from the comments page directly, and now it works.

thank you very much for a very useful script, and all the support youve given me. thank you.

Chris

PS. bs0d - now that i think of it... is there anyway you can remove my code of the details.php file from this thread? you can leave what you deem relevant so that it may help others, but its probably not the best to leave my source code out there in the open. Thank you!



    Viewed: 9,193 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: $post is not working for Commen..." Posted: @ 3:20 am on Sep 15 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

No problem, I am glad you found the script useful. I will edit your post and remove the code. Thanks




-bs0d | AllSyntax.com

    Viewed: 9,190 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank