calebandchels
11-18-2011, 05:23 PM
I have checked over multiple times and I'm sure it's something stupid. I am new to debugging code I never used the or die(mysqli_error()) till this try by myself. If you can point me into the right direction I would appreciate it.
<?php
require_once('../php_scripts/appvar.php');
//if the user isn't logged, try to log in
if(!isset($_SESSION['id']))
{
if(isset($_POST['login_submit']))
{
//connect to database
$dbc = mysqli_connect($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_NAME)
or die(mysqli_error());
//grab the user input data
$user_login = mysqli_real_escape_string($dbc, trim($_POST['login']));
$user_password = mysqli_real_escape_string($dbc, trim($_POST['login_password']));
if(!empty($user_login) && !empty($user_password))
{
//look up the input data and confirm it exists in database
$query = "SELECT id, alias FROM gig_user WHERE alias = '$user_login' AND password = SHA('$user_password')";
$data = mysqli_query($dbc, $query)
or die(mysqli_error());
if(mysqli_num_rows($data) == 1)
{
//login is confirmed set the sessions
$row = mysqli_fetch_array($data);
$_SESSION['id'] = $row['id'];
$_SESSION['alias'] = $row['alias'];
//redirect to profile page
$profile_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/profile.php';
header('Location: ' . $profile_url);
}
else
{
//login was not found set an error msg
$err_msg = 'Sorry, you must enter a valid username and password to log in.';
echo $err_msg;
}
}
}
}
?>
<form method = "post" action = "php_scripts/login.php">
<fieldset>
<label>Login</label>
<input type = "text" id = "login" name = "login" /><br />
<label>Password</label>
<input type = "password" id = "login_password" name = "login_password" /><br />
<input type = "submit" name = "login_submit" id = "login_submit" />
</fieldset>
</form>
<?php
require_once('../php_scripts/appvar.php');
//if the user isn't logged, try to log in
if(!isset($_SESSION['id']))
{
if(isset($_POST['login_submit']))
{
//connect to database
$dbc = mysqli_connect($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_NAME)
or die(mysqli_error());
//grab the user input data
$user_login = mysqli_real_escape_string($dbc, trim($_POST['login']));
$user_password = mysqli_real_escape_string($dbc, trim($_POST['login_password']));
if(!empty($user_login) && !empty($user_password))
{
//look up the input data and confirm it exists in database
$query = "SELECT id, alias FROM gig_user WHERE alias = '$user_login' AND password = SHA('$user_password')";
$data = mysqli_query($dbc, $query)
or die(mysqli_error());
if(mysqli_num_rows($data) == 1)
{
//login is confirmed set the sessions
$row = mysqli_fetch_array($data);
$_SESSION['id'] = $row['id'];
$_SESSION['alias'] = $row['alias'];
//redirect to profile page
$profile_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/profile.php';
header('Location: ' . $profile_url);
}
else
{
//login was not found set an error msg
$err_msg = 'Sorry, you must enter a valid username and password to log in.';
echo $err_msg;
}
}
}
}
?>
<form method = "post" action = "php_scripts/login.php">
<fieldset>
<label>Login</label>
<input type = "text" id = "login" name = "login" /><br />
<label>Password</label>
<input type = "password" id = "login_password" name = "login_password" /><br />
<input type = "submit" name = "login_submit" id = "login_submit" />
</fieldset>
</form>