<?php
function valid_email ($email) {
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors = array ();
$naam = strip_tags ($_POST['naam']);
$naam = trim ($naam);
if (empty ($naam)) {
array_push ($errors, '<p>Geen naam ingevuld</p>');
}
if (!valid_email ($_POST['email'])) {
array_push ($errors, '<p>Ongeldig e-mailadres</p>');
}
$naam = mysql_real_escape_string ($naam);
$email = mysql_real_escape_string ($_POST['email']);
if (empty ($errors)) {
$sql = "
INSERT INTO donatie
SET
name = '" . $naam . "',
email = '" . $email . "',
datum = NOW(),
ip = '".$a."'
";
if (!mysql_query ($sql)) {
trigger_error (mysql_error ());
}
}
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Mail Formulier</title>
<style type="text/css">
label {
cursor: pointer;
float: left;
width: 200px;
text-align: right;
padding: 2px;
}
label, p, input {
font: 12px verdana;
}
h1 {
font: bold 14px arial;
color: blue;
}
#errors {
margin: 0px auto;
width: 400px;
border: 1px solid red;
padding: 9px;
font: 14px courier;
}
</style>
</head>
<body>
<h1>Vul uw naam en een geldig e-mailadres in</h1>
<form method="post" action="#">
<p>
<label for="naam">naam:</label>
<input name="naam" type="text" value="<?php if (isset ($_POST['naam'])) echo htmlentities ($_POST['naam']); ?>">
</p>
<p>
<label for="email">e-mail:</label>
<input name="email" type="text" value="<?php if (isset ($_POST['email'])) echo htmlentities ($_POST['email']); ?>">
<input type="submit" value="verzenden">
</p>
</form>
<?php
if (isset ($errors) && !empty ($errors)) {
echo '<div id="errors">';
foreach ($errors as $value) {
echo $value;
}
echo '</div>';
}
?>
</body>
met dank
[edit]Code tags toegevoegd. Ik kan me niet voorstellen dat style sheets nuttige en relevante code zijn. Volgende keer weg laten aub. [/edit]