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

  • Home
  • SEARCH
  • 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 6325259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:51:46+00:00 2026-05-24T16:51:46+00:00

I am trying to create a basic search function. I have a text field

  • 0

I am trying to create a basic search function. I have a text field with an id of “npa” when I submit I would like the values placed in the npa field to be inserted in to the $searchroute mysql query.

I am VERY new to php so this has got me slightly stumped.

if ($_POST["submit"]) {

    $searchroute = "SELECT * FROM destination_route as d WHERE d.destPrefix='npa'";


    $results = mysql_query($searchroute);
    $row = mysql_fetch_array($results);
    print_r($row);

}


    ?>

<html>

    <form name="query" id="showdid" action="" method="post" enctype="multipart/form-data" >
    <input type="text" name="npa" id="npa" value="">
    <input type="submit" name="submit" id="submit" value="Submit">
    </form>

</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-05-24T16:51:46+00:00Added an answer on May 24, 2026 at 4:51 pm

    Since you’re already using the mysql_* functions, the example code below also uses them. However, you should abandon those functions and instead use PDO. That aside:

    <?php
    if (!empty($_POST['submit'])) {
    
        if (!empty($_POST['npa'])) {
    
            $searchroute = "SELECT * 
                            FROM destination_route as d 
                            WHERE d.destPrefix='".mysql_real_escape_string($_POST['npa'])."'";
    
            $results = mysql_query($searchroute);
            $row = mysql_fetch_array($results);
            print_r($row);
        }
    }
    ?>
    
    <html>
    
        <form name="query" id="showdid" action="" method="post">
        <input type="text" name="npa" id="npa" value="">
        <input type="submit" name="submit" id="submit" value="Submit">
        </form>
    
    </html>
    

    All I did was add some calls to empty (to avoid notices in case the variables haven’t been created), escaped the data as it was sent to the database (very important, PDO makes this much easier too) and removed the enctype="multipart/form-data" as it’s not needed for your functionality (no files are being uploaded).

    I’ve kept my modifications to a minimum to better show the basics of what needs to occur. There’s much more you can do, such as perform additional sanitizing/validating of the input, e.g., triming the input, etc…

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

Sidebar

Related Questions

I'm trying to create a basic template to display the selected instance's field values,
I'm trying to create a basic submit form (like the dajaxice's example) but i
I'm trying to create a basic navigation and I'd like to have a horizontal
Question I'm trying to create a basic wxWidgets program with a text entry box,
I'm trying to create a basic function to swap the endianness of a short
I am trying to implement a basic full-text search with MySQL. I wrote this
I am trying to create a basic video and text chat web site.In the
I'm trying to create a basic system that will allow only specific users to
I'm trying to create a basic shopping cart, having an issue with the product
I'm trying to create a very basic Setup and Deployment project using Visual Studio.

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.