include 'connect.php';


                    $page_id = $_GET['id'];

                    $select_query = "SELECT * FROM articles WHERE articles_id='$page_id'";

                    $run_query = mysql_query($select_query);


                        $articles_id = $row['articles_id'];
                        $articles_date = $row['articles_date'];
                        $articles_title = $row['articles_title'];
                        $articles_category = $row['articles_category'];
                        $articles_image = $row['articles_image'];
                        $articles_content = $row['articles_content'];

                    <a href="articlespage.php?id=<?php echo $articles_id; ?>">
                    <?php echo $articles_title; ?>

                    <p><i>Published on <b><?php echo $articles_date; ?></b></i></p>

                    <img src="<?php echo $articles_image; ?>" width="300" height="250">

                    <p align="justify"><?php echo $articles_content; ?></p>


                    <?php } } ?>



            <form method="post" action="articlespage.php" enctype="multipart/form-data">

                <table width="300" align="center" border="0">

                        <td align="right">Name</td>
                        <td><input type="text" name="author"></td>

                        <td align="right">Email</td>
                        <td><input type="text" name="email"></td>

                        <td align="right">Comment</td>
                        <td><textarea type="text" name="content" cols="30" rows="10"></textarea></td>

                        <td align="center" colspan="6"><input type="submit" name="submit" value="Publish Now"></td>


            include 'connect.php';
            if (isset($_POST['submit'])){

            // my problem is
            // i cannot get the article_id to store it on com_art_id,
            // the articles_id is already showing on url bar
            // i have no idea how to place it on com_art_id

            ////     $com_art_id = $articles_id;
                 $comment_date = date('d-m-y');
                 $comment_name = $_POST['author'];
                 $comment_email = $_POST['email'];
                 $comment_content = $_POST['content'];

                if ($comment_name=='' or $comment_email=='' or $comment_content==''){

                    echo '<center><b><font color="red">All fields are required.</font></b></center>';


                    $insert_query = "INSERT INTO comments(com_art_id, comment_date, comment_name, 
                    comment_email, comment_content) 
                    VALUES('$com_art_id', '$comment_date', '$comment_name', '$comment_email', '$comment_content')";


                        //echo "<center>Submitted sucessfully.</center>";
                        header("Location: articlespage.php?");




Edited by 2mhzbrain

4 Years
Discussion Span
Last Post by 2mhzbrain

Can you provide more information? how is anyone supposed to figure out what to do with the title and code you provided?

A more detailed description of the problem, what you are trying to accomplish, etc.. will likely get you more help.


sorry, i included it on comment, my problem is i cannot get the article_id to store it on com_art_id, the articles_id is already showing on url bar, i have no idea how to place it on com_art_id, can i use GET function? show me how to do it, im realy new at php

Edited by 2mhzbrain


Ok, i see it in your code as commented...

Refer to this page in the online PHP manual: http://www.php.net/manual/en/reserved.variables.get.php

If you want to get the query string, use $_GET

Say your URL is articlespage.php?id=1, your code to get that query string parameter called "id" would be... $_GET["id"]

Therefore... $com_art_id = $_GET["id"]; should work.

You should consider performing some check(s) prior to assuming that the value in the query string is going to be a value you expect.

Edited by JorgeM

$com_art_id = $_GET["id"];

this doesnt work, also please tell me why year is always wrong and all months and days are 1-14, it always saved 0 as com_art_id

Edited by 2mhzbrain

Attachments Untitled.jpg 62.29 KB
$comment_date = date('Y-m-d');

this solved the date, i still cant put article_id as the value of com_art_id


how to place article id on a user comment so that if user submitted the comment, it will have the article id, then we can show all comments for specific article

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.