Hello there,
I/ve been working on a script that dynamically fills a form with data from a DB with SQL. This all worked fine until I wanted to build in some validation so I could be sure no-one delete the formfield and then send an empty field to the database.
I tried using the following code...
<html>
<body>
<font face="arial" >
<?php
$conn=odbc_connect('test','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="SELECT NAAM FROM test1 WHERE Id1 IN (355)";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
while (odbc_fetch_row($rs))
{
$naam=odbc_result($rs,"NAAM");
$newnaam = $naam;
if ($naam == "") echo "<td> </td></tr>";
else
echo "<td>$naam</td></tr>";
}
?>
<?php
// only validate form when form is submitted
if(isset($submit_button)){
$error_msg='';
if(trim($newnaam)=="" ) {
$error_msg.="U mag geen leeg veld invoeren<br>";
}
// display error message if any, if not, proceed to other processing
if($error_msg==''){
// other process here
} else {
echo "<font color=red>$error_msg</font>";
}
}
?>
<form action="updatehandler.php" method="post">
NAAM PAKKET: <input type="text" name="naampakket" size="50" value=" <?php echo $newnaam; ?> "><br/>
<input type="Submit" name="submit_button" value="Wijzigen">
</form>
<?php
odbc_close($conn);
echo "</table>";
?>
</font>
</body>
</html>
I hope someone can help me...