Current location: Hot Scripts Forums » Programming Languages » PHP » Login Error


Login Error

Reply
  #1 (permalink)  
Old 10-26-10, 04:20 PM
SkullShatteringProductions SkullShatteringProductions is offline
New Member
 
Join Date: Oct 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Question Login Error

I tried to Incorporate a log-in feature to my website to make some content more secure but I am running into problems again. I created a new table in my database for Users, Passwords, and access or power level. Whenever i try to log into the page i get this error Unknown column 'Power' in 'field list'. I'm not sure why I am getting this error, any help is greatly appreciated.

Log-in page
PHP Code:

<?php require_once('Connections/Jobs.php'); ?>

<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  
session_start();
}

$loginFormAction $_SERVER['PHP_SELF'];
if (isset(
$_GET['accesscheck'])) {
  
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset(
$_POST['User'])) {
  
$loginUsername=$_POST['User'];
  
$password=$_POST['Password'];
  
$MM_fldUserAuthorization "Power Level";
  
$MM_redirectLoginSuccess "PostJob.php";
  
$MM_redirectLoginFailed "403Error.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_Jobs$Jobs);
      
  
$LoginRS__query=sprintf("SELECT `User`, Password, Power Level FROM users WHERE `User`=%s AND Password=%s",
  
GetSQLValueString($loginUsername"-1"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$Jobs) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
    
    
$loginStrGroup  mysql_result($LoginRS,0,'Power Level');
    
    
//declare two session variables and assign them
    
$_SESSION['MM_Username'] = $loginUsername;
    
$_SESSION['MM_UserGroup'] = $loginStrGroup;          

    if (isset(
$_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>403 Access Denied</title>
<style type="text/css">
<!--
body {
    font: 100% Verdana, Arial, Helvetica, sans-serif;
    background: #666666;
    margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
    padding: 0;
    text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
    color: #000000;
}
.oneColElsCtr #container {
    width: 46em;
    background: #FFFFFF;
    margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
    border: 1px solid #000000;
    text-align: left; /* this overrides the text-align: center on the body element. */
}
.oneColElsCtr #mainContent {
    padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
}
.oneColElsCtr #container #mainContent h1 {
    font-size: 30px;
}
-->
</style></head>

<body class="oneColElsCtr">

<div id="container">
  <div id="mainContent">
<h1 align="center">Error 403: Access Denied</h1>
<h1 align="center">You must be logged in to view this page</h1>
<form ACTION="<?php echo $loginFormAction?>" id="form1" name="form1" method="POST">
  <div align="center"><table width="100%" border="0">
  <tr>
    <th scope="col"><table width="500" border="0">
      <tr>
        <th width="250" scope="col"><div align="right">Username</div></th>
        <th width="250" scope="col"><div align="left">
          <input type="text" name="User" id="User" />
        </div></th>
      </tr>
      <tr>
        <td width="250"><div align="right"><strong>Password</strong></div></td>
        <td width="250"><label>
          <div align="left">
            <input type="password" name="Password" id="Password" />
          </div>
          </label></td>
      </tr>
    </table></th>
  </tr>
  <tr>
    <td><div align="center">
      <label>
        <input type="submit" name="GO" id="GO" value="Login" />
      </label>
    </div></td>
  </tr>
</table>
</div>
</form>
<p align="center">If you are an employer looking to post a job please send an email to <a href=""></a> and request a username and password</p>
<p align="center">Please login or return to the <a href="Index.php">Main Page</a>  </p>
  </div>
</div>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 10-26-10, 05:24 PM
kfurlong's Avatar
kfurlong kfurlong is offline
Wannabe Coder
 
Join Date: Oct 2010
Posts: 150
Thanks: 6
Thanked 20 Times in 20 Posts
Quote:
Originally Posted by SkullShatteringProductions View Post
I tried to Incorporate a log-in feature to my website to make some content more secure but I am running into problems again. I created a new table in my database for Users, Passwords, and access or power level. Whenever i try to log into the page i get this error Unknown column 'Power' in 'field list'. I'm not sure why I am getting this error, any help is greatly appreciated.

Log-in page
PHP Code:

<?php require_once('Connections/Jobs.php'); ?>

<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  
session_start();
}

