Page 1 of 1

for loop just work once

Posted: Thu Mar 10, 2011 4:34 pm
by mani123
I have a page named as report

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body  bgcolor="#cfad5f"text="#1f180a">
<p>
  <?php 

session_start(); 
$d= $_SESSION['txt_id'];
include ('dbinfo.inc');
echo mysql_error();

$result=mysql_query("SELECT * FROM `request` WHERE `emp_id` LIKE '$d'");
mysql_error();


echo " <h1><strong><center>Request/s</center></strong></h1>";

       ///****************** Print out lthe contents of each row into a table *************************///

echo "<body bgcolor='#cfad5f'><table width='90%' border='1' align='center' cellpadding='5' cellspacing='1' bgcolor='' class='text_brown' >";

echo " <font color='#663300' size='5' face='times new roman'>";
echo "                 <tr align='center' >";
echo "                 <td ><h3 font color='#663300' >Request no</h3></td>";
echo "                 <td><h3>Item name</h3></td>";
echo "                 <td><h3>Request for Department</h3></td>";
echo "                 <td><h3>Quantity</h3></td>";
echo "                 <td><h3>Request Date</h3></td>";
echo "                 <td><h3>Status</h3></td>";


$field = mysql_fetch_field($result);
$fields_num = mysql_num_fields($result);
            for($i=0; $i<$fields_num; $i++){
		   if(mysql_num_rows($result)){
              while($val=mysql_fetch_row($result))
                {   

                echo       "<tr class=\"black\">";
                echo       " <td align='center' width='15%'>".$val[0]."</td>                ";
                echo       " <td align='center' width='20%'>".$val[4]."</td>                ";
                echo       " <td  align='center' width='25%'>".$val[2]."</td>                ";
				echo       " <td  align='center' width='25%'>".$val[6]."</td>                ";
				echo       " <td  align='center' width='20%'>".$val[8]."</td>                ";
                echo       " <td  align='center' width='20%'>".$val[10]."</td>                ";
				
								echo "</tr>";
                 }         
echo"</table>"; }}

?>
<p>
<p align="center">
<p align="center">
<p align="center">
<p align="center">
<form action="report_logic.php" method="post">
<table align = "center" style="text-align:Left" width = "500" frame = "box" bordercolor="black" >
       <tr>
       <td width="252" font size="3"><font color="#532900" size="5">Request # </font></td>
       <td width="252"><div align="center"><input name="txt_reqno" type="text" size="10" /></div></td>
       </tr>
       
       <tr>
       <td font size="3"><font color="#532900" size="5">Status</font></td>
       <td><div align="center">
         <label>
         <select name="menu_status" id="menu_status">
         
           <option>Basic</option>
           <option>Approved</option>
           <option>Accepted</option>
           <option>Rejected</option>
          </select>
         </label>
       </div></td>
       </tr>
       <tr>
       <td font size="3"><font color="#532900" size="5">Note</font></td>
       <td><div align="center"><font color="#532900" size="5">
         <textarea name="txt_note" cols="40" id="txt_note"></textarea>
       </font></div></td>
     </tr>
  </table>
     <p>&nbsp;</p>
     <label></label>
     <div align="center">
       <input type="submit" name="des" id="des" value="Submit">
       <input name="Reset" type="reset" value="Reset">
     </div>
</form>


  
</body>
</html>
the report_logic works as

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body  bgcolor="#cfad5f"text="#1f180a">
  <?php 

session_start(); 
$d= $_SESSION['txt_id'];
include ('dbinfo.inc');
echo mysql_error();

$reqno==mysql_real_escape_string($_POST['txt_reqno']);
$status=mysql_real_escape_string($_POST['menu_status']);
$not=mysql_real_escape_string($_POST['txt_note']);

mysql_query("INSERT INTO report(rep_for_req,status,note) Values ('$reqno',$not','$status')");
 $_SESSION['txt_id'] = $_POST['txt_id'];		
   
        header('Location:sucrep.php');

?>
</body>
</html>
and finally the sucrep is:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body  bgcolor="#cfad5f"text="#1f180a">
<form action="report.php" method="post">
<h3>Your report has successfully submitted</h3>
 <input type="submit" name="des" id="des" value="Back">
 </form>

</body>
</html>
now the problem is when I open report.php
the data from db is displayed but when I go to any other page and return back to report.php no data is shown.
can any one help
Please