Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-08-2013, 11:08 PM   PM User | #16
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
the entire source (excluding static info such as <head>,<title>, etc)
PHP Code:
<div id="leftcontent">
    <?php 
    
//News articles start
    
$news mysql_query("SELECT * FROM `news` ORDER BY `date` DESC LIMIT 10");
    while(
$article mysql_fetch_array($news)) { 
        
$articlePosted $article['date'];
        
$datePosted date("F jS, Y"strtotime($articlePosted));
        if (empty(
$_GET['id'])) { 
            echo 
'<div class="box3">';
            echo 
'<article><header><h2>'.$article['article_name']. '</h2></header>';
            echo 
'<p>' .$article['summary']. '</p>';
            echo 
'<p>' .$datePosted'</p>';
            echo 
"<a class='special' href='/news?id={$article['id']}'>Read More...</a></article></div>";
        } else if (
$_GET['id'] == $article['id']) {
            echo 
'<section><article><header><h1 class="centered"><b><u>'.$article['article_name']. '</u></b></h1></header>';
            echo 
'<p>' .$article['news']. '</p>';
            echo 
'<footer><p>' .$datePosted.  '</p></footer></section>';
            echo 
'<section><h1 class="centered">Comments</h1></article>';
            
//Comments start
            
$getComments mysql_query("SELECT * FROM `comments` WHERE `category` = 'news' AND `subcategory` = '$article[id]' ORDER BY `date` DESC LIMIT 20");
            while(
$comments mysql_fetch_array($getComments)) {
                echo 
"<br />";
                echo 
"<div class='box'>";
                if (
$comments['reply_to'] > 0) {
            
$get_comment mysql_query("SELECT * FROM `comments` WHERE `id` = $comments[reply_to]");
            while(
$r_comment mysql_fetch_array($get_comment)) {
            echo 
"<i><p>Originally posted by " .$r_comment[username]. '</p></i>';
            echo 
"<i><p> " .$r_comment[comment]. '</p></i>';
            echo 
"<i><p> " .Agotime($r_comment[date]). '</p></i>';
            echo 
"<hr />";
  }
  }
        echo 
"<p>" .$comments[username]. '</p>';
        echo 
"<p>" .$comments[comment]. '</p>';
        echo 
"<p>" .Agotime($comments[date]). '</p>';
        echo 
"<a class='special' href=\"/news?id={$article['id']}&reply={$comments['id']}\"> Reply</a>";
        
//Replies start
    
if ($_GET['reply'] == $comments['id']) {
    echo 
"
    <form action=\"/news?id={$article['id']}\" method='POST'>
    <input class='field' type='text' name='name' placeholder='Name' required='true' />
    <br />
    <textarea class='field' name='comment' rows='2' cols='55' required='true'></textarea>
    <input type='hidden' name='submitted' value='1' />
    <input type='hidden' name='reply' value=\"{$comments['id']}\" />
    <input class='specialbutton' type='submit' name='submit' value='Post Comment' />
    </form>"
;
    }
    echo 
"<br />
    </div>"
;
    
//Replies end
    
}
    echo 
"
    <br />
    <div class='box'>
    <form action=\"/news?id={$article['id']}\" method='POST'>
    <input class='field' type='text' name='name' placeholder='Name' required='true' />
    <br />
    <textarea class='field' name='comment' rows='2' cols='55' required='true'></textarea>
    <input class='specialbutton' type='submit' name='submit' value='Post Comment' />
    <input type='hidden' name='submitted' value='1' />
    </form>
    </div>
    </section>"
;
    
//Comments end
    
if ($_POST['submitted'] == 1) {
    if (
function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
        
$_POST['name'] = stripslashes($_POST['name']);
        
$_POST['comment'] = stripslashes($_POST['comment']);
        
$_POST['reply'] = stripslashes($_POST['reply']);
    }
$username mysql_real_escape_string($_POST['name']);
$comment mysql_real_escape_string($_POST['comment']);
$category 'news';
$subcategory $article['id'];
$reply mysql_real_escape_string($_POST['reply']);
if (empty(
$username)) {
echo 
"<p>Name is a required field</p>";
exit();
}
if (empty(
$comment)) {
echo 
"<p>Comment is a required field</p>";
exit();
}

$sql "INSERT INTO `comments` (`username`, `comment`, `date`, `category`, `subcategory`, `reply_to`) VALUES ('$username','$comment', NOW(), '$category', '$subcategory', '$reply')";

if (!
mysql_query($sql)) {
  die(
'Error: ' mysql_error());
  }
  }
    }
    
//News articles end
        
}
    
?>
    </div>
Edit: After updating error reporting, got this error: Notice: Undefined index: submitted in /home1/elitis/public_html/news/index.php on line 98.But 'submitted' has been defined...
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps

Last edited by elitis; 01-08-2013 at 11:20 PM..
elitis is offline   Reply With Quote
Old 01-08-2013, 11:37 PM   PM User | #17
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You'll get that as well as other errors depending on whether you have provided get and post. Since you have no checks for isset, it will always trigger when attempting to read.

