Jump to content

[SOLVED] Var unassighn error (need to stop the error or go about this difrently)


supergrame

Recommended Posts

this is my problem

 

$var = "hi";

 

i only call this value if password and username fields are empty

 

my questions is can you stop the error or else set it to a value that wont show up untill the feilds are empty or am i trying to get this working in the wrong way.

 

ill post the page just in case i don't make scene witch happens allot

 

 

 

 

 

 

 

<?php
if($_POST) { 
require_once("constants.php");
// Asighning the posted form data to variables for later use!
$username = $_POST['username'];
$password = $_POST['password']; 


// Check if the username and password fields were not empty!
if(strlen($username) == 0 || strlen($password) == 0){
$var = "Please fill in all the required feilds";
} else {

// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql="SELECT * FROM users WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row

if($count==1){
// Register $username, $password and redirect to file!
session_register("username");
session_register("password"); 
header('Location: ../members/members.php');
}
else {
  header('Location: ../index.php');
}
}
}
?>









<html>
<head>
</head>
<body>
<div id="login">
<?php echo $var; ?>
<form method="post" action="">
<table>
  <tr>
    <td colspan="2" align="center">Login or Register!</td>
  </tr>
  <tr>
    <td><label for="username">Username:</label></td>
<td><input type="text" name="username"/></td>
  </tr>
  <tr>
	<td><label for="password">Password:</label></td>
<td><input type="password" name="password"/></td>
  </tr>
  <tr>
<td colspan="2" align="center"><input type="submit" id="submit" value="Login" name="submit" /></td>
  </tr>
</table>	
</form>
</div>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.