0

みんな..

フォームを送信しようとしています..フォームとphpコードは同じファイルindex.phpにあります

if(isset($_POST['post_form'])) {
    echo "ISSET";

    $post_sender=$id;
    $post_reciever=$id2;
    $post_cont=$_POST['news_text'];
    $post_cont=htmlentities($post_cont);
    $post_cont=mysql_real_escape_string($post_cont);

    $post_sql=mysql_query("INSERT INTO wall_posts (from, to, content, date) VALUES ('$post_sender','$post_reciever','$post_cont',now())") or die(mysql_error());

    }else{
        echo "NOT SET";
    }

htmlフォーム

<form  method='POST' action='index.php' enctype='multipart/form-data' id='news_form' name='post_form' >
<textarea id='news_text' name='news_text' >type here..........</textarea>

<input type='submit' id='wall_post_btn' name='wall_post_btn' value='submit'>

</form>

私の間違いはどこですか..???

コードに間違いはありません..ファイル自体が破損しています..新しいPHPファイルでテストを行ったばかりです...うまく動作します...みんなありがとう..

4

6 に答える 6

2

post_formフォームの名前です。送信ボタンを確認する必要がありますwall_post_btn

if(isset($_POST['wall_post_btn'])) {
  // entire code here
}
于 2012-12-18T12:36:15.193 に答える
1

$_POST['wall_post_btn']. フォームではなく、送信の名前

于 2012-12-18T12:34:41.403 に答える
0

このコードを使用すると、正常に機能します

<?php
if($_SERVER['REQUEST_METHOD']=="POST") {
   echo "ISSET";
    $post_sender=$id;
    $post_reciever=$id2;
    $post_cont=$_POST['news_text'];
    $post_cont=htmlentities($post_cont);
    $post_cont=mysql_real_escape_string($post_cont);

    $post_sql=mysql_query("INSERT INTO wall_posts (from, to, content, date) VALUES ('$post_sender','$post_reciever','$post_cont',now())") or die(mysql_error());

    }else{
        echo "NOT SET";
    }
?>
<form  method='post' action='index.php' enctype='multipart/form-data' id='news_form' name='post_form' >
<textarea id='news_text' name='news_text' >type here..........</textarea>

<input type='submit' id='wall_post_btn' name='wall_post_btn' value='submit'>

</form>
于 2012-12-18T12:44:46.307 に答える
0

問題は、決して存在しない、に存在するフォームの名前をチェックしている$_POSTことです...

テストする必要があるのは、送信ボタンの名前です。例:

if(isset($_POST['wall_post_btn'])) {

次に、入力をサニタイズするために 1 行を使用できます。

$post_cont= mysql_real_escape_string(htmlentities($_POST['news_text']));

そして最後の 1 つ: 準備済みステートメントまたは少なくともmysqli_*関数で PDO を使用し始めmysql_*ます。

于 2012-12-18T12:38:43.350 に答える
0

mysql は減価償却されているため、使用しないでください。mysqli または PDO を調べる

これ:

"INSERT INTO wall_posts (from, to, content, date) VALUES ('$post_sender','$post_reciever','$post_cont',now())"

次のようにする必要があります。

"INSERT INTO wall_posts (from, to, content, date) VALUES ('".$post_sender."','".$post_reciever."','".$post_cont."',now())"
于 2012-12-18T12:36:11.233 に答える
0

2 つの問題があります。

  1. mysql_real_... を使用するには、mysql サーバーに接続する必要があります。
  2. mysql_real_... は推奨されておらず、php から削除されています

代替手段については、こちらをご覧ください: http://php.net/manual/en/function.mysql-real-escape-string.php

于 2012-12-18T12:37:54.540 に答える