0

Hi all,

I have small problem regarding my student registration form. When i enter data and submit always below message is displayed irrespective of whether the admission_id is exist or not.

"Admission numberThis student has been already entered to the system"

newStudentRegistrationForm.php

<form name="form1" method="post" action="newStudentRegistrationFormvalidation.php">
<?PHP
$con=mysql_connect("localhost","root","");
mysql_select_db("student_management",$con);

?>
<table width="850" border="1" align="center">
  <tr>
    <td colspan="2"><table width="100%" cellpadding="0" cellspacing="0">
      <tr>
        <td width="25%"><img src="IMAGE/logo.png" width="200" height="200" /></td>
        <td width="75%" align="center" valign="middle"><div align="center">
          <blockquote>
            <p><img src="../../IMAGE/banner.jpg" width="491" height="88" /></p>
          </blockquote>
        </div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td width="170">&nbsp;</td>
    <td width="664"><table width="600" border="0">
      <tr>
        <td width="124">&nbsp;</td>
        <td width="124">&nbsp;</td>
        <td width="124">&nbsp;</td>
        <td width="124" align="center"><a href="../../add admin users/changePasword.php">Change Password</a></td>
        <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"><table width="170" border="1" bordercolor="#000000">
      <tr>
        <td width="162"><a href="../../add admin users/add techer/addAdminUser.php">
          <label>Add Admin Login</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../add admin users/manage teacher/searchAdminUser.php">
          <label>Manage Addmin Login</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td bgcolor="#CCCCCC"><label>Add Student</label>
          &nbsp;</td>
      </tr>
      <tr>
        <td><a href="../manage student details/manageStudentDetails.php">
          <label>Manage Student</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../student attendance/add attendance/addStudentAttendance.php">&nbsp;
            <label>Add Student AttendanceĀ </label>
        </a></td>
      </tr>
      <tr>
        <td><a href="../../student attendance/manage attendance/manageStudentAttendance.php">&nbsp;
            <label>Manage Student AttendanceĀ </label>
        </a></td>
      </tr>
      <tr>
        <td><a href="../../Student time table/add1 time table/addTimeTable.php">
          <label>Add Time Table</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../Student time table/maange time table/manageTimeTable.php">
          <label>Manage Time Table</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../Student marks/add student marks/addStudentMark.php">
          <label>Add Student Marks</label>
        </a></td>
      </tr>
      <tr>
        <td><a href="../../Student marks/manage stdent marks/manageStudentMark.php">
          <label>Manage Student Marks</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../manage subject/add subject.php">
          <label>Add Subject</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../manage subject/manage subject.php">
          <label>Manage Subject</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../search student information/SearchStudentInformation.php">
          <label>Search Student Information</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../manage students grade/manage student grade.php">
          <label>Manage Student Grade</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../manage student class/manageStudentClass.php">
          <label>Manage Student Class</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../manage student payment/manageStudentsPayments.php">
          <label>Manage Student Payment</label>
        </a></td>
      </tr>
      <tr>
        <td><a href="../../home management/home management.php">
          <label>Manage Home Page</label>
          &nbsp;</a></td>
      </tr>
      <tr>
        <td><a href="../../student payments reports/studentsPayments.php">
          <label>Student Payment Reports</label>
          &nbsp;</a></td>
      </tr>

      <tr>
        <td><a href="../../Issue certificate/issueCertificate.php">
          <label>Issue Certificate</label>
          &nbsp;</a></td>
      </tr>
    </table></td>
    <td><table width="633" border="0">
      <tr>
        <td>&nbsp;</td>
        <td colspan="5">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td width="9">&nbsp;</td>
        <td colspan="5"><h3>
          <label><strong>Add Student Information</strong></label>
          <strong>&nbsp;</strong></h3></td>
        <td width="13">&nbsp;</td>
        <td width="19">&nbsp;</td>
        <td width="51">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td colspan="3">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td colspan="3">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Admission Number </label>&nbsp;</td>
        <td colspan="3">

            <input type="text" name="admission_no" id="textfield" />        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Admission Date</label>&nbsp;</td>
        <td colspan="5">

            <input type="text" name="admission_date" id="admission_date" /><a href="javascript:NewCssCal('admission_date','yyyymmdd')">
