473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to allow the visitor to a page if they have entered only full registration number

Hi Experts,

I've created a resulting script like this

search.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Make a MySQL Connection
  4. mysql_connect("localhost", "db_user_name", "db_user_password) or die(mysql_error());
  5. mysql_select_db("db_name") or die(mysql_error());
  6.  
  7.     $query = $_GET['query']; 
  8.  
  9.  
  10.     $min_length = 3;
  11.  
  12.  
  13.     if(strlen($query) >= $min_length){ 
  14.  
  15.         $query = htmlspecialchars($query); 
  16.  
  17.          $query = mysql_real_escape_string($query);
  18.  
  19.          $raw_results = mysql_query("SELECT * FROM students_mark_table
  20.             WHERE (`reg_number` LIKE '%".$query."%')" or die(mysql_error());
  21.  
  22.         if(mysql_num_rows($raw_results) > 0){
  23.  
  24.             while($results = mysql_fetch_array($raw_results)){
  25.  
  26.              echo "<p><h3>Registration&nbsp;Number:&nbsp;".$results['reg_number']."</h3><br></br><h3>Name:&nbsp;".$results['name']."</h3><br></br><h3>Subject:&nbsp;".$results['subject']."</h3><br></br><h3>Marks:&nbsp".$results['marks']."</h3></p>";
  27.             }
  28.  
  29.         }
  30.         else{ 
  31.             echo "You've Entered incorrect registration number or The number may not existed"
  32.         }
  33.  
  34.     }
  35.     else{
  36.         echo "Minimum length is ".$min_length;
  37.     }
  38. ?>

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
  1. <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 == &quot;&quot;) {this.value = &quot;Enter Your REGISTRATION NUMBER&quot;;}' onfocus='if (this.value == &quot;Enter Your REGISTRATION NUMBER&quot;) {this.value = &quot;&quot;}' size='30' type='text' value=''/>  
  2.   <input class='submit' type='submit' value='Submit'/></center></form>
In the My Sql table all registration numbers of the student are 6 digit numbers.

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..
Mar 17 '13 #1

✓ answered by Niheel

Edit the following line:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $raw_results = mysql_query("SELECT * FROM students_mark_table
  3.             WHERE (`reg_number` LIKE '%".$query."%')" or die(mysql_error());
  4.  
to:

Expand|Select|Wrap|Line Numbers
  1.  $raw_results = mysql_query("SELECT * FROM students_mark_table
  2.             WHERE (`reg_number` LIKE '".$query."')" or die(mysql_error());
  3.  
The removal of "%" before and after says you want an exact match returned.

2 1555
Niheel
2,460 Expert Mod 2GB
Edit the following line:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $raw_results = mysql_query("SELECT * FROM students_mark_table
  3.             WHERE (`reg_number` LIKE '%".$query."%')" or die(mysql_error());
  4.  
to:

Expand|Select|Wrap|Line Numbers
  1.  $raw_results = mysql_query("SELECT * FROM students_mark_table
  2.             WHERE (`reg_number` LIKE '".$query."')" or die(mysql_error());
  3.  
The removal of "%" before and after says you want an exact match returned.
Mar 17 '13 #2
Thank YOU............. :)
Mar 17 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Grant Rutherford | last post by:
Hello, I need to get a float8 to display as a number db=# SELECT CAST('0.00001' AS float8); float8 -------- 1e-05 (1 row)
2
by: r dubey | last post by:
Hi, I'm using webclient to enable download of files. However, files get copied to the server rather than the client machine. What could be the problem. Here is the sample that I've used: ...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
7
by: jakeruston | last post by:
Hello, Firstly, i would just like to say this is my first time on this site, and it looks rather cool and helpful! Now, i need a script that: -When the customer purchases a product, a random...
1
by: priyakollu | last post by:
hi guys! please help me in this prob ..while installing .net i have entered wrong serial number....still the installation process continued and whole thing got installed .......but when im trying to...
3
by: DAVE Reed | last post by:
How or where do I get the registration number required to register my copy of Visual Basic 2005 (VB.NET)?
0
by: Hetal | last post by:
We recently upgraded to VS 2008 and for some reason, the environment does not show "Start Page" in full screen mode even when setting in Environment -Startup is set to "Show Start Page". It does...
1
by: thulaseeram | last post by:
Hi to All, I am using general javascript function isNAN to validate whether entered input is number or not it is doing ok. But it should take space in between code number and phone number. ...
1
by: crazy works | last post by:
hello i was working on design new style for games script called onarcade and i want to stretch it , i mean i want to make the script width full screen in the script one css file and i had a...
7
by: dawn123 | last post by:
I have a text box that I only want a user to be able to enter integers. I have it so that if a number with a decmail place is enter a error message comes up. But when i was testing the code, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.