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

Php MySQL查询错误,我不知道';我不知道为什么,php,html,mysql,phpmyadmin,dreamweaver,Php,Html,Mysql,Phpmyadmin,Dreamweaver,好的,那么我想要构建什么: 您登录的网站(我稍后会这样做)。有一个表单,您可以在其中提交新闻报告,然后将其放入MySQL数据库。然后,它会显示在iPhone(稍后提供)的表视图中。 正如我提到的,我得到了一个“错误查询数据库”。我尝试过修复它,但我对MySQL和PHP还不熟悉,所以我不知道还能做什么。 我在家庭服务器(WAMP)上设置了这个 My report.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transition

好的,那么我想要构建什么: 您登录的网站(我稍后会这样做)。有一个表单,您可以在其中提交新闻报告,然后将其放入MySQL数据库。然后,它会显示在iPhone(稍后提供)的表视图中。 正如我提到的,我得到了一个“错误查询数据库”。我尝试过修复它,但我对MySQL和PHP还不熟悉,所以我不知道还能做什么。 我在家庭服务器(WAMP)上设置了这个

My 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>

足球中央新闻报道提交页面
足球中央新闻报道提交页面
萨姆比特你的足球新闻报道在这里
检查错误!!!
标题:

作者:
字幕:
正文:
图片:
My 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>

足球中央新闻报道提交页面
足球中央新闻报道提交页面(确认)

你有一个不匹配。您指定了要插入的4列,但定义了5个值。添加缺少的列

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

你有什么问题吗?简单地
echo mysqli_错误($dbc)
并且您将知道使用
mysqli
扩展而不是旧的
mysql
函数会出现什么问题。但是-100表示根本没有对输入变量进行任何转义。您的代码很容易受到SQL注入攻击,如果任何输入包含引号或其他特殊字符,代码都会失败。您在SQL查询的列列表中没有提到图像字段。大家好,谢谢。我知道这将是一个简单的lol和注射技巧感谢,我还没有达到书中的这一部分。但是谢谢你的提醒!好的,我可能需要更多的帮助。我已经(尝试)改进了很多脚本,但是(使用DreamWeaver)我得到了一个语法错误,但是我看不出有什么问题。我应该把代码贴在哪里?它是249个单词。在您的查询类型之后
echo$query;退出并在这里发布。好吧,现在我有两个新问题。我知道问题是什么,但我不知道如何解决。一个是文件上传,另一个是联系方式。我现在应该在哪里发帖?对不起,伙计们。如果你们有新问题,那就问一个新问题。