GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Jul-2004, 18:21
cmarti cmarti is offline
New Member
 
Join Date: Jul 2004
Posts: 5
cmarti is on a distinguished road

PHP/MySQL coding issue


Hello everyone! I could really use some help with a MySQL/PHP coding issue. I working on a grade book for a friend at a local elementary school. I'm stuck. Please Help!

I have an html login form:
<form action="StuGetIn.php" method="POST">
Student ID:
<input type="text" name="StuUserID" size="14">
Password:
<input type="password" name="StudPassword" size="14">
<input type="image" src="../Images/Go.gif"></form>

The values entered in the text boxes are sent to the StuGetIn.php page as follows:
PHP Code:

<?
// connect to the database
$conn = mysql_connect("localhost","databaseUsername","databasePassword");
$db = mysql_select_db("databaseName");

// declare values from form
$username = $_POST["StuUserID"];
$password = $_POST["StudPassword"];
// connect to User_Info table to see if the login is correct
$result = MYSQL_QUERY("SELECT * from User_Info WHERE StuID='$username'and Password='$password'")
   or die ("Name and password not found or not matched");

$worked = mysql_fetch_array($result);

$username = $worked[StuID];
$password = $worked[Password];
$fname = $worked[FirstName];
$lname = $worked[LastName];
$cname = $worked[ClassName];
$glevel = $worked[GradeLevel];
$assign = $worked[Assignment];
$grade = $worked[Grade];
$comments = $worked[Comments];
$dposted = $worked[DatePosted];

if($worked) {
   include "header.php";
   echo "<br><center>Welcome $fname!</center><br><div align=center>
  <center>
  <table border=1 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 id=AutoNumber1>
    <tr>
      <td>Class Name</td>
      <td>Assignment</td>
      <td>Grade</td>
      <td>Date Posted</td>
      <td>Comments</td>
    </tr>
    <tr>
      <td>$cname</td>
      <td>$assign</td>
      <td>$grade</td>
      <td>$dposted</td>
      <td>$comments</td>
    </tr>
  </table>
  </center>
</div><br>"; 
   include "footer.php";
} else {
  include "header.php";
  echo "<br><br><b><center>Sorry, Name and password not found or not matched</center></b><br><br>";
  include "footer.php";
}
?>

The problem is that I have two tables which need to be joined but are not joined yet because I don't know how to test the username and pasword entered in the login form from the User_Info table and display the values from the other table. At the same time I have to check the login info from one and get the value from the other.
User_Info table: StuId, TeachID, Password, GradeLevel
GradeBook table: FirstName, LastName, ClassName, Grade, Comment, DatePosted

Please help me join these tables!!!!!!!!!!!! Thank you fellow PHP/MySQL fans.
  #2  
Old 25-Jul-2004, 22:04
cmarti cmarti is offline
New Member
 
Join Date: Jul 2004
Posts: 5
cmarti is on a distinguished road

problem solved


problem solved
  #3  
Old 26-Jul-2004, 04:59
jlee jlee is offline
New Member
 
Join Date: Jul 2004
Posts: 9
jlee is on a distinguished road
Hi

Any chance you could post the answer to your problem - it would be useful for something I am doing also - thanks
  #4  
Old 26-Jul-2004, 08:01
cmarti cmarti is offline
New Member
 
Join Date: Jul 2004
Posts: 5
cmarti is on a distinguished road

reply to jlee


jlee,
Keeping in mind that my code is not the cleanest, I fixed the problem by doing the following:

PHP Code:

<?
$conn = mysql_connect("localhost","databaseUsername","databasePassword");
$db = mysql_select_db("databaseName");

$username = $_POST["StuUserID"];
$password = $_POST["StudPassword"];

$result = MYSQL_QUERY("select * from User_Info, GradeBook where User_Info.stuID=GradeBook.stuID AND User_Info.StuID='$username'and User_Info.Password='$password' ORDER BY DatePosted DESC, ClassName DESC") 
or die ("Name and password not found or not matched"); 

include "header.php"; 
echo " 
<div align=center>
  <center>
  <table border=1 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 id=AutoNumber1 width=80%>
    <tr>
      <td width=20% align=center><b>Class Name</b></td>
      <td width=20% align=center><b>Assignment</b></td>
      <td width=20% align=center><b>Grade</b></td>
      <td width=20% align=center><b>Date Posted</b></td>
      <td width=20% align=center><b>Comments</b></td>
    </tr>
  </table>
  </center>
</div>
"; 

$found = false; 
//use while 
while($worked = mysql_fetch_array($result)) 
{ 
$found = true; 
$username = $worked[StuID]; 
$password = $worked[Password]; 
$fname = $worked[FirstName]; 
$lname = $worked[LastName]; 
$cname = $worked[ClassName]; 
$glevel = $worked[GradeLevel]; 
$assign = $worked[Assignment]; 
$grade = $worked[Grade]; 
$comments = $worked[Comments]; 
$dposted = $worked[DatePosted]; 

echo " 
<div align=center>
  <center>
  <table border=1 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 id=AutoNumber1 width=80%>
    <tr>
      <td width=20% align=center>$cname</td>
      <td width=20% align=center>$assign</td>
      <td width=20% align=center>$grade</td>
      <td width=20% align=center>$dposted</td>
      <td width=20% align=center>$comments</td>
    </tr>
  </table>
  </center>
</div>
"; 

}
echo "<br>"; 
if (!$found) echo "<b><center>Sorry, Name and password not found or not matched</center></b><br>"; 
include "footer.php";   
?>

 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pls help in this coding. harsha CPP / C++ Forum 5 08-Apr-2004 20:48
PHP/Apache memory usage issue bacchus Apache Web Server Forum 0 18-Aug-2003 12:57
PHP/mySQL backend configuration help needed jrobbio Web Design Forum 2 17-Apr-2003 10:07
Tripod UK offering PHP/MySQL! roly Free Web Hosting 15 04-May-2002 03:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:35.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.