<img src="images/cal.gif"alt="Pick a date" width="16" height="16" border="0"></a>         </td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Student Full Name </label>&nbsp;</td>
        <td colspan="3">

            <textarea name="full_name" id="textfield2"></textarea>       </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Student Name With Initials  </label>&nbsp;</td>
        <td colspan="3">

            <input type="text" name="name_with_initial" id="textfield3" />        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Date of Birth </label>&nbsp;</td>
        <td colspan="3"><input type="text" name="date_of_birth" id="date_of_birth" /><a href="javascript:NewCssCal('date_of_birth','yyyymmdd')">
<img src="images/cal.gif"alt="Pick a date" width="16" height="16" border="0"></a></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Religion </label>&nbsp;</td>
        <td colspan="3"><label>
          <select name="religion" id="select2">
            <option selected="selected"></option>
            <option>Buddhism</option>
            <option>Cathelic</option>
            <option>Roman Cathelic</option>
            <option>Muslim</option>
            <option>Hindu</option>
            <option>Other</option>
             </select>
        </label></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Address </label>&nbsp;</td>
        <td colspan="3">

            <textarea name="address" id="textarea" cols="45" rows="5"></textarea>           </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Telephone Number </label>&nbsp;</td>
        <td colspan="3">

            <input type="text" name="telephone" id="textfield6" />       </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Grade on Admission </label>&nbsp;</td>
        <td colspan="3">
          <select name="grade_on_admission" id="jumpMenu" >
          <?PHP

$query="SELECT * FROM grade ";
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{
  echo "<option value=\"".$row['grade_id']."\">".$row['grade']."</option> \n  ";
}
            ?>
          </select>        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Present Grade</label>&nbsp;</td>
        <td width="113">
          <select name="grade_ID" id="jumpMenu2" onchange="changestream()" >
<?php

$query="SELECT * FROM grade ";
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{
  echo "<option value=\"".$row['grade_id']."\">".$row['grade']."</option> \n  ";
}
            ?>
          </select>        </td>
        <td width="59"><label>Stream</label>&nbsp;</td>
        <td>
          <select  name="stream_ID" id="jumpMenu4"  disabled="disabled">
            <option selected="selected"></option> 
            <option>Maths</option>
            <option>Science</option>
            <option>Commerce</option>
            <option>Art</option>
          </select>        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Present Class</label>&nbsp;</td>
        <td colspan="3">
          <select name="class_ID" id="jumpMenu3" >
            <option selected="selected"></option>
            <option>A</option>
            <option>B</option>
            <option>C</option>
            <option>D</option>
            <option>E</option>
            <option>F</option>
            <option>G</option>
            <option>H</option>
            <option>I</option>
            <option>J</option>
            <option>K</option>
            <option>L</option>
            <option>M</option>
            <option>N</option>
            <option>O</option>
            <option>P</option>
            <option>Q</option>
            <option>R</option>
            <option>S</option>
            <option>T</option>
            <option>U</option>
            <option>V</option>
            <option>W</option>
            <option>X</option>
            <option>Y</option>
            <option>Z</option>
          </select>        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Student House</label>&nbsp;</td>
        <td colspan="3">
          <select name="student_house" id="select">
            <option selected="selected"></option>
            <option>PARAVI</option>
            <option>HANSA</option>
            <option>GIRA</option>
            <option>KOKILA</option>
          </select>        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>School payments</label>&nbsp;</td>
        <td colspan="3">

            <input type="radio" name="payment" id="radio3" value="2000" />
            yes
            <input type="radio" name="payment" id="radio4" value="0" checked="checked"/>

        no        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Password</label>&nbsp;</td>
        <td colspan="3">
          <input type="password" name="password" id="textfield8" />        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Confirm Password</label></td>
        <td colspan="3">
          <input type="password" name="ConfirmPassword" id="textfield9" />        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2"><label>Student Description</label>&nbsp;</td>
        <td colspan="3">

            <textarea name="description_about_st" id="textarea2" cols="45" rows="5">
            </textarea>        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td colspan="3">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>

      <tr>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td colspan="3">

            <input type="submit" name="button3"  id="button3" value="Save" onClick="return Validate();"/>        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td colspan="3">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
      <p>&nbsp;</p>
    <p>&nbsp;</p></td>
  </tr>
