0

データベースにいくつかのデータを送信した後、example.php にリダイレクトしようとしています。フォームは完璧に送信されますが、リダイレクトを機能させることができません。

<html>
    <head>

        <title>MySQLi Create Record</title>

    </head>
<body>

<?php
$action = isset($_POST['action']) ? $_POST['action'] : "";

if($action=='create'){
        //include database connection
        include 'db_connect.php';

        //write query
        $query = "insert into referb 
                                set
                                        make = '".$mysqli->real_escape_string($_POST['make'])."', 
                                        model = '".$mysqli->real_escape_string($_POST['model'])."',
                                        unitt  = '".$mysqli->real_escape_string($_POST['unitt'])."'";

        if( $mysqli->query($query) ) {
                echo " header( 'Location: example.php' ) ;";
        }else{
                echo "Database Error: Unable to create record.";
        }
        $mysqli->close();
}

?>

<!--we have our html form here where user information will be entered-->
<form action='#' method='post' border='0'>
    <table>
        <tr>
            <td>Manufactor</td>
            <td><input type='text' name='make' /></td>
        </tr>
        <tr>
            <td>Model</td>
            <td><input type='text' name='model' /></td>
        </tr>
        <tr>
            <td>Unit Type</td>
            <td>
            <select name='unitt'>
  <option>Laptop</option>
  <option>Computer</option>
  <option>Tablet</option>
</select></td>
        </tr>

            <td></td>
            <td>
                <input type='hidden' name='action' value='create' />
                <input type='submit' value='Save' />

                                <a href='index.php'>Back to index</a>
            </td>
        </tr>
    </table>
</form>

</body>
</html>
4

5 に答える 5

1

header() の呼び出しはエコーされるべきではありません。その行は次のように変更する必要があります。

header('Location: example.php');
exit();

exit() afterards を呼び出すと、スクリプトのそれ以上の実行が停止します。

于 2013-08-17T15:00:12.110 に答える
0

ステップ 1: 最初にクエリを実行してデータベースにデータを挿入する

ステップ 2: データベース接続を閉じる

ステップ 3: 置くだけ >>> header('Location: example.php');

于 2013-08-17T17:06:31.727 に答える
-4

これは、ユーザーを別の URL にリダイレクトする php スクリプトであり、これを適切な条件の後またはコードの指示の後に配置します。

 <html>
 <?php
 header('Location: http://www.example.com/');
 exit;
 ?>
于 2013-08-17T15:03:25.557 に答える