Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 11-18-2021, 09:13 PM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Control SQL query through URL?

Im trying to figure out how to run an sql query via a url with a string appended to it like this:

domain.com/collection.php?keyword=chicken%garlic

That would display a listing of recipes where the ingredients specifically contained both chicken and garlic.

This is what I have in my regular SQL statement in the coding, how would I make it so that the URL controls the SQL query itself?

Quote:
$con=mysqli_connect("localhost","user","pass","dat abase");

$result = mysqli_query($con,"SELECT * FROM Recipe WHERE Ingredient REGEXP '(?=.*chicken)(?=.*garlic)' ORDER BY RAND() LIMIT 10;");
Is this even possible without significantly changing what I already use for the pages SQL query?

The end goal is to be able to randomly list a bunch of specific recipes from the database in their own page, kind of like how sites like TasteofHome and BHG do for their visitors as a 'recipe collection' article.

So in this instance, that url when clicked would display some filler content, with a dynamically generated listing of 10 (or however many I choose) random recipes that contain both chicken and garlic in their ingredients.

As I undertand it, I'll need to put an escape string in the page somewhere to(?)

Any help/pointers would be greatly appreciated.
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-18-2021, 11:44 PM   #2
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
Untested, and assuming your regex is correct.


domain.com/collection.php?keyword=chicken|garlic

$keywords = explode("|",$_GET['keyword']);
foreach($keywords as $i) {
$output[] = "(?=.*".mysqli_real_escape_string($con,$i).")" ;
}
$result = mysqli_query($con,"SELECT * FROM Recipe WHERE Ingredient REGEXP '".implode("",$output)."' ORDER BY RAND() LIMIT 10");
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-19-2021, 08:10 AM   #3
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
Quote:
Originally Posted by k0nr4d View Post
Untested, and assuming your regex is correct.


domain.com/collection.php?keyword=chicken|garlic

$keywords = explode("|",$_GET['keyword']);
foreach($keywords as $i) {
$output[] = "(?=.*".mysqli_real_escape_string($con,$i).")" ;
}
$result = mysqli_query($con,"SELECT * FROM Recipe WHERE Ingredient REGEXP '".implode("",$output)."' ORDER BY RAND() LIMIT 10");
Thank you.

That gives me something to work off, its tossing out a few SQL errors but I can get those fixed.

Appreciate the assistance
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-19-2021, 04:05 PM   #4
V_RocKs
Damn Right I Kiss Ass!
 
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,391
domain.com/collection.php?keyword=chicken%garlic'--; SELECT * from...
V_RocKs is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-19-2021, 04:26 PM   #5
fuzebox
making it rain
 
fuzebox's Avatar
 
Industry Role:
Join Date: Oct 2003
Location: seattle
Posts: 22,009
Quote:
Originally Posted by V_RocKs View Post
domain.com/collection.php?keyword=chicken%garlic'--; SELECT * from...
fuzebox is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
sql, query, url, recipes, chicken, garlic, page, ingredients, recipe, string, display, listing, visitors, collection, instance, article, appreciated, specific, bunch, list, database, tasteofhome, sites, bhg, randomly
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.