Poceo sam da vezbam primere iz knjige,ali ova forma nece da radi.
Evo html forme koja je ispravna:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Project p-7-1</title>
</head>
<body>
<form method="post"action="p-7-1">
<h1>Contact information</h1>
<table>
<tr>
<td>Nickname:</td>
<td><input type="text"name="nickname"></td>
</tr>
<tr>
<td>Firstname:</td>
<td><input type="text"name="firstname"></td>
</tr>
<tr>
<td>Lastname:</td>
<td><input type="text"name"lastname"></td>
</tr>
<tr>
<td>Primary Email:</td>
<td><input type="text"name="email"></td>
<td width"20"> </td>
<td>Secondary Email:</td>
<td><input type="text"name"secondaryemail"></td>
</tr>
<tr>
<td>Company name:</td>
<td><input type="text"name="companyname"></td>
</tr>
<tr>
<td>Office Address:</td>
<td><input type="text"name="officeaddress"></td>
<td width"20"> </td>
<td>Home Address:</td>
<td><input type="text"name="homeaddress"></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text"name="city"></td>
</tr>
<tr>
<td>State</td>
<td><input type="text"name="state"></td>
</tr>
<tr>
<td>Zip:</td>
<td><input type="text"name="zip"></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text"name="phone"></td>
</tr>
</table>
<br>
<br>
<br>
<br>
<input type="submit"value="Submit">
<br>
<br>
<input type="reset"value="Reset">
</form>
</body>
</html>
Problem je verovatno u ovoj PHP scripti,koja izgleda ovako:
<?php
include "p-7-1";
function validate_form()
{
global $nickname,$firstname,$lastname,$email;
$errors=0;
if(!trim($nickname))
{
echo"<br><b>Nickname</b>is required";
errors++;
}
if(!trim($firstname))
{
echo"<br><b>Firstname</b>is required";
errors++;
}
if(!trim($lastname))
{
echo"<br><b>Lastname</b>is requires";
errors++;
}
if(!trim(email))
{
echo"<br><b>Email</b>is required";
$errors++;
} switch($errors)
{
case 0;
return TRUE;
case 1;
echo"<br><br>Please use your";
echo"browser back button to return to";
echo"the form,correct the errors,and";
echo"re-submit the form";
return FALSE;
}
}
function update_database()
{
echo"<br>Updating database...";
}
$ok=validate_form();
if($ok)
update_database();
?>