I'm trying to put events of our coverband in a database. I want to correct the typo of every record, if required for any case. Here is a live version of the webapp
The problem is: I have made a link to change the record called: "wijzig agendapunt" in the index.php file (which is working fine). A php file takes the text from database and puts it in a form(so far so good). When I think everything is correct I press: "wijzig". Then another php file starts to update in database with correct text. But here it goes wrong.
I hope you guys can help me! Thank you! :)
Code snippet for database connection:
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();
}
?>
Then the php file with the form:
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>
After filling up the form completely I have triggered the next php file. But it doesn't update the data to the database. I can't figure out why
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>