1

別の記事のコメント ボックスを作成しました。

データベース名は test です

**INSERT INTO `test`.`test` (`id`, `name`, `email`, `comment`, `timestamp`, `articleid`)**

コメントファイル名はformcode.php、コードは

**<form method='post'>
        NAME: <input type='text' name='name' id='name' /><br />

        Email: <input type='text' name='email' id='email' /><br />

        Comment:<br />
        <textarea name='comment' id='comment' /></textarea><br />

        <input type='hidden' name='articleid' id='articleid' value='<?php echo $_GET["id"]; ?>' />

        <input type='submit' value='Submit' />  
    </form>**

1つをファイルする必要がありますmanage_comments.phpコードはこちらです

**<?php
if( $_POST )
{
    $con = mysql_connect("localhost","asim","1234");

    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("test", $con);

    $users_name = $_POST['name'];
    $users_email = $_POST['email'];
    $users_comment = $_POST['comment'];

    $users_name = htmlspecialchars($users_name);
    $users_email = htmlspecialchars($users_email);
    $users_comment = htmlspecialchars($users_comment);

    $articleid = $_GET['id'];
    echo $id; 
    if( ! is_numeric($articleid) )
        die('invalid article id');

    $query = "
 INSERT INTO `test`.`test` (`id`, `name`, `email`,
        `comment`, `timestamp`, `articleid`) VALUES (NULL, '$users_name',
        '$users_email','$users_comment',
        CURRENT_TIMESTAMP, '$articleid');";

    mysql_query($query);

    echo "<h2>Thank you for your Comment!</h2>";

    mysql_close($con);
}
?>**

他のファイルはdisplay_comments.phpで、コードは

**<?php

$con = mysql_connect("localhost","asim","1234");

if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("test", $con);

$article_id = $_GET['id'];

if( ! is_numeric($article_id) )
    die('invalid article id');

$query = "SELECT * FROM `test` WHERE `articleid` =$article_id LIMIT 0 , 30";

$comments = mysql_query($query);

echo "<h1>User Comments</h1>";

while($row = mysql_fetch_array($comments, MYSQL_ASSOC))
{
    $name = $row['name'];
    $email = $row['email'];
    $comment = $row['comment'];
    $timestamp = $row['timestamp'];

    echo "  <div style='margin:30px 0px;'>
            Name: $name<br />
            Email: $email<br />
            Comment: $comment<br />
            Timestamp: $timestamp
        </div>";
}

mysql_close($con);

?>**

私はさまざまな記事を持っています。しかし、URLパスのクエリ値を取得できません

たとえば、パスは

**http://localhost/mysite-Copy/category/Article/money1.php**

しかし、それは記事IDのクエリ値を設定しませんでした。何が問題なのか教えてください

4

1 に答える 1

0

$_POST['articleid']の代わりに使用し$_GET['id']ます。なぜならフォームメソッドは'post'. ?id=12たとえば、記事 ID 12 の URL にも追加します。

于 2013-02-17T11:07:37.290 に答える