Jump to content

How do I make a Search function onto my website?

So I am making a small school project, where I need to make a website which is a website with a Create, Read, Update and Delete functions, but I also need a search function. I made the website for the most part, but I am having a hard time making a search function on my website. 

 

Is there anyway I can make a search function onto my website? 

 

My code and picture of my website is here:

 

https://imgur.com/a/4bGip7V

Link to comment
Share on other sites

Link to post
Share on other sites

In essence, it's a matter of running the SELECT mysql command towards the database, but it all depends on how advanced the search is supposed to be.

 

As for the code you've provided, it's not actually very secure, and it would be subject to a lot of potential explots, e.g. XSS and SQL injection to name the most serious flaws.

Link to comment
Share on other sites

Link to post
Share on other sites

of course there's a way

 

add an address column/field with the text datatype in the mysql table definition , then if you want drop the lastname and rename firstname to name

 

then go through the code and change all queries to refer to "name" and "address"

 

and learn to escape the input, never trust the user... use mysqli_real_escape_string: https://www.php.net/manual/en/mysqli.real-escape-string.php - see the procedural style which is what you're using.

Link to comment
Share on other sites

Link to post
Share on other sites

your search can be something as simple as 

 

// link is your sql connection

$querystring =  $_REQUEST['searchtext']; 
$queryesc = mysqli_real_escape_string($link,$querystring);

$results = mysqli_query($link,"SELECT * FROM user WHERE firstname LIKE '%".$queryesc."%' OR lastname LIKE '%".queryesc."%'");

 

% is like a * wildcard, means there can be some random text before and after  ... ex  "Johnathan"  will be returned if you search for "nath" because you added % and created  %nath% in the mysql query sent to the mysql server

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, Emil_Loenneberg SE said:

Is there a way to rename the tables from firstname and lastname to name and address?

Can you elaborate a little bit on where you want it changed?

Do you want it changed in your database, HTML page, or the HTML id?

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

Just change every instance of those words in your code with the ones you want... and in your database. Since you only have a handful of values it's simpler to just make a new table and use that.

 

And next time use code tags instead of screenshotting your code.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

-= Topic Merged =-

Your 3 topic have been merged into the original topic, please do not repost your topic; this is against our forum rules.

COMMUNITY STANDARDS   |   TECH NEWS POSTING GUIDELINES   |   FORUM STAFF

LTT Folding Users Tips, Tricks and FAQ   |   F@H & BOINC Badge Request   |   F@H Contribution    My Rig   |   Project Steamroller

I am a Moderator, but I am fallible. Discuss or debate with me as you will but please do not argue with me as that will get us nowhere.

 

Spoiler

  

 

Character is like a Tree and Reputation like its Shadow. The Shadow is what we think of it; The Tree is the Real thing.  ~ Abraham Lincoln

Reputation is a Lifetime to create but seconds to destroy.

You have enemies? Good. That means you've stood up for something, sometime in your life.  ~ Winston Churchill

Docendo discimus - "to teach is to learn"

 

 CHRISTIAN MEMBER 

 

 
 
 
 
 
 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Quote

Is there a way to rename the tables from firstname and lastname to name and address?

Yes. I have no idea what DB you're using but you can do a couple of things. However, (first, last) doesn't go into (name, address). I'm assuming you want to concatenate first and last then add the addresses separately. So I'll cover that. 

 

You could create a new table with name and address, then insert the concatenated name fields like this (The pipes concatenate the fields, there's also a concatenate function but again no idea what DB you use) :

INSERT INTO users_with_address (name)

SELECT firstname || ' ' || lastname FROM users

You can then drop your original table AFTER CHECKING THE DATA IS ALL THERE. Probably not too important in this case, but good to make it a habit. 

 

Some DBs support renaming, no idea if this is the case but the statements are here.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×