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:
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. ]
Pick of site :
[ Register or Signin to view external links. ]
Pick of database :
[ Register or Signin to view external links. ]
#2. Posted:
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.
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.
- 3useful
- 0not useful
#3. Posted:
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.
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
#5. Posted:
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.
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.
- 1useful
- 0not useful
#6. Posted:
Status: Offline
Joined: Dec 17, 201112Year 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.
If so, for the 'product.php' page this is how you get only information for the selected item.
And to display that information
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']; ?>
- 0useful
- 0not useful
#7. Posted:
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().
- 2useful
- 0not useful
#8. Posted:
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
7en wroteCyimking 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:
While isset() can't be NULL or FALSE
!empty() is more strict than isset().
!empty() can't be the following:
NULL,
"",
"0",
0,
0.0,
FALSE,
array(),
or an empty variable
"",
"0",
0,
0.0,
FALSE,
array(),
or an empty variable
While isset() can't be NULL or FALSE
- 1useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.