Jump to content

PHP form help


cry of war

Recommended Posts

I am kind of new to PHP form files and was wondering if this was set up correct. I took this from parts of a book I am reading. This is my 2nd try at it. I havent tested this yet because I cant get on my server ATM but the first time I tried the whole page was blank including the Source code.

<?
$page = "form1.php"
?>
<html>
<head>
<style type="text/css">
.error {color:red;}
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
fuction error_flag($error, $field) {
if($error[$field]) {
print ("<td class=error>");
} else {
print ("<td>");
}
}

funtion print_form() {
global $error, $print_again, $first, $last, $page;
?>
<form action="<?echo $page ?>" method="post">
<?
if($print_again) {
?><h3> You missed some fields. Please correct the <span class=error>red</span> fields.<?
} else {
/><h3> Please fill-in the following fields.<h3><?
}
?>
<table border="0">
<tr><td><? error_flag($error, "first"): ?> First Name:</td>
<td><input type="text" name="first" value="<?=$first ?>"></td></tr>
<tr><td><? error_flag($error, "last"): ?> Last Name:</td>
<td><input type="text" name="last" value="<?=$last ?>"></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" name="submit" value="Submit Form"></td></tr>
</table>
</form>
<?
}

function check_form() {
global $error, $print_again, $first, $last;
$error['first'] = false;
$error['last'] = false;
$print_again = false;
if($first == "") {
$errror['first'] = true;
$print_again = true;
}
if($last == "") {
$errror['last'] = true;
$print_again = true;
}
if($print_again) {
print_form();
} else {
print("<h3>Thank you for copleting the form!</h3>");
}
}


if(isset($submit)) {
check_form();
} else {
print_form();
}
?>
</body>
</html>

Link to comment
Share on other sites

Yes, it's not very secure. Basically the difference is when you are passing variables from one page to another you should reference variables like this

 

Instead of $variable use $_GET['variable'] or $_POST['variable'] depending on how the data is passed from one page to another.

;)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.