Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

$_get and SQL

Explorer ,
Feb 03, 2023 Feb 03, 2023

Hi, i have problem on connecting 2 tables with $_get in SQL

First, i have shown the menu category on my website

Screen Shot 2023-02-03 at 17.04.13.pngexpand image

Screen Shot 2023-02-03 at 17.03.10.pngexpand image

Screen Shot 2023-02-03 at 17.03.57.pngexpand image

I want to make a SQL to show the products what i clicked into the menu_category

Screen Shot 2023-02-03 at 17.05.39.pngexpand image

Please check where did i do wrong in the coding.

Screen Shot 2023-02-03 at 17.07.27.pngexpand image

292
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 03, 2023 Feb 03, 2023

Why don't you just code the menu to return the menu_type??

 

<a href="whateverURL.php?category=A">Clothing</a>

<a href="whateverURL.php?category=B">Sports</a>

<a href="whateverURL.php?category=C">Disney/USJ</a>

 

Then:

 

$category = $_GET['category'];

 

$sql ="SELECT * FROM Products WHERE menu_type = '$category'"'

 

No need for table joins for this simple task.

 

I would advise NOT to include your php variable within the sql query, that's a security risk and open to sql injection attacks on your

...
Translate
Explorer ,
Feb 03, 2023 Feb 03, 2023

so when i click "clothing" on the menu, (menu_type is "A"), i want to show the products that the menu_type is "A". So basically what i GET from menu, it will become the condition of selecting the products.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2023 Feb 03, 2023

Why don't you just code the menu to return the menu_type??

 

<a href="whateverURL.php?category=A">Clothing</a>

<a href="whateverURL.php?category=B">Sports</a>

<a href="whateverURL.php?category=C">Disney/USJ</a>

 

Then:

 

$category = $_GET['category'];

 

$sql ="SELECT * FROM Products WHERE menu_type = '$category'"'

 

No need for table joins for this simple task.

 

I would advise NOT to include your php variable within the sql query, that's a security risk and open to sql injection attacks on your database. You should be using sql 'prepared statements'. Anything that a user can potentially alter through a $_GET  or a $_POST input field request should never be included directly within an sql query.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 04, 2023 Feb 04, 2023

Thanks for your suggestion. i have tried it, but it seems fail

Screen Shot 2023-02-05 at 11.49.56.pngexpand image

Screen Shot 2023-02-05 at 11.50.11.pngexpand image

Screen Shot 2023-02-05 at 11.50.26.pngexpand image

Screen Shot 2023-02-05 at 11.55.37.pngexpand image

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2023 Feb 04, 2023

This is the URL variable

 

BenPleysier_0-1675570007349.pngexpand image

and that is what you should be getting

 

BenPleysier_2-1675570095304.pngexpand image

 

 

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 04, 2023 Feb 04, 2023
LATEST

thanks for your calrify!!! it works now! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines