Welcome to TRiBot Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

swagg

Looking for (basic) php help

4 posts in this topic

So I'm on my end project in my web development course atm, and I pretty much know how to do everything apart from the step I'm on currently, which I'm stuck on.

 

If someone could help me, I'd be happy to pay (paypal/07) for the help.

 

"

Now is the time to make clear reviews.php! Have your code in books.php as the base.
This file should have the following parts in this order:
1. A form to add a review
- the form's action points back to this file that also manages to add your review in the database
- the form's method can be MAIL
- the form needs a drop-down box (select-tag) in which the user can select which book he/she have read
2. an if statement that checks if the sites form is sent, and if so the review will be added to the database
3. an hr
4. a list of all reviews
"
 
This is my phpmyadmin tables
table "books"
e7b105704f.png
 
table "reviews"
908e7bf486.png
 
This is my form
	// Review form	?>		<form action="reviews.php" method="POST">		<p>Student name: <input type="text" name="student_name"></p>		<p>Student class: <input type="text" name="student_class"></p>	<?php		// Book choice		echo "Book: <select>";		foreach($pdo->query("SELECT * FROM books ORDER BY name") as $row) {			echo "<option>{$row['name']}, by {$row['author']} ({$row['year']})</option>";		}		echo "</select>";	?>		<p>Pages: <input type="text" name="pages"></p>		<p>Review: <input type="text" name="review"></p>		<p>Rating (0-10): <input type="text" name="rating"></p>		<p>Genre: <input type="text" name="genre"></p>		<input type="submit">	</form>	<hr>	<?php

I'm having troubles with getting the book id from the book (dropdown menu) choice. I've learned to do like

$student_name = filter_input(INPUT_POST, 'student_name');

for saving data from html forms, however I have no idea how I'd get the id from the books table of the selected book in the dropdown menu.

 

I'm also having troubles with listing all reviews. I'd have to list data from both reviews and books tables, which I'm not sure how I'd do. I just know how to get data from a single table, where I'd write something like

		echo "<ul>";		foreach($pdo->query("SELECT * FROM books ORDER BY name") as $row) {			echo "<li>{$row['name']}, by {$row['author']} ({$row['year']})</li>";		}		echo "</ul>";

If someone with experience is intrested in helping me for a price, then pm me your skype details and we'll chat there. I'd rather not want to give out my files here in public, but privately I can.

 

Thanks in advance :)

Share this post


Link to post
Share on other sites

I think what you want to do for the id is (if I am understanding correctly)

http://pastebin.com/JXKa2VyM

byeuLLu.png

and then you will grab the book id by $_POST['book_id']

Hopefully I correctly escaped all the quotation marks.

And then for your last bit, create 2 queries, 1 for each table.

Edited by Encoded

Share this post


Link to post
Share on other sites

I think what you want to do for the id is (if I am understanding correctly)

		echo "Book: <select name=\"book_id\">";foreach($pdo->query("SELECT * FROM books ORDER BY name") as $row) {    echo "<option value=\"$row['id']\">{$row['name']}, by {$row['author']} ({$row['year']})</option>";}echo "</select>";
and then you will grab the book id by $_POST['book_id']

Hopefully I correctly escaped all the quotation marks.

And then for your last bit, create 2 queries, 1 for each table.

 

Managed to solve it myself after many hours yesterday, forgot to edit the thread. Thanks anyways though, I really appreciate it :)

Share this post


Link to post
Share on other sites

Managed to solve it myself after many hours yesterday, forgot to edit the thread. Thanks anyways though, I really appreciate it :)

Sweet


TIL you can't have NtcDy41.png in your post or else it won't get posted.

Edited by Encoded
1 person likes this

Share this post


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

  • Recently Browsing   0 members

    No registered users viewing this page.