2016-12-01 66 views
0

我试图将我们的coverband事件放入数据库中。如果需要,我想纠正每个记录的错字。 Here is a live version of the webapp更新数据库记录不起作用

问题是:我已经做了一个链接,改变index.php文件(工作正常)中名为“wijzig agendapunt”的记录。一个PHP文件从数据库中获取文本并将其放置在一个表单中(迄今为止非常好)。当我认为一切正确时,我按下:“wijzig”。然后另一个php文件开始用正确的文本在数据库中更新。但是这里出错了。

我希望你们能帮助我!谢谢! :)数据库连接

代码片段:

connect.php

<?php 
    try { 
    $conn = new PDO("mysql:host=localhost;dbname=davyschouw_app",  
    'davyschouw_app', '***'); 
// set the PDO error mode to exception 
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    } 
catch(PDOException $e) 
{ 
    echo "Connection failed: " . $e->getMessage(); 
} 
?> 

然后与形式的PHP文件:

editmarker.php

<body> 

<?php 
include "connect.php"; 

    $record_name = $_GET["id"]; 


    echo $record_name; 

    $sth = $conn -> prepare(" 

     SELECT * 
     FROM addmarker 
     WHERE id = :record_name 

    "); 

    $sth -> bindValue(":record_name", $record_name, PDO::PARAM_STR); 

    $sth -> execute(); 

    $printRecord = $sth -> fetchAll(PDO::FETCH_ASSOC); 

    /* 
    //dit record als array weergeven 
    print("<pre>"); 
    print_r($printRecord); 
    print("</pre>"); 
    */ 

    //gegevens in variabelen zetten 
    $printRecordRecord = $printRecord[0]; 
    $huidigeNaam = $printRecordRecord["event"]; 
    $huidigAdres = $printRecordRecord["address"]; 
    $huidigeDatum = $printRecordRecord["date"]; 
    $huidigeSets = $printRecordRecord["sets"]; 
    $huidigeTijd = $printRecordRecord["time"]; 
    $huidigeBeschrijving = $printRecordRecord["description"]; 
    $huidigeLink = $printRecordRecord["tickets"]; 

    print(" 

     <form action='editedmarker.php' method='POST'> 
      <table> 

       <tr> 
        <td bgcolor='green'><b>Naam</b></td> 
        <td bgcolor='green'><b>Adres</b></td> 
        <td bgcolor='green'><b>Datum</b></td> 
        <td bgcolor='green'><b>Sets</b></td> 
        <td bgcolor='green'><b>Tijd</b></td> 
        <td bgcolor='green'><b>Beschrijving</b></td> 
        <td bgcolor='green'><b>Tickets</b></td> 
        <td bgcolor='green'></td> 
       </tr> 

       <tr> 
        <td><input type='text' name='naam' value='$huidigeNaam'/></td> 
        <td><input type='text' name='address' value='$huidigAdres' /></td> 
        <td><input type='text' name='date' value='$huidigeDatum' /></td> 
        <td><input type='text' name='sets' value='$huidigeSets'/></td> 
        <td><input type='text' name='time' value='$huidigeTijd' /></td> 
        <td><input type='text' name='description' value='$huidigeBeschrijving' /></td> 
        <td><input type='text' name='tickets' value='$huidigeLink' /></td> 
        <td><input type='submit' value='Wijzig' /></td> 
       </tr> 

      </table> 
     </form> 

    "); 

?> 

</body> 

完全填充表单后,我触发了下一个php文件。但它不会将数据更新到数据库。我想不通为什么

editedmarker.php

<head> 
<title>Gewijzigd</title> 
</head> 

<body> 

<?php 
include "connect.php"; 

    //geupdate gegevens ophalen 
    $newEvent = $_POST["event"]; 
    $newAddress = $_POST["address"]; 
    $newDate = $_POST["date"]; 
    $newSets = $_POST["sets"]; 
    $newTime = $_POST["time"]; 
    $newDescription = $_POST["description"]; 
    $newTickets = $_POST["tickets"]; 

    //gegevens updaten als ALLES is ingevuld 
    if (($newEvent != "") && ($newAddress != "") && ($newDate != "") && ($newSets != "") 
    && ($newTime != "") && ($newDescription != "") && ($newTickets != "")) { 


     $sth = $conn -> prepare(" 

      UPDATE addmarker 
      SET event = :event, 
      address = :address, 
      date = :date, 
      sets = :sets, 
      time = :time, 
      description = :description, 
      tickets = :tickets 
      WHERE event = :event 

     "); 

     $sth -> bindValue(":event", $newEvent, PDO::PARAM_STR); 
     $sth -> bindValue(":address", $newAddress, PDO::PARAM_STR); 
     $sth -> bindValue(":date", $newDate, PDO::PARAM_STR); 
     $sth -> bindValue(":sets", $newSets, PDO::PARAM_STR); 
     $sth -> bindValue(":time", $newTime, PDO::PARAM_STR); 
     $sth -> bindValue(":description", $newDescription, PDO::PARAM_STR); 
     $sth -> bindValue(":tickets", $newTickets, PDO::PARAM_STR); 

     $sth -> execute(); 

     $sthCheck = $conn -> prepare(" 

      SELECT * 
      FROM addmarker 
      WHERE event = :event 

     "); 

     $sthCheck -> bindValue(":event", $newEvent, PDO::PARAM_STR); 

     echo "Number of records changed: ".$sthCheck -> execute(); 

    } 
    else { 
     echo "NO success"; 
    } 

?> 

</body> 
+1

回应您的查询,检查数据库的直接第一,如果其作品那么那里也应该在这里工作。 – Deep

+1

您不能重复使用占位符。 (请参阅':event')。 –

+0

您设置了'PDO :: ERRMODE_EXCEPTION',但您不会在try/catch块中运行您的查询。所以你从来不打扰寻找有用的错误消息,PDO会产生_I认为这就是所谓的忽略流氓明显_ – RiggsFolly

回答

0

从editmarker.php你不张贴event属性。并在editedmarker.php中进行验证,而不是发布naam。 你会在错误日志文件中收到此错误,

你应该总是尾错误日志文件,

感谢 -Shahram