SQL 语法错误;检查与您的 MySQL 服务器版本相对应的手册 [英] Error in your SQL syntax; check the manual that corresponds to your MySQL server version

查看:123
本文介绍了SQL 语法错误;检查与您的 MySQL 服务器版本相对应的手册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML 代码

<头><风格>#正确的{边距顶部:109px;边距右:225px;}#按钮{边距右:;边距顶部:22px;}</风格><身体><div id="total" style="width:1350px"><div id="top" style="width:1350px;height:69px;background-image:url('top.png');float:;"></div><div id="body" style="width:1350px;height:570px;background-image:url('body.jpg');float:;"><div id="right" style="background-color:;height:283px;width:320px;float:right;"><form action="new.php" method="post" ><input type="text" name="username" value="" size="37" placeholder="username"style="height:20px"><br><br><pre><input type="password" name="password" value="" size="37" placeholder="password"style="height:20px"><div id="button"><input type="image" name="" value="submit" src="button.png"/><input type="checkbox" value="check"><br></pre>

</表单>

<div id="footer" style="width:1350px;height:33px;background-image:url('footer.png');clear:both;"></div>

</html>

我的 PHP 代码

<小时>

当我输入用户名后点击提交按钮时:prabha密码:passwordofprabha

它显示以下错误.请修复我的代码.

<块引用>

错误:您的 SQL 语法有错误;检查手册对应于您的 MySQL 服务器版本以使用正确的语法'table (username, password) VALUES ('prabha','passwordofprabha')' 附近在第 1 行

解决方案

对 MYSQL 保留字使用 ` 反引号...

表名table"是MYSQL的保留字...

所以你的查询应该如下...

$sql="INSERT INTO `table` (`username`, `password`)价值观('$_POST[用户名]','$_POST[密码]')";

HTML CODE

<!DOCTYPE html>
<html>
  <head>
    <style>
      #right
      {
      margin-top:109px;
      margin-right:225px;
      }
      #button
      {
      margin-right:;
      margin-top:22px;
      }
    </style>
  </head>
  <body>
    <div id="total" style="width:1350px">
      <div id="top" style="width:1350px;height:69px;background-image:url('top.png');float:;"></div>
      <div id="body" style="width:1350px;height:570px;background-image:url('body.jpg');float:;">
        <div id="right" style="background-color:;height:283px;width:320px;float:right;">
          <form action="new.php" method="post" >
            <input type="text" name="username" value="" size="37"  placeholder="username"style="height:20px"><br><br>
            <pre><input type="password" name="password" value="" size="37" placeholder="password"style="height:20px"> 
<div id="button"><input type="image" name="" value="submit" src="button.png" />  <input type="checkbox" value="check"><br></pre>
            </div>
          </form>
        </div>
      </div>
      <div id="footer" style="width:1350px;height:33px;background-image:url('footer.png');clear:both;"></div>
    </div>
  </body>
</html>

MY PHP CODE

<?php
$con=mysqli_connect("localhost","prabha","prabha","prabha");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="INSERT INTO table (username, password)
VALUES
('$_POST[username]','$_POST[password]')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "1 record added";

mysqli_close($con);
?>


When i clicked on submit button after entering username:prabha password:passwordofprabha

It shows the following error. Please fix my code.

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table (username, password) VALUES ('prabha','passwordofprabha')' at line 1

解决方案

Use ` backticks for MYSQL reserved words...

table name "table" is reserved word for MYSQL...

so your query should be as follows...

$sql="INSERT INTO `table` (`username`, `password`)
VALUES
('$_POST[username]','$_POST[password]')";

这篇关于SQL 语法错误;检查与您的 MySQL 服务器版本相对应的手册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
数据库最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