Unknown table 'students' in field list error...?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sn202
Forum Commoner
Posts: 36
Joined: Thu Dec 16, 2004 7:30 pm

Unknown table 'students' in field list error...?

Post by sn202 »

Using the following code to show transactions taken place by a student along with the balance of their account. But i'm getting a "Unknown table 'students' in field list" error.??

Code: Select all

<?php
		$username = $_POST['username'];
		$self =		$_SERVER['PHP_SELF'];
		$refer =	$_SERVER['HTTP_REFERER'];
error_reporting(E_ALL);			
#connect to MYSQL
$conn = @mysql_connect( "linuxproj", "sn202", "e1420518" )
				or die( "could not connect" );
#select the specified database
$rs = @mysql_select_db ( "db_sn202", $conn )
			or die( "could not select database" );
#create the sql query
$sql="select balance from students where name="$username"";
#exercute the query
$rs = mysql_query( $sql, $conn )
	  or die( mysql_error() );

while( $row  = mysql_fetch_array( $rs ) )
{
	echo( "Balance: " . $row["balance"] ) ;
}
#create the sql query 
$sql="SELECT transaction.*, students.studentid FROM transaction
JOIN users
ON transaction.studentid=students.studentid
WHERE students.studentid="$username"";
#exercute the query 
$rs2 = mysql_query( $sql, $conn )
	  or die( mysql_error() );

while( $row2 = mysql_fetch_array( $rs2 ) ) 

{
	echo( "Transaction ID: " . $row2["transactionid"] );
	echo( "studentid: " . $row2["studentid"] );
	echo( "Product id: " . $row2["productid"] );
	echo( "type of transaction " . $row2["type"] );
	echo( "value " . $row2["value"]. "<br>");
}

{ $msq = "Welcome $username to your account summary"; }
?>
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

And you have a table in the database called students? Spelt in the same way?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

you're trying to use students table without mentioning it in FROM clause in the second query:

Code: Select all

$sql="SELECT transaction.*, students.studentid FROM transaction
JOIN users
ON transaction.studentid=students.studentid
WHERE students.studentid="$username"";
perhaps it should be:

Code: Select all

$sql="SELECT transaction.*, students.studentid FROM transaction
JOIN students
ON transaction.studentid=students.studentid
WHERE students.studentid="$username"";
Post Reply