次に、if(filter_input( 'REQUEST_METHOD')=== 'POST')チェックを使用する必要があります。そのよう
:
<form action="addplayer.php"method "post"/>
<p> id: <input type="text" name="playerid"/></p>
<p> Name: <input type="text" name="name"/></p>
<p> Age: <input type="text" name="age"/></p>
<p> Position: <input type="text" name="position"/></p>
<p> Nationality: <input type="text" name="nationality"/></p>
<input type="submit" value="submit"/>
</form>
<?php
if(filter_input(INPUT_SERVER, 'REQUEST_METHOD') === 'POST'){
require 'connection.php';
$id = filter_input(INPUT_POST, 'playerid');
$name = filter_input(INPUT_POST, 'name');
$age = filter_input(INPUT_POST, 'age');
$position = filter_input(INPUT_POST, 'position');
$nationality = filter_input(INPUT_POST, 'nationality');
$_id = mysql_real_escape_string($id);
$_name = mysql_real_escape_string($name);
$_age = mysql_real_escape_string($age);
$_position = mysql_real_escape_string($position);
$_nationality = mysql_real_escape_string($nationality);
$sql = "INSERT INTO players (playerid, name, age, position, nationality)
VALUES ('$_id', '$_name', '$_age', '$_position', '$_nationality')";
if (!mysql_query($sql)){
die('Error: ' . mysql_error());
}
}
はそれが 'PRIMARY'キーだ設定increment'オート' id' 1人の列名を '作成します。 –
あなたのフォームタグは実際には 'method =" post "'の代わりに 'method" post "'を持っていますか、それとも単に質問の誤字ですか? –
フォームメソッドが定義されていない場合、[デフォルトはGET](http://stackoverflow.com/questions/2314401/what-is-the-default-form-http-method)ので、POST値はすべて空の。 –