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
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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