简体   繁体   English

MYSQL 数据库错误:“pymysql.err.ProgrammingError: (1064, ”您的 SQL 语法有错误;请查看与您对应的手册-"

[英]MYSQL Database error: “pymysql.err.ProgrammingError: (1064, ”You have an error in your SQL syntax; check the manual that corresponds to your-"

Original Title: pymysql.err.ProgrammingError: (1064, "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 'Condition, KitLens, PurchasePrice) VALUES ('Nikon', 'HEWWO', '2020-06-11', 'OHH ' at line 1")原标题: pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; 检查与您的 MySQL 服务器版本相对应的手册以获取在 'Condition, KitLens, PurchasePrice) VALUES 附近使用的正确语法'、'HEWWO'、'2020-06-11'、'OHH' 在第 1 行")

I keep getting this error upon running MYSQL database for cameras.在为相机运行 MYSQL 数据库时,我不断收到此错误。 Upon trying to create a new camera, I come up with the error:在尝试创建新相机时,我遇到了错误:

pymysql.err.ProgrammingError: (1064, "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 'Condition, KitLens, PurchasePrice) VALUES ('Nikon', 'HEWWO', '2020-06-11', 'OHH ' at line 1") pymysql.err.ProgrammingError: (1064, "您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,了解在 'Condition、KitLens、PurchasePrice 附近使用的正确语法) VALUES ('Nikon', HEWWO'、'2020-06-11'、'OHH' 在第 1 行")

I have tried to troubleshoot and fix MYSQL table in Navicat, in my app.py file, and html file but to no avail.我尝试在我的 app.py 文件和 html 文件中对 Navicat 中的 MYSQL 表进行故障排除和修复,但无济于事。 I'm thinking it maybe because of some certain whitespace in the code?我在想这可能是因为代码中的某些空格? Here is my code snippet for creating a new camera which I am sure is only necessary to share here as it is part of the problem:这是我用于创建新相机的代码片段,我确信只需要在此处分享,因为它是问题的一部分:

    @app.route("/new_camera", methods = ["GET", "POST"])
    def newcamera():
        connection=create_connection()
        if request.method =="POST":
            get = request.form
            Company = get["Company"]
            Model = get["Model"]
            PurchaseDate = get["PurchaseDate"]
            Condition = get["Condition"]
            KitLens = get["KitLens"]
            PurchasePrice = get["PurchasePrice"]

            #photo=
            with connection.cursor() as cursor:
            # Create a new record
              sql = "INSERT INTO `tblcameras` (Company, Model, PurchaseDate, Condition, KitLens, PurchasePrice) VALUES (%s, %s, %s, %s, %s, %s)"
              val=(Company, Model, PurchaseDate, Condition, KitLens, PurchasePrice)
              cursor.execute(sql, val)
              #save values in dbase
              connection.commit()
              cursor.close()
              return redirect("/cameras")
        return redirect(url_for('cameras?do=new', title="Add New camera"))
        #return render_template("cameras.html",title="Adding New camera")

and my adding new camera html code:和我添加新相机 html 代码:

   {% extends "layout.html" %}
    {% block content %}

    {% if (request.args.get('do')=='new' )%}
<br />
<h2>New camera</h2>
<form method="post" action="/new_camera" class="was-validated">

    <div class="form-group">
        <label for="Company">Company:</label>
         <select id="Company" name="Company" class="form-control">
            <option value="">Choose an option</option>
            <option value="Canon">Canon</option>
            <option value="Nikon">Nikon</option>
         </select>
        <div class="valid-feedback">Valid.</div>
        <div class="invalid-feedback">Please fill out this field.</div>
    </div>
    <div class="form-group">
        <label for="Model">Model:</label>
        <input type="text" class="form-control" id="Model" placeholder="Enter Model" name="Model" required>
        <div class="valid-feedback">Valid.</div>
        <div class="invalid-feedback">Please fill out this field.</div>
    </div>

    <div class="form-group">
        <label for="PurchaseDate">Purchase Date:</label>
        <input type="date" class="form-control" id="PurchaseDate" placeholder="Purchase Date" name="PurchaseDate" required>
        <div class="valid-feedback">Valid.</div>
        <div class="invalid-feedback">Please fill out this field.</div>
    </div>

    <div class="form-group">
        <label for="Condition">Condition:</label>
        <input type="text" class="form-control" id="Condition" placeholder="Enter Condition" name="Condition" required>
        <div class="valid-feedback">Valid.</div>
        <div class="invalid-feedback">Please fill out this field.</div>
    </div>

    <div class="form-group">
        <label for="Kit Lens">Kit Lens</label>
        <input type="text" class="form-control" id="KitLens" placeholder="Enter Kit Lens (mm) or Standard" name="KitLens" required>
        <div class="valid-feedback">Valid.</div>
        <div class="invalid-feedback">Please fill out this field.</div>
    </div>

    <div class="form-group">
        <label for="Purchase Price">Purchase Price</label>
        <input type="number" min="1" step="any" class="form-control" id="PurchasePrice" placeholder="Enter Purchase Price ($)" name="PurchasePrice" required>
        <div class="valid-feedback">Valid.</div>
        <div class="invalid-feedback">Please fill out this field.</div>
    </div>

    <button type="submit" class="btn btn-primary">Submit</button>
</form>
<hr />
{% endif %}

<br />

<h2>
    Existing cameras
</h2>

<div class="table-responsive">
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>Name</th>
                <th>Action</th>
            </tr>
        </thead>

        {%for camera in cameras%}
        <tr>
            <td>{{camera.Company}} {{camera.Model}}</td>
            <td> 
            <a href="/camera?do=edit&id={{camera.cameraId}}" class="btn btn-info">Edit</a> 
            <a href="/camera?do=details&id={{camera.cameraId}}" class="btn btn-success">Details</a> 
            <a href="/camera?do=delete&id={{camera.cameraId}}" class="btn btn-danger">Delete</a></td>
        </tr>

        {%endfor%}

    </table>
</div>

{% endblock %}

Here is also a screenshot of the data I tried to fill in:这也是我尝试填写的数据的屏幕截图:

Adding A New Camera添加新相机

I tried looking at the other suggested questions and errors similar to this but I could not find a solution within any of them for my context.我尝试查看与此类似的其他建议问题和错误,但我无法在其中任何一个中找到适合我的上下文的解决方案。 If you need any more information please let me know, Any help is appreciated.如果您需要更多信息,请告诉我,任何帮助表示赞赏。 Thank you谢谢

Condition is a reserved word .条件是保留字

sql = "INSERT INTO `tblcameras` (Company, Model, PurchaseDate,`Condition`, KitLens, PurchasePrice) VALUES (%s, %s, %s, %s, %s, %s)"

use backticks liek you did for your table使用你为你的桌子做的反引号

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PYMYSQL ERROR pymysql.err.ProgrammingError: (1064, "你的 SQL 语法有错误") - PYMYSQL ERROR pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax ") pymysql.err.ProgrammingError:您的SQL语法有错误 - pymysql.err.ProgrammingError: You have an error in your SQL syntax 1064(42000):您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法使用 - 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use sqlalchemy.exc.ProgrammingError:您的SQL语法有错误; 查看与MariaDB服务器版本对应的手册 - sqlalchemy.exc.ProgrammingError: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version 您的 SQL 语法有错误; 检查与您的 MySQL 服务器 PYTHON 相对应的手册 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server PYTHON 42000您的SQL语法错误; 检查与您的MySQL服务器相对应的手册 - 42000 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server _mysql_exceptions.ProgrammingError 1064,“您的SQL语法有错误;请检查 - _mysql_exceptions.ProgrammingError 1064, "You have an error in your SQL syntax; check Pymysql 1064,“您的 SQL 语法有错误 - Pymysql 1064, "You have an error in your SQL syntax 警告:您的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在附近使用正确的语法 - Warning: 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 您的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取在 &#39;) 附近使用的正确语法 - 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 ')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM