running 2 SQL queries error!... help needed!

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

running 2 SQL queries error!... help needed!

Post by sn202 »

Hi, basically i'm trying to run this script which looks at a mysql database, looking up student records to display the student's balance and transaction history, (script below) problem is i'm getting a parse error when trying to run the second SQL query, which I'm guessing is the problem (running two querys). Any ideas, help will be much appriciated as I don't have long to get this all done (5 hours ish) and my system seems to be falling into an abyss of chaos!!! :)

Simon.

Code: Select all

<?php
	                $username = $_POST['username'];
		$self =	    $_SERVER['PHP_SELF'];
		$refer =	    $_SERVER['HTTP_REFERER'];
			
#connect to MYSQL
$conn = @mysql_connect( "linuxproj", "****", "*****" )
				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 accountbal from students where username="$username"";
#exercute the query
$rs = mysql_query( $sql, $conn )
	  or die( "could not exercute query" );

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

while( $row  = mysql_fetch_array( $rs ) )
{
	echo( "Balance: " . $row["balance"] ) ."<br>");
}

{ $msq = "Welcome $username to your account summary"; }
?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

get yourself a decent php editor.

you are not performing any inpu tvalidation, at least have a mysql_escape_string on $_POST['username']

you are missing a ; on line 23-26

kick in error_reporting(E_ALL)... this always gives a hint where to look in case of errors... also use mysql_Error... gives you another level of error hinting....
Post Reply