kitschkath 0 Newbie Poster

Hello can anybody help me with constructing a PHP ODBC code for retrieving records in a database?

here's my code:

<html>
<head>
<title>HCPSMSHS: Grade Viewing System</title>
<link rel="stylesheet" href="css.css" type="text/css" charset="UTF-8" media="all">

</head>
<BODY>
<?php

$conn=odbc_connect('DB2','','')
or die("connect error: ".odbc_error());

$username=trim(stripslashes($_POST['username']));
$password=trim(stripslashes($_POST['password']));

$sql="SELECT * FROM tblstudents WHERE S_ID='$username' AND S_PASSWORD1='$password'";


$result=odbc_exec($conn,$sql)
or die ("result error ".odbc_error().'-'.odbc_errormsg());

// if no result: no rows read
if (!odbc_fetch_row($result))
{
echo "<script>alert(\"ERROR! Try again.\");</script>";
print "<script>";
print " self.location='login.html';";
print "</script>"; 
}

// else: all is okay
else {

$_SESSION['username']=$username;
$_SESSION['password']=$password;

$name=odbc_result($result,"S_FNAME");

echo "<script>alert(\"Welcome $name!!\")</script>";

$query_subject="Select Subject from tbltablestudent where S_ID='$username'";
$result_subject=odbc_exec($conn,$query_subject)
or die ("result error ".odbc_error().'-'.odbc_errormsg());

$yeah=odbc_fetch_array($result_subject);

$query_grade="Select Total from $yeah[Subject],tbltablestudent where $yeah[Subject].S_ID=tbltablestudent.S_ID and $yeah[Subject].S_ID='$username'";
$result_grade=odbc_exec($conn,$query_grade)
or die ("result error ".odbc_error().'-'.odbc_errormsg());

$yeah2=odbc_fetch_array($result_grade);

$date=getdate();

}
odbc_close($conn);
?>

<center><div id="content"></div></center>
<center><div id="subcontent">

<?php
echo "$yeah[Subject]";
echo "$yeah2[Total]";
?>
</div></center>
</body>
</html>

the code only retrieves one record. HELP. I've tried a lot of codings but it still won't work~

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.