I've created a resulting script like this
search.php
Expand|Select|Wrap|Line Numbers
- <?php
- // Make a MySQL Connection
- mysql_connect("localhost", "db_user_name", "db_user_password) or die(mysql_error());
- mysql_select_db("db_name") or die(mysql_error());
- $query = $_GET['query'];
- $min_length = 3;
- if(strlen($query) >= $min_length){
- $query = htmlspecialchars($query);
- $query = mysql_real_escape_string($query);
- $raw_results = mysql_query("SELECT * FROM students_mark_table
- WHERE (`reg_number` LIKE '%".$query."%')" or die(mysql_error());
- if(mysql_num_rows($raw_results) > 0){
- while($results = mysql_fetch_array($raw_results)){
- echo "<p><h3>Registration Number: ".$results['reg_number']."</h3><br></br><h3>Name: ".$results['name']."</h3><br></br><h3>Subject: ".$results['subject']."</h3><br></br><h3>Marks: ".$results['marks']."</h3></p>";
- }
- }
- else{
- echo "You've Entered incorrect registration number or The number may not existed"
- }
- }
- else{
- echo "Minimum length is ".$min_length;
- }
- ?>
The Sql table Data's like this....
Table Name is /--->students_mark_table<----\
It is having, reg_number, name, subject, marks.
The input section like this
index.php
Expand|Select|Wrap|Line Numbers
- <h1>Enter Your REGISTRATION NUMBER in the box</h1><form name="myForm" action="search.php" onsubmit="return validateForm()" method="GET"><center> <input name='query' onblur='if (this.value == "") {this.value = "Enter Your REGISTRATION NUMBER";}' onfocus='if (this.value == "Enter Your REGISTRATION NUMBER") {this.value = ""}' size='30' type='text' value=''/>
- <input class='submit' type='submit' value='Submit'/></center></form>
In the sql table there is a register number existed like this "405060". When I Enter the registration number(405060) in the form in index.php page, The output of the page is
Registration Number: 405060
Name: BALA
Subject: ENGLISH
Marks: 98
But, IF I've entered few charactors of the registration Number "4050" or "40506" It also shows the result of the Registration Number "405060".
How to I block the output from entering few charactors. Only allow if the full charactors entered.
There is more than registration number existed in the sql same series of the registration number like this "405067", "405062". If the visitor entered few charactors like this "40506" It shows the output of all registration number of the same series.
How to I solve this.. please help me..