I'm in the process of creating a form but I'm running into a problem. I'm not that experienced with php/sql so I'll define what i need here.
There is a field called "klantnummer" that needs to be in a fixed format. The format will be as followed "xxxx-yyy". Where xxxx will be the year (eg 2008, 2009, ....), - will be the mandatory divider, and yyy will be another number but not fixed in length. A valid number would be like 2008-001 or 2009-1 or 2009-03. The fixed part is "xxxx-", that will always stay like that.
To see if a "klantnummer" is valid, it needs to verify if the "klantnummer" exists in the database "klanten". I know there is a function or somethin called mysql_fetch_object but i don't really know how to use it or if there is a simpler way.
The page that has the form coded is separate.
eg page : index.php has the form created in HTML > form action = processing.php
what i have so far for processing.php is this.
<?php
session_start();
$naam=$_POST['naam'];
$voornaam=$_POST['voornaam'];
$email=$_POST['email'];
$klantnummer=$_POST['klantnummer'];
$afdeling=$_POST['afdeling'];
$onderwerp=$_POST['onderwerp'];
$bericht=$_POST['bericht'];
$secure = trim(strip_tags($_POST['secure']));// leave case as entered
$match = $_SESSION['captcha']; // the code on the image
if (($secure!=$match) && ($secure!=""))
{
echo "<link rel='stylesheet' href='../../../../templates/techline_de_template-j15-001/style2.css' />Security code ongeldig.<br/>Ga <a href=\"javascript:history.go(-1)\">Terug</a> en probeer opnieuw. ";
}
if ($secure=="")
{
echo "<link rel='stylesheet' href='../../../../templates/techline_de_template-j15-001/style2.css' />Security code niet ingevuld.<br/> Ga <a href=\"javascript:history.go(-1)\">Terug</a> en probeer opnieuw.";
}
elseif(($secure==$match) && ($secure!=""))
{
if (($naam=="") || ($voornaam=="") || ($email=="") || ($klantnummer=="") || ($afdeling=='kies') || ($onderwerp=="") || ($bericht==""))
{
echo "<link rel='stylesheet' href='../../../../templates/techline_de_template-j15-001/style2.css' />1 of meerdere velden niet ingevuld.<br/>Ga <a href=\"index.php\">Terug</a> en probeer opnieuw.";
}
elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
{
echo "<link rel='stylesheet' href='../../../../templates/techline_de_template-j15-001/style2.css' />Ongeldig e-mail adres ingevuld.<br/>Ga <a href=\"index.php\">Terug</a> en probeer opnieuw.";
}
/* klantnummer field formatcheck goes here. Based on klantnummer, extra info will be retrieved from database */
else
{
?>
<html>
<head>
<link rel="stylesheet" href="../../../../templates/techline_de_template-j15-001/style2.css" />
</head>
<body>
<form action="send.php" method="post">
<table>
<tr>
<th colspan="2">Gelieve onderstaande gegevens te controleren.</th>
</tr>
<tr>
<td>Naam: <?php echo $naam ?><input type="hidden" name="naam" value="<?php echo $naam ?>" /></td>
<td>Voornaam: <?php echo $voornaam ?><input type="hidden" name="voornaam" value="<?php echo $voornaam; ?>"/></td>
</tr>
<tr>
<td colspan="2">E-Mail: <?php echo $email ?><input type="hidden" name="email" value="<?php echo $email ?>"/></td>
</tr>
<tr>
<td>Klantnummer: <?php echo $klantnummer ?><input type="hidden" name="klantnummer" value="<?php echo $klantnummer ?>"/></td>
<td>Bestemd voor: <?php echo $afdeling ?><input type="hidden" name="afdeling" value="<?php echo $afdeling ?>" /></td>
</tr>
<tr>
<td align="center" colspan="2">Onderwerp: <?php echo $onderwerp ?><input type="hidden" name="onderwerp" value="<?php echo $onderwerp ?>"/></td>
</tr>
<tr>
<td align="center" colspan="2">Uw bericht<br /><?php echo $bericht ?><br /><input type="hidden" name="bericht" value="<?php echo $bericht ?>" /></td>
</tr>
<tr>
<td colspan="2" align="center">Is dit correct ? Zoja druk op versturen. Indien niet druk op herbeginnen.</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Versturen" /><input type="reset" value="Herbeginnen" onClick="window.location.href=index.php"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
}
?>
ps: is there a way to change my username :p i havent used "TheAvenger" in years :p