i try different method to hide the "hide" div if status result is "E"
i have four status : R ,A , I and E,, if status is E then show the "hide" div other vise hide it,,
you people suggest me something, thanks in advance,,,

code is here :

<?php
 session_start();
?>
<html>
    <head>
        <title>Student Welcome</title>
         <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
     <script language="javascript" type="text/javascript">
                      //   function load(){
                        //$('#hide').css('display','none');
                         //}
                            //var text = $('#show').text();
                            //var comparingText = 'R';
                            //$("#show").html('E')
                    //if(text==comparingText){
                        //$('#hide').css('display','block');

                    //};//else{
                        //  $('#hide').css('display','block');
                        //};
                        //launch code when dom is ready
//$(document).ready(){
  //if a div doesn't have content, then we should remove another div
  //if($('#show').html()!='E'){
    //$('#hide').hide()



     </script>
    </head>
    <body onload="load()"><pre> <?php echo $_SESSION['name'] ?> is login                                                       <a href="logout.php"><input type="button" name="Logout" value="Logout" style="width: 62px"/></a>  <a href="stdresetpass.php"><input type="button" name="resetpassord" value="Reset Password" style="width: 110px"/></a></pre>
        </br>
        </br>
        </br>
        <?php

  $con=mysql_connect("localhost:3307","root","kust");
  if(!$con)
  {
   die("Some problems occured during making connection with mysql".mysql_error());
  }
 ?>
 <?php
  $bd_con= mysql_select_db("kustkht",$con);
  if(!$bd_con)
  {
   die("Some problems occured during selecting DataBase from MySQL".mysql_error());
  }
   $RegNo = $_SESSION['registrationNo'];




   $qry   ="select registrationNo,name,fatherName,cnic,gender,discipline,department,admissionSession,email,password,address,domicile,contactNo,status,currentEmployer,designation,salaryInfo,totalExperience,lastOrganizationname,organizationAdd,organizationPhno,organizationEmail,Remarks from students where registrationNo='$RegNo' ";


  if (!mysql_query($qry,$con))
  {
  die('Error: ' . mysql_error());
  }
    $result= mysql_query($qry);
    $count =mysql_num_rows($result);
    if($count==1)
    {
    ?>

<?php
    while($row = mysql_fetch_array($result)){


    ?>
    <h3 align="center">Your Profile</h3>
    <table border="1" cellspacing="2" cellpadding="2" align="center">
<tr>
<td>Registration#</td>
<td><?php echo $row['registrationNo'] ?></td>
</tr>
<tr>
<td>Student Name </td>
<td><?php echo $row['name'] ?></td>
</tr>
<tr>
<td>Father's Name </td>
<td><?php echo $row['fatherName'] ?></td>
</tr>
<tr>
<td>CNIC#</td>
<td><?php echo $row['cnic'] ?></td>
</tr>
<tr>
<td>Gender</td>
<td><?php echo $row['gender'] ?></td>
</tr>
<tr>
<td>Discipline</td>
<td><?php echo $row['discipline'] ?></td>
</tr>
<tr>
<td>Department </td>
<td><?php echo $row['department'] ?></td>
</tr>
<tr>
<td>Admission Session</td>
<td><?php echo $row['admissionSession'] ?></td>
</tr>
<tr>
<td>Email Address </td>  
<td><?php echo $row['email'] ?></td>
</tr>
<tr>
<td>Address </td>
<td><?php echo $row['address'] ?></td>
</tr>
<tr>
<td>Domicile</td>
<td><?php echo $row['domicile'] ?></td>
</tr>
<tr>
<td>Contact# </td>
<td><?php echo $row['contactNo'] ?></td> 
</tr>
<tr>
<td>Status </td>
<td ><div id="show" ><?php echo $row['status'] ?></div></td>
</tr>
</table>
<div id="hide" >
<table>
<tr colspan="2"> 

<td align=center>Alumanai Record</td>

</tr>
<tr> 
<td>Current Employer</td>
<td><?php echo $row['currentEmployer'] ?></td>
</tr>
<tr>
<td>Designation </td>
<td><?php echo $row['designation'] ?></td>
</tr>
<tr>
<td>Salary Information </td>
<td><?php echo $row['salaryInfo'] ?></td>
</tr>
<tr>
<td>Total Experience </td>
<td><?php echo $row['totalExperience'] ?></td>
</tr>
<tr>
<td>
<td><?php echo $row['lastOrganizationname'] ?></td>
</tr>
<tr>
<td>Organization Address</td>
<td><?php echo $row['organizationAdd'] ?></td>
</tr>
<tr>
<td>Organization Phone#</td>
<td><?php echo $row['organizationPhno'] ?></td>
</tr>
<tr> 
<td>Organization Email</td>
<td><?php echo $row['organizationEmail'] ?></td>
</tr>
<tr>
<td>Remarks About Emplyer</td>
<td><?php echo $row['Remarks'] ?></td>
</tr>

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




   mysql_close($con);
 ?>
    </body>  
</html>

Dani AI

Generated

As pointed out, the simplest, most robust fix is to decide on the server and only output the alumni block when the record's status is the expected value. That avoids fragile client-side checks, keeps the DOM smaller, and prevents showing empty/irrelevant HTML when status is not "E". This also aligns with modern PHP practices. (php.net)

Also, update the database access: the old mysql_* functions are deprecated/removed — switch to either MySQLi or PDO and use parameterized queries (prepared statements) rather than interpolating variables into SQL. That change makes your code compatible with current PHP versions and removes a large class of SQL-injection risk. See the PHP docs for MySQL removal and MySQLi, and the PDO prepared-statement guidance. PHP: MySQL (intro) · PHP: MySQLi · PDO prepared statements. (php.net)

Example workflow (safe pattern): prepare the query with a placeholder for registrationNo, execute with the session value, fetch the row, then render the alumni HTML only when status is exactly "E". This keeps authorization/display logic on the server and uses a prepared statement to protect the DB:

$pdo = new PDO('mysql:host=127.0.0.1;port=3307;dbname=yourdb;charset=utf8mb4', 'dbuser', 'dbpass', [
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);

$stmt = $pdo->prepare('SELECT status, currentEmployer, designation, /* ... */ FROM students WHERE registrationNo = :reg');
$stmt->execute([':reg' => $_SESSION['registrationNo']]);
$row = $stmt->fetch();

if ($row && trim($row['status']) === 'E') {
  // echo alumni block here
}

When debugging mismatches: var_dump the returned status to check whitespace or casing (use trim() and strtoupper()/strtolower() as needed). If a client-side show/hide is still wanted for UX, render the alumni block only when needed or render it hidden by default and reveal it with unobtrusive JS — but keep the authoritative check server-side. For SQL-injection guidance and why prepared statements matter, see the OWASP SQL Injection Prevention Cheat Sheet. OWASP SQLi prevention. (cheatsheetseries.owasp.org)

Credit to for the example and to for the server-side suggestion that fixed the issue in this thread.

Recommended Answers

All 3 Replies

You say the #hide div should be shown only if the status equals E. Are you referring to the status column returned by your query?

If so, could you not use this:

<?php if($row['status'] == 'E'): ?>
    <div id="hide">

        <!-- HTML table here -->

    </div>
<?php endif; ?>

Excellent. Please mark the thread as solved :)

Be a part of the DaniWeb community

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