0

次のファイルがあります。何らかの理由で、JavaScript (PHP の「echo」タグ内) が機能しません。

HTML (index.php):

<form action="submit.php" method="post">
<div id="edit-box">
<INPUT type="submit" name="save-text" id="save-text" value="Save">
<textarea id="editor" name="editor">
<?php echo $content; ?>
</textarea>
</div>
</form>

PHP (submit.php):

<?php

include('connect-db.php');

$submit_date = date("Ymd");
$content = mysql_real_escape_string(htmlspecialchars($_POST['editor']));
$ip_address = getRealIPAddress();

if ($content != '') { 
mysql_query("INSERT source SET submit_date='$submit_date', ip='$ip_address', content='$content'")
or die(mysql_error());

// The following line is not working! I need help here!
echo '<script type="text/javascript"> alert("Your file saved!");</script>';  

mysql_close($connection);
}
?>

「submit.php」には、他の PHP または HTML スクリプト/タグはありません。古い PHP/MySQL API (PDO/MySQLi の代わりに) を使用していることは理解していますが、それは的外れです。

4

2 に答える 2

0

アラートを出力する必要があります。スクリプトを印刷していますか? クエリのエラーで停止する可能性があることがわかります。

そうでない場合は、connect-db.php に何を含めていますか?必要なファイルのどこかで出力バッファーを台無しにしている可能性があります..

また、SQLが間違っていると確信しています:

INSERT source SET submit_date='$submit_date', ip='$ip_address', content='$content'
INSERT INTO source (submit_date, ip, content) values('$submit_date','$ip_address','$content');

しかし、それは安全なクエリではありません...それは的外れです。

これが発生する可能性があるその他の理由を次に示します。

  1. include("connect-db.php');スクリプトの実行を強制終了する可能性があります 。
    • 内部に異常がある場合。
  2. クエリが死ぬ可能性があります。
  3. 出力は、php 構成内または「connect-db.php」内の別の場所にリダイレクトされます。
  4. getRealIPAddress()文書化されておらず、スクリプトが壊れる可能性があります。
  5. $_POST['editor']壊れてSQLが死ぬ可能性がある何か偽物があるかもしれません。
于 2013-03-09T21:41:41.967 に答える
-1

以下のコードを試してください

<?php

include('connect-db.php');

$submit_date = date("Ymd");
$content = mysql_real_escape_string(htmlspecialchars($_POST['editor']));
$ip_address = getRealIPAddress();
$content = $_POST["editor"];
if ($content != '') { 
mysql_query("INSERT source SET submit_date='$submit_date', ip='$ip_address', content='$content'")
or die(mysql_error());

// The following line is not working! I need help here!
echo '<script type="text/javascript"> alert("Your file saved!");</script>';  

mysql_close($connection);
}
?>
于 2013-03-09T21:09:45.440 に答える