...

View Full Version : Validation problem



alpinhasov
03-12-2007, 01:08 AM
I have two pages. One is registration, and the other is validation to validate the input.

Register.php is as like this:
<form name="signup" action="validate.php" method="post">
<table width="751">
<tr>
<td width="78"><b>First Name</b></td>
<td width="185"><input type="text" name="fname" size="20" ></td>

<td width="79"><b>Last Name</b></td>
<td width="185"><input type="text" name="lname" size="20" ></td>
</tr>
</table>
<input type="submit" value="Continue>">
</form>

validate.php is as follows

<?php

//require("db.php");
$message="<b><font size=\"4\">Please enter your:</font></b> ";
$message= $message. "<font size=\"3\" color=\"#FF0000\">";
$returnValue = true;

//First name
if ($fname == "" || $fname == '')
{
$message = $message ."<b><br>First name";
$returnValue = false;
}
//Last name
if ($lname == "")
{
$message= $message . "<br>Last name ";
$returnValue = false;
}
if($returnValue)
{
session_start();

$_SESSION['fname'] = $fname ;
$_SESSION['lname'] = $lname ;
}
else
{
print("<html><head><link rel=\"stylesheet\" href=\"mystyles.css\" type=\"text/css\"><title>Data Validation</title></head>
<body class=\"validation\">");
print($message. "</font>");
print("<br><br><font size=\"3\" color=\"#0000FF\">Press the back button.</font></b>");
print("</body></html>");
}

It used to work before but stopped at some point. So even if I type the first name and last name it doesn't see it. Does anybody know why? Thank you.

printf
03-12-2007, 01:53 AM
Register Globals is most likely Off, which is good thing. Anyways to access your input variables, you need to use the SUPER GLOBAL that holds the input variables name value pairs -> name=value.

So your form, is using the method post, so your input variables if they are set, will be found in the SUPER_GLOBAL -> $_POST...


$_POST['fname'];
$_POST['lname'];


You script might look like this...


<?php

// don't use (), require is a language construct, not a function!

require 'db.php';

$message = $f_test = $l_test = '';

if ( isset ( $_POST['fname'] ) )
{
$f_test = trim ( $_POST['fname'] );

if ( empty ( $f_test ) )
{
$message .= '<br />First Name';
}
}

if ( isset ( $_POST['lname'] ) )
{
$l_test = trim ( $_POST['lname'] );

if ( empty ( $l_test ) )
{
$message .= '<br />Last Name';
}
}

if ( empty ( $message ) )
{
session_start();

$_SESSION['fname'] = $f_test;
$_SESSION['lname'] = $l_test;
}
else
{
?>
<html>
<head>
<link rel="stylesheet" href="mystyles.css" type="text/css">
<title>Data Validation</title>
</head>
<body class="validation">
<font size="4">
<b>
Please enter your:
</b>
</font>
<font size="3" color="#FF0000">
<b>
<?php echo $message; ?>
</b>
</font>
<br />
<br />
<font size="3" color="#0000FF">
<b>
Press the back button.
</b>
</font>
</body>
</html>
<?php
}
?>

alpinhasov
03-19-2007, 08:13 AM
Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum