Welcome to WebmasterWorld Guest from 54.161.110.186

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Unknown column 'username' in 'where clause'

     
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");
}
10:29 am on May 24, 2011 (gmt 0)



it shows Unknown column 'username' in 'where clause'
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".
1:51 pm on May 24, 2011 (gmt 0)

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



Unknown column means you are using/referring to a column name that does not exist in the table.
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.
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.
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
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!
5:42 pm on May 25, 2011 (gmt 0)

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



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.
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.
4:39 pm on May 26, 2011 (gmt 0)

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



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;
}
}
5:27 pm on May 27, 2011 (gmt 0)

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



oops, some typos there . . .

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

and

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

Featured Threads

Hot Threads This Week

Hot Threads This Month