Hello, I am new in php..here is my problem. I updated my server to the latest php and now I have problem with my code, it was working fine before, but after update i got errors like that
and it seems that the function VerifyForm doesn't returns the values.
here is my code:
the file config.php is the information for the mysql db
thank you in advice
Code:
Notice: Undefined index:
here is my code:
Code:
<?php
include("config.php");
function VerifyForm($values, $errors)
{
// checks
$nick_check = $values['nick'];
$nick_check2 = mysql_query("Select user_id from users where user_name='$nick_check'");
while($nick_check = mysql_fetch_array($nick_check2))
{
if($nick_check['user_id']>0)
$errors['nick'] = 'The username is alreade in use';
}
if (strlen($values['nick']) < 3)
$errors['nick'] = 'The username is too short';
elseif (strlen($values['nick']) > 32)
$errors['nick'] = 'The username is too long';
if (!explode('.*@.*\..{2,4}', $values['mail']))
$errors['mail'] = 'Email address invalid';
$mail_check = $values['mail'];
$mail_check2 = mysql_query("Select user_id from users where user_mail='$mail_check'");
while($mail_check = mysql_fetch_array($mail_check2))
{
if($mail_check['user_id']>0)
$errors['mail'] = 'The Email is already in use';
}
if (strlen($values['password']) < 5)
$errors['password'] = 'The password must be at least 5 symbols';
elseif ($values['password'] != $values['password2'])
$errors['password2'] = 'The passwords didn\'t match';
if ( $values['c'] != $values['captcha'])
$errors['captcha'] = 'Wrong answer!';
return (count($errors) == 0);
}
function DisplayForm($values, $errors)
{
srand (time(NULL));
$a = rand(1, 10);
$b = rand(1, 10);
$c=$a+$b;
if(!isset($errors))
{ $errors=null;}
?>
<html>
<head>
<title>Register New User</title>
<style>
TD.error
{
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<?php
if (count($errors) > 0)
echo "<p><font color='red'>There were some errors, please check again</font></p>";
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="nick" value="<?php htmlentities($values['nick']) ?>"/>
<td class="error"><?php $errors['nick'] ?></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="mail" value="<?php htmlentities($values['mail']) ?>"/>
<td class="error"><?php $errors['mail'] ?></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" value="<?php htmlentities($values['password']) ?>"/>
<td class="error"><?php $errors['password'] ?></td>
</tr>
<tr>
<td>Confirm:</td>
<td><input type="password" name="password2" value="<?php htmlentities($values['password2']) ?>"/>
<td class="error"><?php $errors['password2'] ?></td>
</tr>
<tr>
<td><?php echo $a.'+'.$b; ?> = </td>
<input type="hidden" name="c" value="<?php echo $c ?>"/>
<td><input type="text" name="captcha" value="<?php htmlentities($values['captcha']) ?>"/>
<td class="error"><?php $errors['captcha'] ?></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit">
</tr>
</table>
</form>
</body>
</html>
<?php
}
//make the insert
function ProcessForm($values)
{
$nick = $values['nick'];
$password = $values['password'];
$mail = $values['mail'];
$id = mysql_query("Select max(user_id) from users") ;
$user_id = mysql_fetch_array($id);
$user_id = $user_id['max(user_id)']+1;
$ip = GetHostByName($REMOTE_ADDR);
$password = sha1(md5(substr($nick, 0, 3) . $password));
mysql_query("Insert into users values
(
$user_id,
'$nick',
'$password',
'$mail',
now(),
INET_ATON('$ip'),
1,
1
)
");
echo "<a href='index.php'>index</a>";
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$formValues = $_POST;
$formErrors = array();
$formValues['nick'] = stripslashes($formValues['nick']);
$formValues['password'] = stripslashes($formValues['password']);
$formValues['nick'] = mysql_real_escape_string($formValues['nick']);
$formValues['password'] = mysql_real_escape_string($formValues['password']);
if (!VerifyForm($formValues, $formErrors))
{
DisplayForm($formValues, $formErrors );
}
else
ProcessForm($formValues);
}
else
{
DisplayForm(null, null);
}
?>
thank you in advice