MySQL查询错误,我不知道为什么

时间:2013-03-29 17:29:00

标签: php html mysql phpmyadmin dreamweaver

好的,我想要构建: 您登录的网站(我稍后会这样做)。有一个表单,您可以在其中提交新闻报告,然后进入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>

我的报告.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>

AND FINALLY-我的数据库结构(我无法发布截图) 领域: report_id(主键,自动增量) 标题 作者 字幕 身体 图片

P.S 对于image / \我正在关注“Head First PHP and MySQL”,所以它是存储在db中的图像名称,而不是图像(我没有把它放到表单中,但我不认为这是问题)。

对不起,很长的帖子。 路加

1 个答案:

答案 0 :(得分:2)

你有不匹配的地方。您将4列命名为要插入,但您定义了5个值。添加缺少的列。

$query = "INSERT INTO news_reports (title, author, subtitle, body) " .
    "VALUES ('$title', '$author', '$subtitle', '$body', '$image')"