php5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

php5

Post by hrubos »

I have received error : "Notice: Undefined variable: emai" ???
I have error because mycode isn't for PHP5??? Do you think that? or somewhere are mistakes???

Code: Select all

<?php
Header("Pragma: No-cache");
Header("Cache-Control: No-cache, Must-revalidate");
Header("Expires: ".GMDate("D, d M Y H:i:s")." GMT");

$MC = MySQL_Connect("localhost", "root", "ha1985");
$MS = MySQL_Select_DB("kolej");

If (($email != "") AND ($password != "") AND ($login != "") AND ($name != "")):
$MSQ = MySQL_Query("SELECT * FROM users WHERE login LIKE '$login'");
If (MySQL_Num_Rows($MSQ) > 0):
$login = "";
$error = "<h4>Login již existuje!!!</h4>";
$f = "true";
Else:
$p = MD5($password);
$MSQ = MySQL_Query("INSERT INTO users VALUES (NULL, '$login', '$p', '$name', '$email')");
$m = "true";
$x = StrLen($password);
Endif;

Elseif (IsSet($send)):
$error = "<h4>Chybí povinné údaje!!!</h4>";
Endif;
?>
<html>
<head>
<title>Registrace nového uživatele</title>
</head>

<body>
<h3 align="center">Registrace nového uživatele</h3>
<?php
If ((IsSet($error)) OR (!IsSet($send))):
echo $error;
?>
<form method="post" action="registrace.php">
<input type="Hidden" name="send" value="true">
<table>
<tr>
<td>Login:</td>
<td><input type="Text" name="login" size="40" maxlength="20" value="<?php echo $login;?>"></td>
</tr>
<tr>
<td>Heslo:</td>
<td><input type="Password" name="password" size="40" maxlength="20" value=""></td>
</tr>
<tr>
<td>Emailová adresa:</td>
<td><input type="Text" name="email" size="40" maxlength="80" value="<?php echo $email;?>"></td>
</tr>
<tr>
<td>Jméno:</td>
<td><input type="Text" name="name" size="40" maxlength="80" value="<?php echo $name;?>"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="Submit" value="Zaregistrovat">
</td>
</tr>
</table>
</form>
<?php Elseif (IsSet($m)):?>
Byl(a) jste úsp&#283;šn&#283; zaregistrován(a) s t&#283;mito údaji:
<b>P&#345;ihlašovací jméno</b>: <?php echo $login;?>
<b>Heslo</b>: <?php For ($i = 1; $i <= $x; $i++): echo "*"; Endfor;?>
<b>Jméno</b>: <?php echo $name;?>
<b>Emailová adresa</b>: <?php echo $email;?>
<?php Endif;?>
</body>
</html>
<?php MySQL_Close($MC);?>
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Notice the spelling mistake: "Notice: Undefined variable: emai"
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

that's because in that script you haven't defined $email yet, but you try to use it anyway:

Code: Select all

<?php
Header("Pragma: No-cache");
Header("Cache-Control: No-cache, Must-revalidate");
Header("Expires: ".GMDate("D, d M Y H:i:s")." GMT");

$MC = MySQL_Connect("localhost", "root", "ha1985");
$MS = MySQL_Select_DB("kolej");

// $email hasn't been defined anywhere, and neigher have any of these other variables...
If (($email != "") AND ($password != "") AND ($login != "") AND ($name != "")):
If you are expecting these to be $_POST or $_GET variables, you need to call them like this $_POST['email'] and $_POST['password']... look up "register_globals and security"... you don't want register_globals on
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post by hrubos »

Who can explain for me that why does it run when I use $_POST[] and I code in 2 classes.(I use PHP 5)???

I use the same code, I have only change method $_POST

version 2 registrace.php

Code: Select all

<html>
<head>
<title>Registrace nového uživatele</title>
</head>

<body>
<h3 align="center">Registrace nového uživatele</h3>
<?php
$login 
?>
<form method="post" action="registrace_DB.php">
<input type="Hidden" name="send" value="true">
<table>
<tr>
<td>Login:</td>
<td><input type="Text" name="login" size="40" maxlength="20"></td>
</tr>
<tr>
<td>Heslo:</td>
<td><input type="Password" name="password" size="40" maxlength="20" value=""></td>
</tr>
<tr>
<td>Emailová adresa:</td>
<td><input type="Text" name="email" size="40" maxlength="80" ></td>
</tr>
<tr>
<td>Jméno:</td>
<td><input type="Text" name="name" size="40" maxlength="80" ></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="Submit" value="Zaregistrovat">
</td>
</tr>
</table>
</form>
</body>
</html>
registrace_DB

Code: Select all

<?php
Header("Pragma: No-cache");
Header("Cache-Control: No-cache, Must-revalidate");
Header("Expires: ".GMDate("D, d M Y H:i:s")." GMT");

$email = $_POST['email'];
$password = $_POST['password'];
$login = $_POST['login'];
$name = $_POST['name'];





$MC = MySQL_Connect("localhost", "root", "ha1985");
$MS = MySQL_Select_DB("kolej");

 if(!$email||!$password||!$login||!$name){
  echo 'T&#345;eba vyplnit upnle informace !!!';
  exit;
 }
 if(!get_magic_quotes_gpc())
 {
 $email = addslashes($email);
 $password  = addslashes($password);
 $login  = addslashes($login);
 $name  = addslashes($name);
 
 }
$MSQ = MySQL_Query("SELECT * FROM users WHERE login LIKE '$login'") or die(mysql_error());
if (MySQL_Num_Rows($MSQ) > 0){
$login = "";
$error = "<h4>Login již existuje!!!</h4>";
$f = "true";
}
else {
$p = MD5($password);
$MSQ = MySQL_Query("INSERT INTO users VALUES (NULL, '$login', '$p', '$name', '$email')") or die(mysql_error());;
$m = "true";
$x = StrLen($password);
}

if ((IsSet($error)) OR (!IsSet($send))){
echo $error;
}
if (IsSet($m)){
echo "Byl(a) jste úsp&#283;šn&#283; zaregistrován(a) s t&#283;mito údaji:";
echo "<b>P&#345;ihlašovací jméno</b>: "; 
echo $login;
echo "<b>Heslo</b>: ";
for ($i = 1; $i <= $x; $i++){
 echo "*";
 }
 echo "<b>Jméno</b>: ";
  echo $name;
echo "<b>Emailová adresa</b>:";
 echo $email;
}

//<?php MySQL_Close($MC);?>
?>
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

hrubos wrote:Who can explain for me that why does it run when I use $_POST[]
Because $_POST is the array that contains the variables that were posted to that particular page. There is a setting in php.ini that extracts this array into the global namespace so that you can just call them like any other variable and it's called "register_globals". Using register_globals is a n00b move... very bad practice. Also a big security risk... look it up on Google or wikipedia, (type in "register_globals").
hrubos wrote:and I code in 2 classes.(I use PHP 5)???
What??
hrubos wrote:I use the same code, I have only change method $_POST
uhh ??
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post by hrubos »

The Ninja Space Goat wrote:
hrubos wrote:
hrubos wrote:and I code in 2 classes.(I use PHP 5)???
What??
hrubos wrote:I use the same code, I have only change method $_POST
uhh ??
this is only about how did I changed.

Thanx bro!!!
Post Reply