$loginFormAction $_SERVER['PHP_SELF'];
if (isset(
$_GET['accesscheck'])) {
  
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset(
$_POST['User'])) {
  
$loginUsername=$_POST['User'];
  
$password=$_POST['Password'];
  
$MM_fldUserAuthorization "Power Level";
  
$MM_redirectLoginSuccess "PostJob.php";
  
$MM_redirectLoginFailed "403Error.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_Jobs$Jobs);
      
  
$LoginRS__query=sprintf("SELECT `User`, Password, Power Level FROM users WHERE `User`=%s AND Password=%s",
  
GetSQLValueString($loginUsername"-1"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$Jobs) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
    
    
$loginStrGroup  mysql_result($LoginRS,0,'Power Level');
    
    
//declare two session variables and assign them
    
$_SESSION['MM_Username'] = $loginUsername;
    
$_SESSION['MM_UserGroup'] = $loginStrGroup;          

    if (isset(
$_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>403 Access Denied</title>
<style type="text/css">
<!--
body {
    font: 100% Verdana, Arial, Helvetica, sans-serif;
    background: #666666;
    margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
    padding: 0;
    text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
    color: #000000;
}
.oneColElsCtr #container {
    width: 46em;
    background: #FFFFFF;
    margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
    border: 1px solid #000000;
    text-align: left; /* this overrides the text-align: center on the body element. */
}
.oneColElsCtr #mainContent {
    padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
}
.oneColElsCtr #container #mainContent h1 {
    font-size: 30px;
}
-->
</style></head>

<body class="oneColElsCtr">

<div id="container">
  <div id="mainContent">
<h1 align="center">Error 403: Access Denied</h1>
<h1 align="center">You must be logged in to view this page</h1>
<form ACTION="<?php echo $loginFormAction?>" id="form1" name="form1" method="POST">
  <div align="center"><table width="100%" border="0">
  <tr>
    <th scope="col"><table width="500" border="0">
      <tr>
        <th width="250" scope="col"><div align="right">Username</div></th>
        <th width="250" scope="col"><div align="left">
          <input type="text" name="User" id="User" />
        </div></th>
      </tr>
      <tr>
        <td width="250"><div align="right"><strong>Password</strong></div></td>
        <td width="250"><label>
          <div align="left">
            <input type="password" name="Password" id="Password" />
          </div>
          </label></td>
      </tr>
    </table></th>
  </tr>
  <tr>
    <td><div align="center">
      <label>
        <input type="submit" name="GO" id="GO" value="Login" />
      </label>
    </div></td>
  </tr>
</table>
</div>
</form>
<p align="center">If you are an employer looking to post a job please send an email to <a href=""></a> and request a username and password</p>
<p align="center">Please login or return to the <a href="Index.php">Main Page</a>  </p>
  </div>
</div>
</body>
</html>
When an mysql error says unknown column '....' in field list, that means that that field does not exist in that table..
maybe check the spelling/capitalization/ missing commas (if the field is Power and the next one is Level then you need to add a comma), but in this case it looks like it is looking for the word Power, when it should actually be looking for `Power Level`... if your column name is Power Level with a space. then you should surround it in ticks (`), if that doesnt work, then change the name of the column from Power Level to Power_Level and change it in the code too, but that should fix it.
Reply With Quote
  #3 (permalink)  
Old 10-26-10, 06:05 PM
SkullShatteringProductions SkullShatteringProductions is offline
New Member
 
Join Date: Oct 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Thumbs up Thanks

yep it was looking for the collum Power not Power Level i added ' ' around 'Power Level' and it worked. Thank you!
Reply With Quote
Reply

Bookmarks

Tags
log in, login, mysql, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error. operation error jayhighway Visual Basic 2 10-01-11 06:04 AM
C++ and MSSQL tutorials? scott2500uk C/C++ 8 05-11-09 02:33 AM
[SOLVED] 500 Internal Server Error - Please help Dawn Perl 15 07-08-08 11:08 AM
Syntax Error Nikas Database 4 05-15-08 10:48 AM


All times are GMT -5. The time now is 08:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.