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

问题描述 投票:0回答:1

原始标题:pymysql.err.ProgrammingError:(1064,“您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以获取在'Condition,KitLens,PurchasePrice”附近使用的正确语法)值(第1行的“ Nikon”,“ HEWWO”,“ 2020-06-11”,“ OHH”)

我在运行相机的MYSQL数据库时不断收到此错误。尝试创建新相机时,出现以下错误:

pymysql.err.ProgrammingError:(1064,“您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册 以获取在'Condition,KitLens,PurchasePrice附近使用的正确语法 值(第1行的“ Nikon”,“ HEWWO”,“ 2020-06-11”,“ OHH”)

我曾尝试对Navicat的MYSQL表进行故障排除和修复,但位于我的app.py文件和html文件中,但无济于事。我在想这可能是因为代码中存在某些空白吗?这是我的代码片段,用于创建新相机,我敢肯定,只需在这里共享它,因为它是问题的一部分:

    @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")

和我添加的新相机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 %}

这里也是我尝试填写的数据的屏幕截图:

Adding A New Camera

我尝试查看与此类似的其他建议的问题和错误,但是在我的上下文中我都找不到任何解决方案。如果您需要更多信息,请告诉我,我们将为您提供任何帮助。谢谢

python mysql navicat
1个回答
0
投票

条件是reserved word

sql = "INSERT INTO `tblcameras` (Company, Model, PurchaseDate,`Condition`, KitLens, PurchasePrice) VALUES (%s, %s, %s, %s, %s, %s)"
© www.soinside.com 2019 - 2024. All rights reserved.