i know the best approach when programming is not to disable errors,i have been getting a series of errors ever since i started making my simple web forum,i have tried to get ride of some but i am having a problem with some,the undefined variable
is the most common error and it seems like i have to declare some like A='';
then A=values;
for example but i have no idea how i can tackle this one below
Notice: Undefined variable: act in C:\xampp\htdocs\mysite\forum part two\login.php on line 74
the code on line 74 is this
case "login";
and my other code where there is login
is this in the login.php
switch($act){
default;
index();
break;
case "login";
login();
break;
}
my code on the login.php
is this
<?php
session_start();
//This displays your login form
function index(){
echo "<form action='?act=login' method='post'>"
."Username: <input type='text' name='username' size='30'><br>"
."Password: <input type='password' name='password' size='30'><br>"
."<input type='submit' value='Login'>"
."</form>";
}
//This function will find and checks if your data is correct
function login(){
//Collect your info from login form
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
//Connecting to database
$connect = mysql_connect("localhost", "root", "nokiae71");
if(!$connect){
die(mysql_error());
}
//Selecting database
$select_db = mysql_select_db("forumStructure", $connect);
if(!$select_db){
die(mysql_error());
}
//Find if entered data is correct
$result = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
$row = mysql_fetch_array($result);
$id = $row['id'];
$select_user = mysql_query("SELECT * FROM users WHERE id='$id'");
$row2 = mysql_fetch_array($select_user);
$user = $row2['username'];
if($username != $user){
die("Username is wrong!");
}
$pass_check = mysql_query("SELECT * FROM users WHERE username='$username' AND id='$id'");
$row3 = mysql_fetch_array($pass_check);
$email = $row3['email'];
$select_pass = mysql_query("SELECT * FROM users WHERE username='$username' AND id='$id' AND email='$email'");
$row4 = mysql_fetch_array($select_pass);
$real_password = $row4['password'];
if($password != $real_password){
die("Your password is wrong!");
}
//Now if everything is correct let's finish his/her/its login
session_register("username", $username);
session_register("password", $password);
echo "Welcome, ".$username." please continue on our <a href=index.php>Index</a>";
}
switch($act){
default;
index();
break;
case "login";
login();
break;
}
?>