0

Hi guys,

In the below form when a user enters an admission number and click on the relevant type report the report was generated. ..Then I want something like this.When a user enters an admission number which is already existing, a validation should come as "The number already existed". How can i do that?

<form name="form1" method="post" action="certificaterValid.php">
<table width="850" border="1" align="center" bgcolor="#00FFFF">
  <tr>
    ing="0" cellspacing="0">

      <tr>
        <td width="25%"><img src="../IMAGE/banner - Copy.jpg" alt="" width="186" height="136" /></td>
        <td width="75%" align="center" valign="middle"><div align="center"><img src="../IMAGE/banner.jpg" alt="" width="733" height="137" /></div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td width="170">&nbsp;</td>
    <td width="664"><table width="657" border="0">
      <tr>
        <td width="124"><a href="../../Home page/new student registration/add_or_manage.php">Manage Data</a></td>
        <td width="124">&nbsp;</td>
        <td width="124">&nbsp;</td>
        Change Password
        <td width="129" align="center"><a href="../Home page/new student registration/signout.php">Signout</a></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="59" valign="top"><ul id="MenuBar1" class="MenuBarVertical">

Add Admin Login

      <li><a href="../../Student registration/new student registration/newStudentRegistrationForm.php">Add Student</a></li>
      <li><a href="../../student attendance/add attendance/addStudentAttendance.php">Add Student Attendance</a> </li>
      <li><a href="../../Student time table/add1 time table/addTimeTable.php">Add Time Table</a></li>
      <li><a href="../../Student marks/add student marks/addStudentMark.php">Add Student Marks</a></li>
      <li><a href="../../manage subject/add subject.php">Add Subject</a></li>

Search Student Information

      <li><a href="../../student payments reports/studentsPayments.php">Student Payment Reports</a></li>
      <li><a href="../../Issue certificate/issueCertificate.php">Issue Certificates</a></li>
    </ul>
      <p>&nbsp;</p>
    <p>&nbsp;</p></td>
    <td valign="top"><table width="659" border="0">
      <tr>
        <td>&nbsp;</td>
        <td colspan="8">&nbsp;</td>
      </tr>
      <tr>
        <td width="14">&nbsp;</td>
        <td colspan="8"><h3>
          <label>Issue cretificate</label>
          &nbsp;</h3></td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td width="153">&nbsp;</td>
        <td width="3">&nbsp;</td>
        <td width="128">&nbsp;</td>
        <td width="32">&nbsp;</td>
        <td width="60">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="55">&nbsp;</td>
        <td width="66">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><label>Admission No</label>&nbsp;</td>
        <td>&nbsp;</td>
        <td>

             <center>
<div >
  <input type="text" onkeyup="getScriptPage('box','text_content')" id="text_content" size="40" name="admission_no" />
  <div id="box"></div>
</div>
</center>        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><label>Issue  Cetificate</label>&nbsp;</td>
        <td>&nbsp;</td>
        <td>
          <select name="report" id="jumpMenu" >

            <option value="c">Character</option>
            <option value="r">Recommendation</option>
          </select>        </td>
        <td>&nbsp;</td>
        <td>

            <input type="submit" name="Submit" id="button" value="Issue" onClick="return Validate();"/>        
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>

    </table>
      <p>&nbsp;</p>
    <p>&nbsp;</p></td>
  </tr>
</table>
</form>

Below is the PHP coding..How can i edit the coding to fulfill my above requirement?

<?php

$admission_no=$_POST["admission_no"];
$report=$_POST["report"];
$date=date("Y-m-d");
$con=mysql_connect("localhost","root","");
mysql_select_db("student_management",$con);


if($report=="l"){
    $query="insert into certificate values(null,'$admission_no','$report','$date')";
$result=mysql_query($query);
        header("location:leavingCertificate.php?admission_no=".$admission_no."&report=".$report);
exit();

}
if($report=="c"){
    $query="insert into certificate values(null,'$admission_no','$report','$date')";
    $result=mysql_query($query);
        header("location:characterCertificate.php?admission_no=".admission_no."&report=".$report);
exit();
}
if($report=="r"){
    $query="insert into certificate values(null,'$admission_no','$report','$date')";
$result=mysql_query($query);
        header("location:recommendLetter.php?admission_no=".$admission_no."&report=".$report);
exit();
}


?>
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by jstfsklh211
0

@heshanm

if($report

Why are your repeating the if statement that often?

Try to used:

if ($_POST){
      $admission_no=$_POST["admission_no"];
      $report=$_POST["report"];
      $date=date("Y-m-d");
if (!$admission_no){
        $msg = "Please Add something";
} else {
        $msg = "The number already existed";
    }
}

I'm not going to write all of the code! This is something you can start to work on. Hopefully you can try to understand what I wrote and this will give you idea how to finish writing the code that you wanted or needed.

0

instead of just doing a plain insert

insert into certificate values(null,'$admission_no','$report','$date')

use an insert select

INSERT INTO certificate (admission_no, report, date) SELECT '$admission_no','$report','$date' FROM certificate WHERE //check whatever values you dont want repeated ie admission_no HAVING (count(*) = 0)

also you might want to look into sql injection as this code leaves you wide open

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.