0
<?php
include("dbinit.php");
$text="helow";
    $eadd = $_SESSION['account'];
    $result = mysqli_query($link,"SELECT * FROM account where Eadd='". $eadd ."'");
        while($row = mysqli_fetch_array($result))
            {
                $name = $row['Name'];
            }
                $ctext = $_POST['ctext'];
                $sql = "INSERT INTO chat (By, Content, Reported) VALUES ('$name','$ctext','No')";
                mysqli_query($link,$sql);
                mysqli_close($link);
                $text=$name . $ctext;
echo $text;
?>

これが私のコードです。私の他のページでは、これは機能しますが、「挿入先」の値を変更すると、データベースに保存できないのはなぜですか?

<?php
session_start();
        $link = mysqli_connect("localhost", "xxx", "xxx", "xxx");

        /* check connection */
        if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
        }
        mysqli_select_db($link, "xxx");
        header('Content-type: text/html; charset=utf-8');
?>

ここに私のdbinitファイルがあります

4

3 に答える 3

1
$sql = "INSERT INTO `chat` (`By`, `Content`, `Reported`) VALUES ('".$name."','".$ctext."','No')";

mysql インジェクションから保護するには、これをお読みください。

また、どのような値に変更した場合は機能しませんか?

于 2013-07-21T10:39:28.777 に答える