-1

これがphpコードです。PHP変数をフォームフィールドのテキストボックス属性にエコーしようとしています。

<?php
while($result=mysql_fetch_array($query))
{

        $title=$result["title"];
        $date=$result["date"];
        $body=$result["body"];
        $email=$result["email"];
        $id=$result["id"];
//can i use the $id variable into the form field like bellow 
//if not then how so    


echo"<form action="" method="post">";
//Here i m using  $id variable  
echo "<input type="test" name="test" value='<?php echo "$id"?>'/>";
echo "<input type="submit" name="submit" value="submit"/>";
echo "</form>";
}
?>

ありがとうございました

4

4 に答える 4

1

私があなたの質問を誤解していない限り、あなたはあなたのコードの中のタグを削除するべきです。

11行目を次のように変更します。

echo '<input type="test" name="test" value="' . htmlentities($id) . '"/>';

IDがユーザー入力からのものである場合は、htmlentities()でサニタイズする必要があります。そうしないと、サイトがxss(クロスサイトスクリプティング)の脆弱性にさらされます。

于 2013-03-22T21:40:07.033 に答える