我试图将我们的封面带事件放入数据库中。如果需要,我想纠正每条记录的拼写错误。 Here is a live version of the webapp
问题是:我已经建立了一个链接来更改名为:" wijzig agendapunt"在index.php文件中(工作正常)。一个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>
答案 0 :(得分:0)
来自editmarker.php,您没有发布event
属性。并在editedmarker.php中验证它,而不是发布naam
。
您将在错误日志文件中收到此错误,
您应该始终关闭错误日志文件
由于 -Shahram