我的项目中的“更新”查询有问题

时间:2019-06-23 15:54:46

标签: mysql node.js express

我需要更新“预订”中的值,但更新查询不起作用。我设置了新值,但没有任何变化。值保持不变。顺便说一句,它没有给出错误。只是查询不会更改值。我需要你的帮助。我不明白问题出在哪里。

server.js:

app.get("/edit/:id", function(req, res){
    const idBooking = req.params.idBooking;
    pool.query("SELECT * FROM booking WHERE idBooking=?", [idBooking], function(err, data) {
      if(err) return console.log(err);
       res.render("edit.hbs", {
          booking: data[0]
           });
     });
      });


 app.post("/edit", urlencodedParser, function (req, res) {

     

if(!req.body) return res.sendStatus(400);
      const Parties_idParties = req.body.Parties_idParties;
         const Halls_idHalls = req.body.Halls_idHalls;
          const Duration = req.body.Duration;
    const Price = req.body.Price;
        const Year = req.body.Year;
     const Mounth = req.body.Mounth;
      const Day = req.body.Day;
      const Time = req.body.Time;
           const idBooking = req.body.idBooking;
            pool.query("UPDATE booking SET Parties_idParties=?, Halls_idHalls=?, Duration=?, Price=?, Year=?, Mounth=?, Day=?, Time=? WHERE idBooking=?", [Parties_idParties, Halls_idHalls, Duration, Price, Year, Mounth, Day, Time, idBooking], function(err, data) {
       if(err) return console.log(err);
       res.redirect("/dashboard");
  });
   });

edit.hbs:

 <!DOCTYPE html>
    <html>
    <link rel="stylesheet" type="text/css" href="/css/style.css">
    <head>
    <title>Редактирование пользователя</title>
    </head>
    <body>

    <div class="fullscreen-bg">
     <div class="main-log3">


      <span class="book_title"> Редактирование </span> <br>
     <form action="/edit" method="POST">
        <input type="hidden" name="idBooking" value="{{booking.idBooking}}"/>
        <label>Time</label><br>
        <input name="time"  value="{{booking.Time}}"  class="field" /><br> 
        <br>

        <label>Day</label><br>
        <input name="day"  value="{{booking.Day}}"  class="field" /><br><br>

        <label>Mounth</label><br>
        <input name="Mounth"  value="{{booking.Mounth}}"  class="field" /> 
        <br><br>

        <label>Year</label><br>
        <input name="Year" value="{{booking.Year}}"  class="field" /><br><br>

        <label>Price</label><br>
        <input name="Price"  value="{{booking.Price}}"  class="field" /><br> 
        <br>

        <label>Duration</label><br>
        <input name="Duration"  value="{{booking.Duration}}"  class="field" /><br><br>

        <label>Hall</label><br>
        <input name="Halls_idHalls" value="{{booking.Halls_idHalls}}"  class="field" /><br><br>

        <label>Party</label><br>
        <input name="Parties_idParties" value="{{booking.Parties_idParties}}"  class="field" /><br><br>

         <input type="submit" value="Отправить" />
         </form>

          <a href="/dashboard">К списку пользователей</a>

          </div>

           <video loop muted autoplay poster="video/plane.jpg" class="fullscreen-bg__video" width="100%" height="auto" autoplay="autoplay" loop="loop" preload="auto">
     <source src="/club_v.mp4" type="video/mp4">

           </video>
            </div>


            </body>
            <html>

dashboard.hbs:

   <!DOCTYPE html>
   <html>
     <link rel="stylesheet" type="text/css" href="/css/style.css">
    <head>
    <title>database</title>
  </head>
  <body>
   <div class="site-style">





 <div class="fullscreen-bg">
    <div class="main-log1"><span class="book_title">  мероприятия </span> <br> <table class="table" border="1" width="100%" cellpadding="5">
        <tr><th>Time</th><th>Day</th><th>Mounth</th><th>Year</th> 
     <th>Price</th><th>Duration</th><th>Halls_idHalls</th> 
    <th>Parties_idParties</th><th></th></tr>
        {{#each booking}}
            <tr>

                <td>{{this.Time}}</td>
                                <td>{{this.Day}}</td>
        <td>{{this.Mounth}}</td>
      <td>{{this.Year}}</td>
         <td>{{this.Price}}</td>
         <td>{{this.Duration}}</td>
       <td>{{this.Halls_idHalls}}</td>
        <td>{{this.Parties_idParties}}</td>
 
                <td>
                    <a href="/edit/{{this.idBooking}}">Edit</a>
                    <form action="delete/{{this.idBooking}}" method="POST" style="display: inline;">
                        <input type="submit" value="Delete" />
                    </form>
                </td>
            </tr>
        {{/each}}
    </table>
      </div>

    <video loop muted autoplay poster="video/plane.jpg" class="fullscreen-bg__video" width="100%" height="auto" autoplay="autoplay" loop="loop" preload="auto">
    <source src="club_v.mp4" type="video/mp4">

</video>
</div>

 </body>
 </html>

1 3

1 个答案:

答案 0 :(得分:0)

中的小写字母可能是 d ay和<< strong> t ime
<input name="date">
<input name="time">

发送键区分大小写和要求的正文。 D 日期和要求的正文。 T ime大写