0

**Look at the picture **

enter image description here

I want to see the page without 'Notice:' because here all the result I think works finely. But why does it shows. Any Mistake? Please help me.

The code is like:

<?php
    mysql_connect("localhost","root");
    mysql_select_db("simple");
    $id=$_POST['id'];
    $res=mysql_query("SELECT * FROM simple_tb WHERE id=$id");
    while($row=mysql_fetch_array($res))
    {
?>
    <link rel="stylesheet" type="text/css" href="demo.css" media="screen" /></head>
    <h1 align="center"> ABC IDEAL SCHOOL AND COLLEGE</h1>
    <h3 align="center">Baraiyahat, Chittagong, 01772969874 </h3>
    <p align="center">Students Tuetion Fee Payment Sheet<br></p>
    <table class="table" align="center"width="800"  bgcolor="skyblue">
        <tr><td width="25%">ID No:</td><td width="25%"><?php echo $row['id'];?></td></tr>
        <tr><td>Name:</td> <td><?php echo $row['n'];?></td></tr>
        <tr><td>Class:</td><td><?php echo $row['c'];?></td></tr>
        <tr><td>Roll:</td> <td><?php echo $row['r'];?></td></td></tr>
    </table>
    <br>
    <h4 ALIGN="CENTER">PAYMENT STATUS</H4>
        <table align="center"width="800" BORDER="1" bgcolor="red">
            <tr>
                <td align="center"><B>DATES</B></td>
                <td align="center"><B>DESCRIPTION</B></td>
                <td align="center"><B>MEMO NO</B></td>
                <td align="center"><B>BDT</B></td>
                <td align="center"><B>Con.Total</B></td>
            </tr>
<?php

        $res2=mysql_query("SELECT * FROM ac WHERE sid=".$row['id']);
        while($row2=mysql_fetch_array($res2))
        {   $sum+= $row2['t'];
        ?>

            <tr bgcolor="cream">
                <td bgcolor="white"align="center"><?php echo $row2['d'];?></td>
                <td bgcolor="white"align="center"><?php echo $row2['des'];?></td>
                <td bgcolor="white"align="center"><?php echo $row2['m'];?></td> 
                <td bgcolor="white"align="center"><?php echo $row2['t'];?></td>
                <td bgcolor="white"align="center"><?php echo $sum."<br>";?></td>
                 <td bgcolor="white"align="center"></td>
            </tr>

<?php
        }
        ?></table><?php
    }

Now please tell me details what can I do for the written code.

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
Shyful74
  • 29
  • 7
  • This question is off-topic for StackOverflow. Please, use correct website from SE network: https://codereview.stackexchange.com/ – polkovnikov.ph May 12 '17 at 10:25
  • 2
    Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Masivuye Cokile May 12 '17 at 10:25

2 Answers2

1

You need to assign value of sum to 0 before while loop

<?php
        $sum = 0;
        $res2=mysql_query("SELECT * FROM ac WHERE sid=".$row['id']);
        while($row2=mysql_fetch_array($res2))
        {   $sum+= $row2['t'];
        ?>
B. Desai
  • 16,414
  • 5
  • 26
  • 47
0

Try this one. You have used somewhere mysql and some where mysqli. That is one problem.

 <?php
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"simple");
$id=$_POST['id'];
$res=mysqli_query($con,"SELECT * FROM simple_tb WHERE id=$id");
while($row=mysqli_fetch_array($res))
{
?>
<link rel="stylesheet" type="text/css" href="demo.css" media="screen" />
</head>
<h1 align="center"> ABC IDEAL SCHOOL AND COLLEGE</h1>
<h3 align="center">Baraiyahat, Chittagong, 01772969874 </h3>
<p align="center">Students Tuetion Fee Payment Sheet<br></p>
<table class="table" align="center"width="800"  bgcolor="skyblue">
    <tr><td width="25%">ID No:</td><td width="25%"><?php echo $row['id'];?>
</td></tr>
    <tr><td>Name:</td> <td><?php echo $row['n'];?></td></tr>
    <tr><td>Class:</td><td><?php echo $row['c'];?></td></tr>
    <tr><td>Roll:</td> <td><?php echo $row['r'];?></td></td></tr>
</table>
<br>
<h4 ALIGN="CENTER">PAYMENT STATUS</H4>
    <table align="center"width="800" BORDER="1" bgcolor="red">
        <tr>
            <td align="center"><B>DATES</B></td>
            <td align="center"><B>DESCRIPTION</B></td>
            <td align="center"><B>MEMO NO</B></td>
            <td align="center"><B>BDT</B></td>
            <td align="center"><B>Con.Total</B></td>
        </tr>
     <?php

    $res2=mysqli_query($con,"SELECT * FROM ac WHERE sid=".$row['id']);
    while($row2=mysqli_fetch_array($res2))
    {   $sum+= $row2['t'];
    ?>

        <tr bgcolor="cream">
            <td bgcolor="white"align="center"><?php echo $row2['d'];?></td>
            <td bgcolor="white"align="center"><?php echo $row2['des'];?>
</td>
            <td bgcolor="white"align="center"><?php echo $row2['m'];?></td> 
            <td bgcolor="white"align="center"><?php echo $row2['t'];?></td>
            <td bgcolor="white"align="center"><?php echo $sum."<br>";?></td>
             <td bgcolor="white"align="center"></td>
        </tr>

<?php
    }
    ?></table><?php
  ``}
Sushank Pokharel
  • 869
  • 7
  • 15