</table>
</form>

newStudentRegistrationFormValidation.php

<?php

$admission_no=$_POST['admission_no'];
$admission_date=$_POST['admission_date'];
$full_name=$_POST['full_name'];
$name_with_initial=$_POST['name_with_initial'];
$date_of_birth=$_POST['date_of_birth'];
$religion=$_POST['religion'];
$address=$_POST['address'];
$telephone=$_POST['telephone'];
$grade_on_admission=$_POST['grade_on_admission'];
$grade_ID=$_POST['grade_ID'];
$stream_ID=isset($_POST['stream_ID']) ? $_POST['stream_ID'] :'';
$class_ID=$_POST['class_ID'];
$student_house=$_POST['student_house'];
$password=$_POST['password'];
$description_about_st=$_POST['description_about_st'];
$payment=$_POST["payment"];


$currentdate=getdate(time());
$year=$currentdate["year"];

//admission number validation

$answer='';

$con=mysql_connect("localhost","root","");
mysql_select_db("student_management",$con);
$query="SELECT admission_no FROM student_info WHERE student_info.admission_no='$admission_no'";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){

    $answer=$row['admission_no'];}
    if($answer==0)
{
header("location:studentregistrationDatabase.php?admission_no=".urlencode($admission_no)."&year=".urlencode($year)."&admission_date=".urlencode($admission_date)."&full_name=".urlencode($full_name)."&name_with_initial=".urlencode($name_with_initial)."&date_of_birth=".urlencode($date_of_birth)."&religion=".urlencode($religion)."&address=".urlencode($address)."&telephone=".urlencode($telephone)."&grade_on_admission=".urlencode($grade_on_admission)."&grade_ID=".urlencode($grade_ID)."&stream_ID=".urlencode($stream_ID)."&class_ID=".urlencode($class_ID)."&student_house=".urlencode($student_house)."&password=".urlencode($password)."&description_about_st=".urlencode($description_about_st)."&payment=".urlencode($payment));
exit();

}else{



?>
<body>
<?php
 echo "Admission number".$admission_no."This student has  been alredy entered to the system ."."<BR>"."<BR>"."<BR>";
 echo "<a href='newStudentRegistrationForm.php'>GO to manage student details page</a> ";
 exit();
}?>

studentregistrationDatabase.php

<?PHP

 $admission_no=isset($_POST['admission_no']) ? $_POST['admission_no'] :'';
 $admission_date=isset($_POST['admission_date']) ? $_POST['admission_date'] :'';
 $full_name=isset($_POST['full_name']) ? $_POST['full_name'] :'';
 $name_with_initials=isset($_POST['name_with_initial']) ? $_POST['name_with_initial'] :'';
 $dob=isset($_POST['date_of_birth']) ? $_POST['date_of_birth'] :'';
 $religion=isset($_POST['religion']) ? $_POST['religion'] :'';
 $address=isset($_POST['address']) ? $_POST['address'] :'';
 $telephone=isset($_POST['telephone']) ? $_POST['telephone'] :'';
 $grade_on_admission=isset($_POST['grade_on_admission']) ? $_POST['grade_on_admission'] :'';
 $present_grade=isset($_POST['grade_ID']) ? $_POST['grade_ID'] :'';
 $stream=isset($_POST['stream_ID']) ? $_POST['stream_ID'] :'';
 $present_class=isset($_POST['class_ID']) ? $_POST['class_ID'] :'';
 $student_house=isset($_POST['student_house']) ? $_POST['student_house'] :'';
 $password=isset($_POST['password']) ? $_POST['password'] :'';
 $description_about_st=isset($_POST['description_about_st']) ? $_POST['description_about_st'] :'';
 $payment=isset($_POST["payment"]) ? $_POST["payment"] :'';

$current=getdate(time());
$year=$current["year"];

$today = date("Y-m-d");


$con=mysql_connect("localhost","root","");
mysql_select_db("student_management",$con);

//insert to database

