わかりましたので、私が構築したいもの: ログインする Web サイト (これは後で行います)。ニュース レポートを送信するフォームがあり、MySQL データベースに入力されます。これは、iPhone のテーブル ビューに表示されます (後で表示されます)。前述したように、「データベースのクエリ中にエラーが発生しました」というメッセージが表示されます。私はそれを修正しようとしましたが、MySQL と PHP は初めてなので、他に何をすべきかわかりません。これをホームサーバー(WAMP)にセットアップしました。
私のreport.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Football Central News Report Submission Page</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1>Football Central News Report Submission Page</h1>
<h2>Sumbit your football news report here</h2>
<h3>CHECK FOR MISTAKES !!!</h3>
<form method="post" action="report.php">
<label for="title">Title:</label>
<input type="text" name="title" />
<br />
<label for="author">Author:</label>
<input type="text" name="author" />
<br />
<label for="subtitle">Subtitle:</label>
<input type="text" name="subtitle" />
<br />
<label for="body">Body:</label>
<textarea name="body"></textarea>
<br />
<label for="image">Image:</label>
<input type="file" id="image" name="image" />
<br />
<input type="submit" value="Submit your news report" name="submit" />
</form>
</body>
</html>
私のreport.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Football Central News Report Submission Page</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1>Football Central News Report Submission Page (Confirmation)</h1>
<?php
$title = $_POST['title'];
$author = $_POST['author'];
$subtitle = $_POST['subtitle'];
$body = $_POST['body'];
$image = $_POST['image'];
$dbc = mysqli_connect('localhost', 'root', 'xxxxxx', 'news_reports')
or die('Error connecting to database server.');
$query = "INSERT INTO news_reports (title, author, subtitle, body) " .
"VALUES ('$title', '$author', '$subtitle', '$body', '$image')";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
mysqli_close($dbc);
?>
<p>
-Thanks for submitting the form.<br />
-Your news report has been submitted to the database and should appear in the app shorty.
</p>
</body>
</html>
そして最後に - 私のデータベース構造 (スクリーンショットは投稿できません) フィールド: report_id (主キー、自動インクリメント) タイトル 作者 サブタイトル 本文画像
PS画像について/\私は「ヘッドファーストPHPとMySQL」に従っているので、画像ではなく、データベースに保存されているのは画像名です(これをフォームに入れていませんが、これは考えていませんが問題です)。
長い投稿で申し訳ありません。ルーク