Ik zou het zo doen:
Code:
<?php
error_reporting(E_ALL);
include("bestanden/verbinding.php");
$tabel = "totem";
if (isset($_POST['voornaam'])) {
$voornaam = addslashes($_POST['voornaam']);
} else {
$voornaam = "";
}
if (isset($_POST['naam'])) {
$naam = addslashes($_POST['naam']);
} else {
$naam = "";
}
if (isset($_POST['geboortedatum'])) {
$geboortedatum = addslashes($_POST['geboortedatum']);
} else {
$geboortedatum = "";
}
if (isset($_POST['totem'])) {
$totem = addslashes($_POST['totem']);
} else {
$totem = "";
}
if (isset($_POST['jaarTotem'])) {
$jaarTotem = addslashes($_POST['jaarTotem']);
} else {
$jaarTotem = "";
}
if (isset($_POST['adjectief'])) {
$adjectief = addslashes($_POST['adjectief']);
} else {
$adjectief = "";
}
if (isset($_POST['jaarAdjectief'])) {
$jaarAdjectief = addslashes($_POST['jaarAdjectief']);
} else {
$jaarAdjectief = "";
}
if (isset($_POST['jaarBelofteJG'])) {
$jaarBelofteJG = addslashes($_POST['jaarBelofteJG']);
} else {
$jaarBelofteJG = "";
}
if (isset($_POST['jaarBelofteG'])) {
$jaarBelofteG = addslashes($_POST['jaarBelofteG']);
} else {
$jaarBelofteG = "";
}
if (isSet($_POST['invoer'])) {
if ($naam == "") $error = "Je moet een voornaam invullen!";
elseif ($voornaam =="") $error = "Je moet je naam invullen!";
elseif ($geboortedatum =="");
elseif ($totem =="");
elseif ($jaarTotem =="");
elseif ($adjectief =="");
elseif ($jaarAdjectief =="");
elseif ($jaarBelofteJG =="");
elseif ($jaarBelofteG =="");
if (!isset($error)) {
if ($totem <> "") {
$update = "UPDATE" . $tabel . " SET Totem='" . $totem . "' WHERE Voornaam='" . $voornaam . "' AND Naam= '" . $naam . "'";
$query = mysql_query($update)or die(mysql_error());
}
if ($jaarTotem <> "") {
$update = "UPDATE" . $tabel . " SET jaarTotem='" . $jaarTotem . "' WHERE Voornaam='" . $voornaam . "' AND Naam= '" . $naam . "'";
$query = mysql_query($update)or die(mysql_error());
}
if ($tadjectief <> "") {
$update = "UPDATE" . $tabel . " SET adjectief='" . $adjectief . "' WHERE Voornaam='" . $voornaam . "' AND Naam= '" . $naam . "'";
$query = mysql_query($update)or die(mysql_error());
}
// en idem voor jaarAdjectief, jaarBelofteJG en jaarBelofteG
echo "Uw gegevens zijn aangepast";
} else {
echo $error;
}
}
?>
Als je het op jouw manier wil doen, zal je er iets als volgt van moeten maken:
Code:
<?php
error_reporting(E_ALL);
include("bestanden/verbinding.php");
$tabel = "totem";
if (isset($_POST['voornaam'])) {
$voornaam = addslashes($_POST['voornaam']);
} else {
$voornaam = "";
}
if (isset($_POST['naam'])) {
$naam = addslashes($_POST['naam']);
} else {
$naam = "";
}
if (isset($_POST['geboortedatum'])) {
$geboortedatum = addslashes($_POST['geboortedatum']);
} else {
$geboortedatum = "";
}
if (isset($_POST['totem'])) {
$totem = addslashes($_POST['totem']);
} else {
$totem = "";
}
if (isset($_POST['jaarTotem'])) {
$jaarTotem = addslashes($_POST['jaarTotem']);
} else {
$jaarTotem = "";
}
if (isset($_POST['adjectief'])) {
$adjectief = addslashes($_POST['adjectief']);
} else {
$adjectief = "";
}
if (isset($_POST['jaarAdjectief'])) {
$jaarAdjectief = addslashes($_POST['jaarAdjectief']);
} else {
$jaarAdjectief = "";
}
if (isset($_POST['jaarBelofteJG'])) {
$jaarBelofteJG = addslashes($_POST['jaarBelofteJG']);
} else {
$jaarBelofteJG = "";
}
if (isset($_POST['jaarBelofteG'])) {
$jaarBelofteG = addslashes($_POST['jaarBelofteG']);
} else {
$jaarBelofteG = "";
}
if (isSet($_POST['invoer'])) {
if ($naam == "") $error = "Je moet een voornaam invullen!";
elseif ($voornaam =="") $error = "Je moet je naam invullen!";
if (!isset($error)) {
$selecteer = "SELECT * FROM $tabel WHERE Voornaam='$voornaam' AND Naam= '$naam' LIMIT 1";
$query = mysql_query($selecteer)or die(mysql_error());
while($oude_gegevens = mysql_fetch_object($query)) {
if ($geboortedatum =="") $geboortedatum = $oude_gegevens->Geboortedatum;
if ($totem =="") $totem = $oude_gegevens->Totem;
if ($jaarTotem =="") $jaarTotem = $oude_gegevens->jaarTotem;
if ($adjectief =="") = $oude_gegevens->Adjectief;
if ($jaarAdjectief =="") = $oude_gegevens->jaarAdjectief;
if ($jaarBelofteJG =="") = $oude_gegevens->jaarBelofteJG;
if ($jaarBelofteG =="") = $oude_gegevens->jaarBelofteG;
}
$update = "UPDATE" . $tabel . " SET Geboortedatum='" . $geboortedatum ."', Totem='" . $totem . "', jaarTotem='" . $jaarTotem . "', Adjectief='" . $adjectief . "', jaarAdjectief='" . $jaarAdjectief . "', jaarBelofteJG='" . $jaarBelofteJG . "', jaarBelofteG='" . $jaarBelofteG . "' WHERE Voornaam='" . $voornaam . "' AND Naam= '" . $naam . "'";
$query = mysql_query($update)or die(mysql_error());
echo "Uw gegevens zijn aangepast";
} else {
echo $error;
}
}
?>
To