Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:52:00+00:00 2026-06-06T21:52:00+00:00

Possible Duplicate: PHP, MySQL validation malfunction and search doesn't work? I have created a

  • 0

Possible Duplicate:
PHP, MySQL validation malfunction and search doesn't work?

I have created a form, every thing is working fine, except the search. For example whenever a user input any value in the search box, it will display the result from the database, example name of the employee and etc…
Please see my coding below…

<html>
<head>
<?php
//require_once('student_form.php');
if(isset($_POST['search'])){ 
$id=$_REQUEST['id']; 
$fname=$_POST['fname'];
    //connect  to the database 
include('connection.php');
//-query  the database table 
$sql=mysql_query("SELECT  * FROM members WHERE (FirstName LIKE '". $fname ."%' OR LastName LIKE '". $lname ."%'");
    //-run  the query against the mysql query function 
    $result=mysql_query($sql); 

    if($row=mysql_fetch_array($result)){ 
                $fname=$row['FirstName']; 
                $lname=$row['LastName']; 
                /*$email=$row['Email'];
                $age =$row['Age'];
                $gender=$row['Gender'];
                $course = $row['Course'];*/
    }
    //-display  the result of the array 
    else
    {
    <?php echo $rows['FirstName']; ?>
    <?php echo $rows['LastName']; ?>
    } 
} 
?>
</head>
<body>
<form action="search.php" method="post">
<table>
    <tr>
    <td><strong>search box</strong></td>
    <td><strong>:</strong></td>
    <td><input type="text" name="search" value=""size="30"/><input type="submit" name="s1" value="Search"/></td>

</table>
</form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:52:02+00:00Added an answer on June 6, 2026 at 9:52 pm

    Please note that using the old mysql_ extensions are being deprecated … see the notice at the top of the mysql_query doc

    Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

    • mysqli_query()
    • PDO::query()

    But for you to see what the problem is, replace this line :

    $sql=mysql_query("SELECT  * FROM members WHERE (FirstName LIKE '". $fname ."%' OR LastName LIKE '". $lname ."%'");
    //-run  the query against the mysql query function 
    $result=mysql_query($sql); 
    

    with this :

    $result=mysql_query("SELECT  * FROM members WHERE (FirstName LIKE '". $fname ."%' OR LastName LIKE '". $lname ."%'");
    if (!$result) {
        die('Could not query:' . mysql_error());
    }
    

    You only need to execute mysql_query once and this will now output the error with your query … as mysql_query returns a boolean false if the query fails … see the docs here

    And please, please take some time to read about SQL Injection

    Note this answer will fix your problem – but just fixing it wont help you in the future ….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: E-mail validation in php? please help I have Ajax sign up form.
Possible Duplicate: PHP MySQL Search And Order By Relevancy Hi, I have a table
Possible Duplicate: PHP MySQL multiple search query using option / select HTML form tags
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
Possible Duplicate: Rating System in PHP and MySQL I am working on a rating
Possible Duplicate: Format mysql datetime with php Well.. I have stored date(c) in Mysql
Possible Duplicate: highlighting search results in php/mysql I am doing a search with a
Possible Duplicate: PHP/MySQL - Format date/time I have input field (name:day1 and varchar) to
Possible Duplicate: PHP/MYSQL using an array in WHERE clause I have an array with
Possible Duplicate: Special characters in PHP / MySQL I have a problem. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.