Jump to content

Php Search MySql


NasimUddinAhmmad
Go to solution Solved by Barand,

Recommended Posts

Hello friends,

I am a novice in php. Though I create 2 scripts:

 

1. students registration form

2. search students by Registration Number

 

Our students' Registration Numbers are as follows: nifeA001, nifeA002 & so on...

 

But when someone enter just "nife" or "n" or "A" etc all the students's data is showing.

 

I want that students can search data by entering only Full Registration Number not a Part.

 

I am placing the search.php code below. Please help me out....

 

----------------- Search.php ------------------

<?php

mysql_connect("localhost", "root", "") or die("could not connect");

mysql_select_db("student") or die("could not connect");

 

//collect

if(isset($_POST['search'])) {

    $searchq = $_POST['search'];

    $searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);

 

//here

$query = mysql_query("SELECT * FROM user WHERE registration LIKE '%$searchq%'") or die("could not search!");

    $count = mysql_num_rows($query);

    if($count == 0){

        $output = 'There was no search results!';

    }else{

        while($row = mysql_fetch_array($query)) {

            $fname = $row['firstname'];

            $lname = $row['surname'];

            $id = $row['registration'];

 

            $output .= '<div> '.$id.' '.$fname.' '.$lname.'</div>';

               }

        }

}

 

?>

 

<html>

<head>

</head>

<body>

<form action="form.php" method="post">

    <input type="text" name="search" placeholder="search for students.."

    <input type="submit" value=">>" />

</form>

 

<?php print("$output");?>

</body>

</html>

Edited by NasimUddinAhmmad
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.