$query="select count(*) from student_info where admission_no='$admission_no'";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
if($row[0]==0)
{
$query="INSERT INTO student_info values('$admission_no','$admission_date','$full_name','$name_with_initials','$dob','$religion','$address','$telephone','$grade_on_admission','$password','$student_house','$description_about_st')";
$result=mysql_query($query);

if($stream!=null){

    $query="select class_id  from class
         where class.grade_id='$present_grade' and class.class_name='$present_class' and class.stream='$stream'";
    }else{

        $query="select class_id  from class
         where class.grade_id='$present_grade' and class.class_name='$present_class'";
        }
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$class_id=$row['class_id'];
}

$query="insert into student_class values('$admission_no','$class_id','$year')";
$result=mysql_query($query);

if($payment=="2000")
{
    $query="insert into payment_amount values(null,'2000','$today')";
    $result=mysql_query($query);

    $query="SELECT amount_id FROM payment_amount order by amount_id DESC limit 1";
    $result=mysql_query($query);
    while($row = mysql_fetch_array($result))
{
 $amount_id=$row['amount_id'];
}
    $query="insert into payment values('$admission_no','$amount_id')";
    $result=mysql_query($query);

}else{

    $query="insert into payment_amount values(null,'0','$today')";
    $result=mysql_query($query);

$query="SELECT amount_id FROM payment_amount order by amount_id DESC limit 1";
$result=mysql_query($query);
    while($row = mysql_fetch_array($result))
{
 $amount_id=$row['amount_id'];
}
    $query="insert into payment values('$admission_no','$amount_id')";
    $result=mysql_query($query);


}


header("location:../new student registration-parent details/studentRegistrationParentDetailsForm.php?admission_no=".$admission_no);
exit();
}

else{

?>


<!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>
</body>
<?php

echo "Admission number".$admission_no."This student has been already entered to the system"."<BR>"."<BR>"."<BR>";
echo "<a href='newSstudentRegistrationForm.php'>GO to registration page</a>";
exit();
}
?>
5
Contributors
9
Replies
10
Views
5 Years
Discussion Span
Last Post by IIM
0

You need to investigate further in these lines:

$query="select count(*) from student_info where admission_no='$admission_no'";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
if($row[0]==0)

I am not sure which field is better to use count for, but you may want to change it to something like this:

if($row['COUNT(admission_no)'] == 0 )

or something of that effect.

0

Or maybe something like this if you are checking to make sure that a number in the database doesn't match the number that is being submitted:

if($row['admission_no'] != $_POST['admission_no'])

It's hard for me to read your form to determine if the admission_no is autogenerated or not.

0

Try below.

$query="SELECT admission_no FROM student_info WHERE student_info.admission_no='$admission_no'";
$result=mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows > 0)
{
    // admission no already exist in system 
}
else
{
    // admission no not exist
}

Edited by vibhaJ: added code tag

0

Dear vibhadevit,

The coding works. But stil there is a problem. Even though the form submitted there are no records in the database.
Is there a problem in my insert query?

Tha table looks like this.

student_info (st_id, admission_no, admission_date, full_name, name_with_initial, date_of_birth, religion, address, telephone_nograde_on_admission, password, st_house, description_about_st)

0

Do this, if there is an error you'll know:

$query = "INSERT INTO student_info VALUES('$admission_no', '$admission_date', '$full_name', '$name_with_initials', '$dob', '$religion', '$address', '$telephone', '$grade_on_admission', '$password', '$student_house', '$description_about_st')";
$result = mysql_query($query) or die(mysql_error());

One likely error is that you have more columns then you are inserting. If that's the case, you'll need to specify which columns you want to use.

0

I checked and the error says,

Duplicate entry '' for key 'admission_no'

Is anyone got an idea about this?

0

You probably have a unique index set on admission_no, and you are trying to insert a value that is already in the table.

0

Check for unique constraint in your database and do as per vibha's post....
As per the error is concerned you are entering data into database even if the same admission_no is present which should be avoided as it is a unique field.

So,if record is already(That can be calculated if

$query="SELECT admission_no FROM student_info WHERE student_info.admission_no='$admission_no'";
$result=mysql_query($query);
$num_rows = mysql_num_rows($result);

num_rows is equal to 1) present donot insert record and display message that record is already present.

Edited by IIM

This question has already been answered. 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.