-3

テキストボックスから値を取得しようとしましたが、失敗しました。これは私のコードです。あなたがしたいことは、テキストボックスから値を取得し、その値をデータベースの値と一致させることです

<form action="" method="post">

 <strong>Code: *</strong> <input type="text"  name = "code" >
 <input type="submit" name="submit" value="Submit">
    </form>
    <?php


$code= $_POST["code"];
$sql = "SELECT bookingref FROM starpick";
        $result = $mysqli->query($sql);

        while (list($bookingref )=$result->fetch_row()) 
        {
            if (($bookingref == $code) )
                {
                    echo "Sorry, there was a problem uploading your file.";

                }else
                    {
                        echo "==";
                    }
        }

?>
4

1 に答える 1

2

この簡単な例から始めてください...フォームをPOSTすると、コードが返されますか...

<form action="" method="post">
    <strong>Code: *</strong> <input type="text"  name="code">
    <input type="submit" name="submit" value="Submit">
</form>
<?php
    if (isset($_POST['code'])) {
        $code = htmlentities($_POST['code']);
        echo 'The code is ' . $code . '<br>';
    }
?>

フォームに期待するものが得られたら、これを実行します...

<form action="" method="post">
    <strong>Code: *</strong> <input type="text"  name="code">
    <input type="submit" name="submit" value="Submit">
</form>
<?php
    if (isset($_POST['code'])) {
        $code = $_POST['code'];
        $sql = "SELECT bookingref FROM starpick WHERE bookingref ='" .
            mysql_real_escape_string($code)."';";
        $result = $mysqli->query($sql);
        if (!$result) {
            die('Invalid query: ' . mysql_error());
        }
        while ($row = mysql_fetch_assoc($result)) {
            // Do something with the result(s)
            echo $row['bookingref'] . '<br>';
        }
    }
?>
于 2012-01-18T14:49:50.913 に答える