Forum Moderators: coopster
<?php $username = $_POST['username'];
$self =$_SERVER['PHP_SELF'];
$refer =$_SERVER['HTTP_REFERER'];
#connect to MYSQL
$conn = @mysql_connect( "linuxproj", "userid", "password" )
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"; }
?>
[edited by: coopster at 1:06 pm (utc) on Dec. 17, 2004]
[edit reason] generalized connection info [/edit]
Also, when doing a nested query like this, I think you'll want to use a second set of variable names, like $rs2, $row2... or you'll be overwriting values that the outside loop still depends on.
When you want to make a script die on a failed mysql function call, take advantage of mysql_error(), like this:
...or die("could not exercute query: ".mysql_error());
...that will tell you why if failed
I hope this helps.
code:
<?php $username = $_POST['username'];
$self =$_SERVER['PHP_SELF'];
$refer =$_SERVER['HTTP_REFERER'];
#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 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 transaction.*, students.studentno FROM transaction
JOIN users
ON transaction.studentno=students.studentno
WHERE students.studentno=\"$username\"";
#exercute the query
$rs2 = mysql_query( $sql, $conn )
or die( mysql_error() );
while( $row2 = mysql_fetch_array( $rs ) )
{
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"; }
?>
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"; }
?>
Can u see wots wrong with it? i'm getting error: "Unknown table 'students' in field list"