ここには、解決が必要な問題が数多くあります。
まず、<input>
type の1 つだけが必要submit
です。それはテーブルの外に出ることができます。次に、valign
属性に余分な>
文字が含まれています。
<table width="600">
<tr valign="top">
<th width="92" scope="row">Enter New Track</th>
<th width="92" scope="row">Enter New Position</th>
<thwidth="92" scope="row">Enter New Driver</th>
<th width="92" scope="row">Enter New Class</th>
</tr>
<tr valign="top">
<td><input type="text" name="track" /></td>
<td><input type="text" name="position" /></td>
<td><input type="text" name="driver" /></td>
<td><input type="text" name="class" /></td>
</tr>
</table>
<br />
<input type="submit" value="Submit" />
上記のコードは、<form>
タグ内に配置する必要があります。
フォームを送信すると、データはinput.phpPOST
に編集されます。その目的は、データを処理し、新しいデータをテーブルに挿入することです (なぜこのようにするのかは謎のままですが、私は最初に質問に答えます)。
input.phpは次のようになります。
<?php
// I will ignore error handling here, but if you want a good tutorial on PHP PDOs, try http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html
$pdoObj = new PDO("mysql:host=[yourhost];dbname=[yourdbname]", [db_username], [db_password]);
// keep in mind that this code is WAY OPEN to SQL injection attacks, but this will at least give you an idea of how to get your code to function, if not securely.
if(isset($_POST['track'])) {
$pdoObj->exec("INSERT INTO tracks (name) VALUE ('" . $_POST['track'] . "')");
}
if(isset($_POST['position'])) {
$pdoObj->exec("INSERT INTO positions (name) VALUE ('" . $_POST['position'] . "')");
}
if(isset($_POST['driver'])) {
$pdoObj->exec("INSERT INTO drivers (name) VALUE ('" . $_POST['driver'] . "')");
}
if(isset($_POST['class'])) {
$pdoObj->exec("INSERT INTO classes (name) VALUE ('" . $_POST['class'] . "')");
}
// some code here that will either display some copy or redirect the user to another page
ノート:
あなたはまだ Web 開発に慣れていないようですので、これで終わりにします。SQL インジェクションは冗談ではありません。あなたはそれに対して防御しなければなりません. そうしないと、データベース内のすべてを失う可能性があります.
PHP、Wordpress、および Web 開発全般に関する本やチュートリアルを数冊手に取ってください。ベスト プラクティスについてコミュニティの人々と話し、快適だと思われる基本的なタスクを実行する方法について、より多くの指針を得るようにしてください。次に、能力をテストするより複雑なシナリオに進みます。十分な経験があれば、自分の Web アプリケーションで何ができるかに驚かれることでしょう。