0

EasyNoteの Web サイトでは、改行に問題があります。

body onload では、次のように 3 秒ごとにメモを自動アップロードするタイマーを設定します。

<body onload="setInterval(uploadNote,3000);current = 1;">

そして、uploadNote のコードは次のとおりです。

function uploadNote() {
    var note = current+document.getElementById(\'note\').value;  //current is the number of the note selected\' because echoed
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200){}
    }
    xmlhttp.open("GET","uploadnote.php?q="+note,true);
    xmlhttp.send();
}

そして、このphpコードがあります:

$note = $_GET["q"]; //contains both notenumber as first digit and note

echo($note."\n"); //for debugging reasons

$notenumber = substr($note, 0, 1);
$notecontent = substr($note, 1, strlen($note));

$notecontent = str_replace("'","''",$notecontent);
$notecontent = nl2br($notecontent);

echo($notecontent); //for debugging reasons

$request = 'UPDATE notes SET note'.$notenumber.' = "'.$notecontent.'" WHERE mail LIKE "'.$email.'"';
$result = mysql_query($request);

問題は、テキストエリアの改行文字が完全に消去されるため、php-snippet の結果は改行なしのテキストの 2 倍になり、データベースにも表示されることです。ただし、データベースに直接挿入すると、テキストエリアに改行が表示されても問題はありません。

助けていただければ幸いです。

編集: 更新された uploadNote() 関数:

function uploadNote() {
    var note = current+document.getElementById(\'note\').value;
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200){}
    }
    xmlhttp.open("POST","uploadnote.php",true);
    xmlhttp.send("note="+note);
}

およびphp:

$note = $_POST["note"];

echo($note."\n");

$notenumber = substr($note, 0, 1);
$notecontent = substr($note, 1, strlen($note));

$notecontent = mysql_real_escape_string($notecontent);

echo($notecontent);

$request = 'UPDATE notes SET note'.$notenumber.' = "'.$notecontent.'" WHERE mail LIKE "'.$email.'"';
$result = mysql_query($request);

今の問題は、何も機能しないことです。メモは MySQL データベースで更新されません。

4

1 に答える 1

0

コードの問題:

  1. サーバー上のものを変更するものには GET リクエストを使用しないでください。POST を使用してください。
  2. データベース クエリでは、変数部分をエスケープする必要があります。mysql_real_escape_string()SQL に書き込まれる値で使用します。
  3. データをデータベースに保存するときは、html 中心の書式設定を使用しないでください。コードをブラウザに出力するときに使用できます。
  4. テキストエリア内では、HTML マークアップを使用することは許可されていない<br>ため、改行に使用することは間違っています。
于 2013-10-13T21:03:33.467 に答える