homepage Welcome to WebmasterWorld Guest from 54.161.192.61
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Unknown column 'username' in 'where clause'
ak282



 
Msg#: 4316800 posted 10:28 am on May 24, 2011 (gmt 0)

getting following error.
coding for index file is as under.
<?php

//Import functions
include("lib/datacon.php");
include("lib/common.php");
$db = new Database();

//Identify the operation
$op=$_REQUEST["op"];


//Process Login
if ($op=="loginme"){

//Send Query
$username=mysql_real_escape_string($_REQUEST["username"]);
$password=mysql_real_escape_string($_REQUEST["password"]);

$resArr = $db->query("SELECT * FROM admin WHERE username='".$username."' AND password='".$password."'");

//Check if Login information was correct
$rowcount=0;
$admintype="";
foreach($resArr as $user) {
$admintype=$user["type"];
$rowcount++;
}
if ($rowcount >0){
//If correct information then create session and redirect to admin-index
session_start();
$_SESSION["username"]=mysql_real_escape_string($_REQUEST["username"]);
$_SESSION["password"]=mysql_real_escape_string($_REQUEST["password"]);

if ($admintype=="2"){
Header("Location:district_index.php");
}else if($admintype=="1"){
Header("Location:super_index.php");
}

 

ak282



 
Msg#: 4316800 posted 10:29 am on May 24, 2011 (gmt 0)

it shows Unknown column 'username' in 'where clause'

agent_x



 
Msg#: 4316800 posted 11:00 am on May 24, 2011 (gmt 0)

"username" might be a reserved word in MySQL so you might have to put backticks around it.

$resArr = $db->query("SELECT * FROM admin WHERE `username`='".$username."' AND password='".$password."'");

Top left hand corner on a UK keyboard.

The same might apply to "password".

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4316800 posted 1:51 pm on May 24, 2011 (gmt 0)

Unknown column means you are using/referring to a column name that does not exist in the table.

ak282



 
Msg#: 4316800 posted 2:11 pm on May 24, 2011 (gmt 0)

dear i have put backticks but its still not working and i have admin table where username exists.two days ago it was working fine but I made some changes in another table of database and when i logout and try to login agian it was showing this message.

agent_x



 
Msg#: 4316800 posted 2:41 pm on May 24, 2011 (gmt 0)

Then there's nothing wrong with the query, there must be something wrong with your table.

ak282



 
Msg#: 4316800 posted 7:43 am on May 25, 2011 (gmt 0)

dear I havce made another table with the name administrator and in field i place user and pass instead of username and password and in query i write
$resArr = $db->query("SELECT * FROM administrator WHERE username='".$_SESSION["username"]."' AND password='".$_SESSION["password"]."'");
but still not working

agent_x



 
Msg#: 4316800 posted 1:20 pm on May 25, 2011 (gmt 0)

If that was the exact query you used for the new table with the column names you describe then it should be obvious why it doesn't work!

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4316800 posted 5:42 pm on May 25, 2011 (gmt 0)

Go into your phpMyAdmin and check your tables or, if you're on command line mySQL, execute

describe administrator;

I am guessing the field is actually named Username or `User Name`, not username.

ak282



 
Msg#: 4316800 posted 5:05 am on May 26, 2011 (gmt 0)

thanks brother agent-X and rocknbil. actually there was something wrong in query.I have solved it now.dear now i need your help in another task.I have table of student having of class and student name.Now if i select class 2 from drop down box in form it should show the student name of class 2(suppose 15 students) in 15 option boxes so that I should upgrade the record of those students.

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4316800 posted 4:39 pm on May 26, 2011 (gmt 0)

if i select class 2 from drop down box in form it should show the student name of class 2


$where = null;
if ($_POST['select-class'])) { //EX. ONLY, CLEANSE!
$where = " classname='".$_POST['select-class']."'";
}

$select = "select * from table";
if ($where) { $select .= " where $where"; }

in 15 option boxes so that I should upgrade the record of those students.



$records = null;
while ($row = mysql_fetch_array($result)) {
$update_id='update_' . $row['id']; // record id
$records .= "
<tr>
<td><input type="checkbox" name=\"$update_id\" id=\"$update_id\" value=\"$update_id\"> (" . $row['id'] . ")</td>
<td>" . $row['fname'] . ' ' . $row['lname'] . "</td>
</tr>
";
}
//
if ($records) {
echo "
<form method=\"post\" action=\"update.php\">
<table>
$records
<tr><td colspan=\"2\"><input type=\"submit\" value=\"update\"></td></tr>
</table>
";
}
else { echo "<p>No records to update.</p>"; }


Then in update.php,


foreach ($_POST as $key=>$value) {
if (preg_match('/^update\_\d+$/) and is_numeric($value)) {
// update $value, record id, here
// update table set field='blah' where id=$value;
}
}

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4316800 posted 5:27 pm on May 27, 2011 (gmt 0)

oops, some typos there . . .

if (isset($_POST['select-class'])) {

and

preg_match('/^update\_\d+$/,$key)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved