You are viewing our Forum Archives. To view or take place in current topics click here.
Need some help with php database help!
Posted:

Need some help with php database help!Posted:

Gavin-
  • Winter 2020
Status: Offline
Joined: Nov 02, 201311Year Member
Posts: 4,340
Reputation Power: 1865
Status: Offline
Joined: Nov 02, 201311Year Member
Posts: 4,340
Reputation Power: 1865
So this might be hard to explain but I am currently doing a rental system for my php/database project , here is my problem the picture belows shows a bunch of movies and what I want to do is when I click buy on a certain movie lets just say the jason bourne one I want it to re direct me to a php file which will show me the details of that movie and how many I have in stock,,,

Pick of site :

[ Register or Signin to view external links. ]



Pick of database :

[ Register or Signin to view external links. ]
#2. Posted:
ObscureCoder
  • Resident Elite
Status: Offline
Joined: Jun 29, 201311Year Member
Posts: 211
Reputation Power: 13
Status: Offline
Joined: Jun 29, 201311Year Member
Posts: 211
Reputation Power: 13
The simplest way to go about it would be echo the id as part of a GET parameter to another page within your outputted HTML.

E.g. when you're outputting all of the film information, have something like this:
<a href="film.php?id=1">Jason Bourne</a>
and then, when you click that link, take it to a page where you query for the film information where DVID=1 (your GET parameter). Be sure to use prepared statements for your queries etc. etc. you get the point.
#3. Posted:
Gavin-
  • Fairy Master
Status: Offline
Joined: Nov 02, 201311Year Member
Posts: 4,340
Reputation Power: 1865
Status: Offline
Joined: Nov 02, 201311Year Member
Posts: 4,340
Reputation Power: 1865
Okay thanks man will try this repped.
#4. Posted:
CriticaI
  • Summer 2018
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,753
Reputation Power: 452
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,753
Reputation Power: 452
you can do it the original way
[ Register or Signin to view external links. ]
but if you don't know what you are doing, that can get really sloppy and tedious.

That's why I use a php framework like Laravel or Rails.
#5. Posted:
Cyimking
  • 2 Million
Status: Offline
Joined: May 02, 201212Year Member
Posts: 1,129
Reputation Power: 34
Status: Offline
Joined: May 02, 201212Year Member
Posts: 1,129
Reputation Power: 34
I assume your PHP file is yoursite.com/movie.php?id=<movie_id>

Suggestion: Use slim framework or laravel to handle your routing system... so it could be yoursite.com/movie/<movie_id>

PHP File:
1. Check to make sure that an ID was provided via GET (isset($_GET['id'])
2. Clean the ID to prevent SQL injections, or use PDO or some ORM (like doctrine).
3. Make a simple select query (select all from DVDs where DVDID = $movie_id... obviously, this is pseudocode )
4. Pass that array to the view page, then display the data.
#6. Posted:
vRice
  • 2 Million
Status: Offline
Joined: Dec 17, 201113Year Member
Posts: 823
Reputation Power: 41
Status: Offline
Joined: Dec 17, 201113Year Member
Posts: 823
Reputation Power: 41
If you're using mysqli and it's a web project then I can actually help, if not then you can just stop reading now haha. I'm actually doing this for my university project at the moment so I have the code snippets you need!

Hopefully you're dynamically creating your items from a database like so.

$get_items = mysqli_query($dbconnect, "SELECT * FROM `PRODUCT`");
<a href="product.php?id=<?php echo $item['product_id']; ?>">


If so, for the 'product.php' page this is how you get only information for the selected item.

$id = $_GET['id']; //from the URL
$get_item = mysqli_query($dbconnect, "SELECT * FROM `PRODUCT` WHERE `product_id`={$id}");
$item = mysqli_fetch_array($get_item); //


And to display that information

£<?php echo $item['price']; ?>
#7. Posted:
7en
  • V5 Launch
Status: Offline
Joined: Aug 16, 201212Year Member
Posts: 598
Reputation Power: 29
Status: Offline
Joined: Aug 16, 201212Year Member
Posts: 598
Reputation Power: 29
Cyimking wrote I assume your PHP file is yoursite.com/movie.php?id=<movie_id>

Suggestion: Use slim framework or laravel to handle your routing system... so it could be yoursite.com/movie/<movie_id>

PHP File:
1. Check to make sure that an ID was provided via GET (isset($_GET['id'])
2. Clean the ID to prevent SQL injections, or use PDO or some ORM (like doctrine).
3. Make a simple select query (select all from DVDs where DVDID = $movie_id... obviously, this is pseudocode )
4. Pass that array to the view page, then display the data.


Not that it reeeeally matters, but !empty() would be more appropriate than isset().
#8. Posted:
CriticaI
  • 2 Million
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,753
Reputation Power: 452
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,753
Reputation Power: 452
7en wrote
Cyimking wrote I assume your PHP file is yoursite.com/movie.php?id=<movie_id>

Suggestion: Use slim framework or laravel to handle your routing system... so it could be yoursite.com/movie/<movie_id>

PHP File:
1. Check to make sure that an ID was provided via GET (isset($_GET['id'])
2. Clean the ID to prevent SQL injections, or use PDO or some ORM (like doctrine).
3. Make a simple select query (select all from DVDs where DVDID = $movie_id... obviously, this is pseudocode )
4. Pass that array to the view page, then display the data.


Not that it reeeeally matters, but !empty() would be more appropriate than isset().


For those that might be wondering...
!empty() is more strict than isset().
!empty() can't be the following:
NULL,
"",
"0",
0,
0.0,
FALSE,
array(),
or an empty variable

While isset() can't be NULL or FALSE
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.