Jump to content

Recommended Posts

Why do i get a blank page now i have tried to print some data from the database to a table?! I cant see for the life of me what ive missed!

 

// query 

$q ="SELECT Loan.BorId, Borrower.BorName, Loan.BcId, BookTitle.BtName, Loan.DateOut, Loan.DateDue, Loan.DateBack

FROM Borrower, BookTitle, Loan, BookCopy

WHERE Borrower.BorId = Loan.BorId 

AND BookTitle.BtId = BookCopy.BtId

AND BookCopy.BcId = Loan.BcId

AND Loan.DateBack > Loan.DateDue

ORDER BY Borrower.BorName ASC"; 



$res1 = mysql_query($q) or die (mysql_error());

echo mysql_num_rows($res1);

if ($res1) { //If it ran OK, display the records.


while($row = mysql_fetch_array($res1)) {

echo "<table border='1' cellpadding=10>  

     <tr>

      <td class='table'>

         <center><b>

         Borrower ID

       </b></center>

       </td>

      <td class='table'>

        <center><b>

           Borrower Name

       </b></center>

      </td>

      <td class='table'>

        <center><b>

          Book Copy ID

        </b> </center>  

      </td>

      <td class='table'>

        <center><b>

         Book Title 

        </b></center> 

      </td> 

      <td class='table'>

        <center><b>

         Publisher ID

       </b></center>

      </td>

      <td class='table'>

        <center><b>

         Date Out 

       </b></center>

      </td>

      <td class='table'>

         <center><b>

         Date Due

       </b></center>

      </td>
  <td class='table'>

        <center><b>

         Date Back

       </b></center>

      </td>

     </tr>

     <tr>

      <td class='table'>

        <center>

           ".$row['BorId']." 

        </center>

      </td>

      <td class='table'>

        <center>

          ".$row['BorName']." 

        </center>

       </td>

      <td class='table'>

        <center>

         ".$row['BcId']."

        </center> 

      </td>

      <td class='table'>

        <center>

         ".$row['BtName']."

        </center> 

      </td>

      <td class='table'>

        <center>

          ".$row['PubId']."

        </center>

      </td>

      <td class='table'>

        <center>

          ".$row['DateOut']."

        </center>

      </td>

      <td class='table'>

        <center>

          ".$row['DateDue']." 

       </center>

      </td>

  <td class='table'>

        <center>

          ".$row['DateBack']."

        </center>

      </td>
    </tr> 

</table>";

 

I feel so stupid many thanks to who ever spots what ive done wrong!

Link to comment
https://forums.phpfreaks.com/topic/147958-solved-data-output/
Share on other sites

No, should i post the entire code, i only posted what i thought would be relivent. Here it is incase its helpful!

 

<?php

session_start();

if(!session_is_registered(myusername)){

header("location:index_Staff.php");

}

?>

<html>

<head>

<title> 

Children's online library -Late Book Return Results 

</title>

</head>

<body>

<h5 align="left"><?print 'You are Logged in as:';?>

   <?print $_SESSION['myusername'];?></h5>

<h1 align=center > Children's Online Library</h1>

<p align = center>

<h1 align =center>Borrower Access To Children's Online Library</h1> 

<table align=center cellpadding="10" border="1"> 

<tr> 

<th> 

<a href="index_Borrower.php"> Homepage</a>

</th>

<th>

<a href="SearchForABook.php">Search For A Book</a>

</th>

<th>

<a href="BorrowABook.php">Borrow A Book</a>

</th> 

<th>

<a href="ReturnABook.php">Return A Book</a>

</th>

<th>

<a href="RenewABook.php">Renew A Book</a>

</th>

<th>

<a href="logout.php">Logout</a>

</th>

</tr>

</table>

</p>

<br>

</br>



<h2 align=center> Late Book Return Results</h2>



<?php #view all late book returns

//connect to the database

   //database information

     $host      = "stocks"; // Host name

     $username  = "njpeddle"; // Mysql username

     $password  = "mysql5"; // Mysql password

     $db_name   = "njpeddle"; // Database name



 mysql_connect("$host", "$username", "$password")or die("cannot connect");

     mysql_select_db("$db_name")or die("cannot select DB"); 



echo '<h1> All Late Book Returns To Current Date</h1>';



// query 

$q ="SELECT Loan.BorId, Borrower.BorName, Loan.BcId, BookTitle.BtName, Loan.DateOut, Loan.DateDue, Loan.DateBack

FROM Borrower, BookTitle, Loan, BookCopy

WHERE Borrower.BorId = Loan.BorId 

AND BookTitle.BtId = BookCopy.BtId

AND BookCopy.BcId = Loan.BcId

AND Loan.DateBack > Loan.DateDue

ORDER BY Borrower.BorName ASC"; 



$res1 = mysql_query($q) or die (mysql_error());

echo mysql_num_rows($res1);

if ($res1) { //If it ran OK, display the records.


while($row = mysql_fetch_array($res1)) {

echo "<table border='1' cellpadding=10>  

     <tr>

      <td class='table'>

         <center><b>

         Borrower ID

       </b></center>

       </td>

      <td class='table'>

        <center><b>

           Borrower Name

       </b></center>

      </td>

      <td class='table'>

        <center><b>

          Book Copy ID

        </b> </center>  

      </td>

      <td class='table'>

        <center><b>

         Book Title 

        </b></center> 

      </td> 

      <td class='table'>

        <center><b>

         Publisher ID

       </b></center>

      </td>

      <td class='table'>

        <center><b>

         Date Out 

       </b></center>

      </td>

      <td class='table'>

         <center><b>

         Date Due

       </b></center>

      </td>
  <td class='table'>

        <center><b>

         Date Back

       </b></center>

      </td>

     </tr>

     <tr>

      <td class='table'>

        <center>

           ".$row['BorId']." 

        </center>

      </td>

      <td class='table'>

        <center>

          ".$row['BorName']." 

        </center>

       </td>

      <td class='table'>

        <center>

         ".$row['BcId']."

        </center> 

      </td>

      <td class='table'>

        <center>

         ".$row['BtName']."

        </center> 

      </td>

      <td class='table'>

        <center>

          ".$row['PubId']."

        </center>

      </td>

      <td class='table'>

        <center>

          ".$row['DateOut']."

        </center>

      </td>

      <td class='table'>

        <center>

          ".$row['DateDue']." 

       </center>

      </td>

  <td class='table'>

        <center>

          ".$row['DateBack']."

        </center>

      </td>
    </tr> 

</table>";


//echo mysql_result($res1, 5); 









//mysql_free_result ($res1); //Free up the resources.



} else { // If it did not run OK.



//Public message:



echo '<p> Unfortunately we could not retrieve the results. We apologise for any inconvience.</p>';



// Debugging message: 



echo '<p>' . mysqli_error($db_name) . '<br 

/><br />Querey: ' .$q. '</p>';



} //End of it ($res1) IF. 



//mysqli_close($db_name); // Close the database connection. 



?>

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/147958-solved-data-output/#findComment-776577
Share on other sites

Why are using mysqli_error here

/ Debugging message: 



echo '<p>' . mysqli_error($db_name) . '<br 

/><br />Querey: ' .$q. '</p>';



} //End of it ($res1) IF. 

 

when in the rest of your code you're using the standard mysql library functions? mysqli_* and mysql_* functions are not cross compatible.

 

You should also realise session_is_registered or session_register are depreciated and should only be used if register_globals is enabled. You should change

if(!session_is_registered(myusername)){

header("location:index_Staff.php");

}

 

to

if(!isset($_SESSION['myusername'])){

header("location:index_Staff.php");

}

 

Link to comment
https://forums.phpfreaks.com/topic/147958-solved-data-output/#findComment-776583
Share on other sites

For starters:

 

if(!session_is_registered(myusername)){

 

has been deprecated as of 5.3 so you have to use:

 

if(!isset($_SESSION['myusername'])){

 

Put this at the top of your page as your first PHP statements and see if there are any errors.

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Link to comment
https://forums.phpfreaks.com/topic/147958-solved-data-output/#findComment-776587
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.