guys i am new to php and have a trouble about validation of a text box. i have to create a student database and its interface capable of insert/delete/view/update option. say now am trying to delete a student from the database i should enter the register number to delete. in this case, if i enter a register number not in the database then too the file redirects to success page. i have made validation for non-zero entry of register number. now my problem is if i want to delete a student who is not in the database it should be redirected to a error page. this should be done using php, javascript and mysql. how am to do this?
here is my delete student code:
<!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>Students Database</title>
<meta author="" content="">
<link rel="stylesheet" type="text/css" href="view.css" media="all">
</head>
<body id="main_body" >
<img id="top" src="top.png" alt="">
<div id="form_container">
<h1><a>Students Database</a></h1>
<form name="admin4" class="appnitro" method="post" action="delete1.php">
<div class="form_description">
<center><h2>Students Database</h2></center>
<p><center><font size='3'>
<?php
$con=mysqli_connect("localhost","admin","123456","mop");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM student");
echo "<table border='1'>
<tr>
<th>Register No</th>
<th>Name       </th>
<th>Department   </th>
<th>Class   </th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['RegNo'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "<td>" . $row['Class'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</center></font></p>
</div>
<b>Enter Register Number <font color='red'>*</font> </b> <input type="text" name="regno"><p>
<ul >
<center><li class="buttons">
<input type="hidden" name="form_id" value="768845" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Delete" /></center>
</li>
</ul>
</form>
</div>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>
the above is the interface code and here is the processing part code:
<?php
$con=mysqli_connect("localhost","admin","123456","mop");
if ($_POST['regno'] == '')
{
header("location:admin4_2.php");
}
else
{
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql1="DELETE from student where regno = ".intval($_POST["regno"]);
if (!mysqli_query($con,$sql1))
{
die('Error: ' . mysqli_error($con));
}
else
{
header("location:admin6_1.php");
}
}
mysqli_close($con);
?>
as u see i have done it to check for non-zero entry. is it possible to check with table for valid register number? can anyone explain me how to do in detail with the code because am new to php and this is my first project. i dont mind using javascript or php for it. if javascript is being used can anyone also show me the code of javascript too??