Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2010
    Location
    Maine
    Posts
    32
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Unhappy I go to my comments test page, but php sends me to index but it shouldn't? PHP error?

    I've been working on a comment script, and I have finally gotten it to work. HOWEVER, whenever I type in the test page in my browser, it brings me to the homepage of the site I'm working on with the extension #comments, which is what the SHOULD be added to the form page I submit the form, but I can't get to the form page. I'm unable to test the rest of my php script because of this... here is the script, and the reload function is near the end by the form. Can you look through it and tell me what I did that might cause that?

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
        <meta http-equiv="content-type" content="text/html; carset=utf-8" /> 
        <meta name="description" content="A research collaboration on the country Russia and its totalitarian roots for a jYork group project stemming from George Orwell's 1984." />
        <meta name="keywords" content="russia, totalitarian, research, george orwell, 1984, regime, soviet union, USSR, project" />
        <title>The Russia Project- A YorkBrit 1984 Research Collaboration</title>
        <link rel="stylesheet" type="text/css" href="trp.css" />
    </head>
    <body>
        <img class="bgimg" src="ussr and russia flag.png" alt="" />
    <div class="wrap">
    <div class="header">
        <img class="headerimg" src="trpheader.png" alt="The Russia Project: A YorkBrit 1984 Research Collaboration" />
    </div>
    <div class="menubar">
        <table class="menubar" cellpadding="0px" cellspacing="0px">
            <tr>
                <td id="leftendcap">&nbsp;</td>
                <td>
                    <a href="index.html" id="home"><span>Home</span></a>
                </td>    
                <td>
                    <a href="ussr.html" id="ussr"><span>U.S.S.R.</span></a>
                </td>
                <td>
                    <a href="russia.html" id="russia"><span>Russia</span></a>
                </td>
                <td>
                    <a href="workscited.html" id="workscited"><span>Works Cited</span></a>
                </td>
                <td id="rightendcap">&nbsp;</td>
            </tr>
        </table>
    </div>
    <div class="content"> 
        <h1 class="page-title">COMMENT TEST PAGE</h1>
            <br />
            <hr id="article_comment_break" noshade />
    <?php
    require_once($_SERVER['DOCUMENT_ROOT']. '/database_connect.php');
    //querying comments for this article
    $inf "SELECT * FROM `comments` WHERE page = '".stripslashes($_SERVER['REQUEST_URI'])."' ORDER BY time";
    $info mysql_query($inf) or die ( mysql_error() );
    if(  
    mysql_num_rows$info ) != ) {
        echo 
    '<h3 class="comments">Comments:</h3>';
        echo 
    '<table class="comments">';
        while ( 
    $info2 mysql_fetch_object$info ) ) {
            echo 
    '<tr>';
            echo 
    '<td>'.htmlspecialchars(stripslashes($info2->subject)).'" by: <a href="'.$info2->contact.'">'.htmlspecialchars(stripslashes($info2->username)).'</a></td><td><div> @'.date('h:is a'$info2->time).' on '.$info2->date.'</div></td>';
            echo 
    '</tr><tr>';
            echo 
    '<td colspan="2"> '.htmlspecialchars(stripslashes(nl2br($info2->comment))).' </td>';
            echo 
    '</tr>';
        } 
    // end while
        
    echo '</table>';
        echo 
    '<hr noshade width="500px" align="center" />';
    }  
    else echo 
    'No comments for this page. Feel free to be the first. <br />';
    if (isset(
    $_POST['submit'])) {
        if(!
    addslashes($_POST['username'])) {
            die(
    '<u>ERROR:</u> You must enter an alias to comment.');
        }
        if(!
    addslashes($_POST['contact'])) {
            die(
    '<u>ERROR:</u> Please enter an email or URL to comment.');
        }
        if(!
    addslashes($_POST['subject'])) {
            die(
    '<u>ERROR:</u> Please give your comment a subject.');
        }
        if(!
    addslashes($_POST['comment'])) {
            die(
    'You <u>must</u> enter a comment in order to comment (DUH!).');
        }
    }
    // this is for a valid contact
        
    if(substr($_POST['contact'],0,7) != 'mailto:' && !strstr($_POST['contact'],'//')) {
            
    $_POST['contact'] = "mailto:".$_POST['contact']."";
        }
        else {
            
    $_POST['contact'] = "http://".$_POST['contact']."";
        }
        
    // end valid contact

    //add comment
    $q "INSERT INTO `comments` (id, page, subject, username, contact, comment, ip, date, time) VALUES ('".$_GET['id']."', '".$_POST['page']."', '".addslashes(htmlspecialchars($POST['subject']))."', '".addslashes(htmlspecialchars($_POST['username']))."', '".addslashes(htmlspecialchars($_POST['contact']))."', '".addslashes(nl2br(htmlspecialchars($_POST['comment'])))."', '".$_SERVER['REMOTE_ADDR']."', '".$_POST['date']."', '".$_POST['time']."')";
    $q2 mysql_query($q);
        if(!
    $q2) {
            die(
    mysql_error());
        }

    //refresh page so they can see new comment
    header('Location: http://' $_SERVER['HTTP_HOST'] . $_POST['page'] . "#comments");

    ?>

    <form name="comments" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
        <input type="hidden" name="page" value="<?php echo($_SERVER['REQUEST_URI']); ?>">
        <input type="hidden" name="date" value="<?php echo(date()); ?>">
        <input type="hidden" name="date" value="<?php echo(time()); ?>">
        <div class="form_fields">
            <label>Alias:</label><input type="text" name="username" size="30"><br />
            <label>Subject:</label><input type="text" name="subject" size="30"><br />
            <label>Email or URL:</label><input type="text" name="contact" size="30"><br />
            <label>Message:</label><textarea name="comment" rows="5" cols="24"></textarea><br />
            <input type="submit" value="Post Comment" />
        </div>
    </form>
    </div>
    <div class="footer">
        <p class="footer">Design &copy;2010 Scriptech Designs &bull; Content &copy;2010 YorkBrit English 11-4</p>
    </div>
    </div>
    </body>
    </html>
    Any insight on what could cause that will be greatly appreciated. Oh, I also want to know if the parentheses on the echo statements within the first three form inputs is okay (I've tried it with ' or ", but both return errors....). Thanks in advance.
    Last edited by deflipp; 04-22-2010 at 07:32 AM. Reason: changed title to fit questoin better

  • #2
    New Coder
    Join Date
    Apr 2010
    Location
    Maine
    Posts
    32
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Fixed that... now the form input is not sending info to the database...

    Okay, I fixed my problem... I finished an if statement too early. HOWEVER, when I try the form, the page refreshes with no comments and then my table in MySQL has no data except the IP number..... what is wrong with my declaration of $q (which is the "write to database" declaration)?

    PHP Code:
    //add comment
        
    $q "INSERT INTO `comments` (id, page, subject, username, contact, comment, ip, date, time) VALUES ('".$_GET['id']."', '".$_POST['page']."', '".addslashes(htmlspecialchars($POST['subject']))."', '".addslashes(htmlspecialchars($_POST['username']))."', '".addslashes(htmlspecialchars($_POST['contact']))."', '".addslashes(nl2br(htmlspecialchars($_POST['comment'])))."', '".$_SERVER['REMOTE_ADDR']."', '".$_POST['date']."', '".$_POST['time']."')";
        
    $q2 mysql_query($q);
        if(!
    $q2) {
            die(
    mysql_error());
        } 
    it is posting SOMETHING, since the die command is not being triggered, but it's posting blank values. Is there something wrong with the way I declared everything? only the

    PHP Code:
    '".$_SERVER['REMOTE_ADDR']."' 
    code bit is working correctly (and, of course, the "id" one... but that is an automatically determined value from the MySQL table). Can you look at this bit and the full code above to tell me what it is that is messed up?

  • #3
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    This shouldn't be the beginning and the end of your problem, but you have overlooked the underscore for $_POST in the subject part of the query:

    PHP Code:
    $q "INSERT INTO `comments` (id, page, subject, username, contact, comment, ip, date, time) VALUES ('".$_GET['id']."', '".$_POST['page']."', '".addslashes(htmlspecialchars($_POST['subject']))."', '".addslashes(htmlspecialchars($_POST['username']))."', '".addslashes(htmlspecialchars($_POST['contact']))."', '".addslashes(nl2br(htmlspecialchars($_POST['comment'])))."', '".$_SERVER['REMOTE_ADDR']."', '".$_POST['date']."', '".$_POST['time']."')"
    Also, "time" is not one of your form fields (you named two fields as "date"). Fixing that will still leave "date" blank since you are mis-using the date() function. You need to do something like echo date("m/d/Y",time()); instead.

    Other than that the query should be building correctly. Have you double-checked your database field names for consistency/spelling with what is in your PHP code?
    Last edited by Rowsdower!; 04-22-2010 at 01:47 PM.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #4
    New Coder
    Join Date
    Apr 2010
    Location
    Maine
    Posts
    32
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Actually, that wasn't the end of my problem... but that particular question had been answered. I asked a different question on another thread and the problem is now resolved (meaning my comment system finally works). Thank you for your help though... it is greatly appreciated!

    EDIT:
    You won't believe it, but my whole issue mainly stemmed from not declaring the name of the submit input, meaning a whole block of code wasn't being executed.... DUH...... Sometimes the little things get overlooked, and I had been working on this from 11:00pm to 4:00pm for about three nights, so the error was bound to be made.....
    Last edited by deflipp; 04-22-2010 at 05:22 PM. Reason: adding something


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •