Jump to content

login script - need help


princevnyt

Recommended Posts

Hi!

 

I need help with the login script i wrote. Please help me get it working. The section related to guest works fine however it always gives me error message when i get to the queryA and queryB stages. Thanks!

 

I've already got the database running, using MySQL. Name of database - connectiontracker; tables- user_admin, user_user

 

Here's the script:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/xhtml1-loose.dtd">

<?php

session_start();

$userType = $_POST["userType"];

$userName = $_POST["username"];

$passWord = $_POST["password"];

$link = mysqli_connect("localhost", "ct1", "ctcfgb") Or die('Could not connect '. mysqli_error());

switch ($userType)

{

case "admin":

if (isset($userName) && isset($passWord))

{

$dbTableA = "user_admin";

mysqli_select_db($link, "connectiontracker") Or die ("Database unavailable");

$queryA = "SELECT * FROM $dbTableA WHERE username='$userName' AND password='$passWord'";

$resultA = mysqli_query($queryA) or die("Verification Error A");

if(mysqli_num_rows($resultA) == 1)

{

$_SESSION = true;

header ('Location: welcomeadmin.php');

}

else echo "Incorrect administrator username and/or password";

}

break;

case "user":

if (isset($userName) && isset($passWord))

{

$dbTableB = "user_user";

mysqli_select_db($link, "connectiontracker") Or die ("Database unavailable");

$queryB = "SELECT * FROM $dbTableB WHERE username='$userName' AND password='$passWord'";

$resultB = mysqli_query($queryB) or die("Verification Error B");

if(mysqli_num_rows($resultB) == 1)

{

$_SESSION = true;

header ('Location: welcomeuser.php');

}

else echo "Incorrect Organization/Individual username and/or password";

}

break;

case "guest":

header ('Location: welcomeguest.php');

break;

}

if (!isset($_POST['Enter']))

{

?>

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Login to Connection Tracker</title>

<!-- <link rel="stylesheet" href="ct_style1.css" type="text/css"> -->

</head>

<body>

Please select from the following:

<br />

<form action="<?php echo $PHP_SELF;?>" method="post">

<select name="userType">

<option value="admin">Administrator</option>

<option value="user" selected>Organization</option>

<option value="guest">Guest</option>

</select>

<br />

Please leave the following fields blank if entering the system as Guest

<br />

Username: <input type="text" name="username">

<br />

Password: <input type="text" name="password">

<input type="submit" name="Enter"/>

<br />

</form>

</body>

</html>

<?php

}

mysqli_close($link);

?>

Link to comment
https://forums.phpfreaks.com/topic/214843-login-script-need-help/
Share on other sites

a simple way to see what is happening... change this:

die("Verification Error A");    // or the other

 

to this

die("Verification Error A <br />" . $queryA . "<br />" . mysql_error());

 

it should allow you to see the query that you are trying to execute and the associated error... after that you should be able to fix it

mysqli_query() requires two parameters. There are php errors that would be notifying you of that problem.

 

You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php errors would be reported and displayed. You will save a ton of time with these simple coding errors.

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.