Where are you opening the connection to the database here? From what you have here you shouldn't even be able to reach the form.
Fou-Lu is offline   Reply With Quote
Old 01-08-2013, 11:45 PM   PM User | #18
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
include "../includes/database.php"; separate file. And to answer your previous question: no, no connection errors whatsoever
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps
elitis is offline   Reply With Quote
Old 01-08-2013, 11:50 PM   PM User | #19
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
What's in the $_POST array when you've submitted the form? HTML5 at least with FF seems to be happy with input elements after the submit button, but I'm pretty sure in the past that was an issue.
Fou-Lu is offline   Reply With Quote
Old 01-09-2013, 12:06 AM   PM User | #20
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
$_POST['name'], $_POST['comment'], $_POST['submit'] and $_POST['submitted'] (input type='hidden' value='1')
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps
elitis is offline   Reply With Quote
Old 01-09-2013, 12:18 AM   PM User | #21
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
That's not my question.
PHP Code:
var_dump($_POST);
// may as well add in the get but it looks pretty straight forward
var_dump($_GET); 
What does that have when you have submitted the form. What you think in there versus what is is likely the problem.
Fou-Lu is offline   Reply With Quote
Old 01-09-2013, 09:46 PM   PM User | #22
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
That's not my question.
PHP Code:
var_dump($_POST);
// may as well add in the get but it looks pretty straight forward
var_dump($_GET); 
What does that have when you have submitted the form. What you think in there versus what is is likely the problem.
oh lol, my mistake. You meant values; I'm not getting anything.
PHP Code:
$sql "INSERT INTO `comments` (`username`, `comment`, `date`, `category`, `subcategory`, `reply_to`) VALUES ('$username','$comment', NOW(), '$category', '$subcategory', '$reply')";

var_dump($_POST);
// may as well add in the get but it looks pretty straight forward
var_dump($_GET);

if (!
mysql_query($sql)) {
  die(
'Error: ' mysql_error());
  } 
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps
elitis is offline   Reply With Quote
Old 01-10-2013, 12:00 AM   PM User | #23
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
That indicates you don't make it there. Place those var_dump at the top of the page after the <?php, at the very minimum you should end up with array (0){} for both ($_GET and $_POST are always available as arrays unless explicitly unset). Also, make sure you pull it from the output HTML source since it has a format to it.
Fou-Lu is offline   Reply With Quote
Old 01-10-2013, 12:25 AM   PM User | #24
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
That indicates you don't make it there. Place those var_dump at the top of the page after the <?php, at the very minimum you should end up with array (0){} for both ($_GET and $_POST are always available as arrays unless explicitly unset). Also, make sure you pull it from the output HTML source since it has a format to it.
Quote:
array(0) { } array(1) { ["id"]=> string(1) "4" }
The '4' being correct as it was the id of the article I was viewing. So, it the script isn't making it to the comment-SQL block, what would most likely be the issue? Could it be the exit() conditionals?
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps
elitis is offline   Reply With Quote
Old 01-10-2013, 12:35 AM   PM User | #25
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
This is from after you've submitted a form?
What's the rendered HTML prior to submission look like?
Fou-Lu is offline   Reply With Quote
Old 01-12-2013, 02:30 AM   PM User | #26
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
This is from before and after form submission. It stays exactly the same.
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps
elitis is offline   Reply With Quote
Old 01-12-2013, 04:13 AM   PM User | #27
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by elitis View Post
This is from before and after form submission. It stays exactly the same.
Okay, I'll try this again:

Quote:
Originally Posted by Fou-Lu View Post
What's the rendered HTML prior to submission look like?
I need to see the rendered HTML. You don't have that here.
Fou-Lu is offline   Reply With Quote
Old 01-12-2013, 05:18 AM   PM User | #28
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
http://xtraz.cu.cc/news?id=5
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps
elitis is offline   Reply With Quote
Old 01-12-2013, 05:21 PM   PM User | #29
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I can't replicate this issue. Have you tried using a valid URL instead of the rewrite?
Edit:
Actually I can replicate it with mod_rewrite. Are you using a redirection type (using R=301 for example) in the rewrite rule? If so, that's a redirect in which case you will lose the post data as it forwards the request through get.

Last edited by Fou-Lu; 01-12-2013 at 05:24 PM..
Fou-Lu is offline   Reply With Quote
Old 01-12-2013, 06:28 PM   PM User | #30
elitis
Regular Coder

 
Join Date: Sep 2010
Posts: 319
Thanks: 9
Thanked 6 Times in 6 Posts
elitis is an unknown quantity at this point
you've lost me unfortunately. As far as I know I'm not using a redirection type.
__________________
Coding is a challenge, get used to it
Always remember to debug
Try the guess & check method
Break it down into simple steps
elitis is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:48 AM.


Advertisement
Log in to turn off these ads.