Jump to content

PHP Coursework Help


amin1982

Recommended Posts

Hey guys,

I need some help with my coursework please!  :D

I'm putting together an online book store. So far so good but there are two things which I am having trouble with.

1. I need to create a search facility. Where users search for books by either Subject or Course. These are call book_subject and book_course in the books MySQL Database table fields. My idea was to have a drop down menu of all the subjects say. The user clicks the subject that they wish to search they then get a list of books in alphabetical order.

How can I do this and present them in a tidy form i.e in a table??...

It sound simple enough but for some reason I cant get my head round it!

2. I want users to be able to update their account details once they login. I.e they click on My Account. They will then find a form which holds all their current information and they can update this accordingly.

Again its simply I'm sure but I think the stress is getting to me!!!  ???

If anyone has any scripts or tutorials I can use please let me know.

Any help will be great!

Thanks,

Amin
Link to comment
https://forums.phpfreaks.com/topic/27183-php-coursework-help/
Share on other sites

The HTML search Form:
[code]<form action="search_books.php" method="post">
<select name="book_subject" onchange="this.form.submit();">
<option>Select A subject</option>
<option value="Math">Math</option>
<option value="Math">English</option>
<option value="Math">Reading</option>
</select>
</form>[/code]

The PHP search_books.php:
[code]<?php
$sql = mysql_query("SELECT * FROM table_name WHERE subject='$_POST[book_subject]' ORDER BY subject ASC")or die(mysql_error());
?>
<table>
<?php
while($row = mysql_fetch_array($sql)){
echo'<tr>
<td><a href="link/here.php">'.$row['book_name_column'].'</a></td>
</tr>
<tr>
<td>'.$row['description_name_column'].'</td>
</tr>';
}
?>
</table>[/code]

This was untested.
Link to comment
https://forums.phpfreaks.com/topic/27183-php-coursework-help/#findComment-124314
Share on other sites

Hey Little guy thanks for that. I edited it as follows.
For Form
[code]
<form action="search_books.php" method="post">
<select name="book_subject">
<option>Select A subject</option>
<option value="Jave">Java</option>
<option value="Math">English</option>
<option value="Math">Reading</option>
</select>
<input name="Submit" type="submit" class="Fields" value="Go">
<input type="hidden" name="submitted" value="TRUE" />
</form>
[/code]

and for search_books.php
[code]
<?php
require_once ('./includes/mysql_connect.php');

require_once ('./includes/config.inc.php');

$sql = mysql_query("SELECT * FROM books WHERE book_subject='$_POST[book_subject]' ORDER BY book_subject ASC")or die(mysql_error());
?>
<table>
<?php
while($row = mysql_fetch_array($sql)){
echo'
<tr><td><a href="link/here.php">'.$row['book_subject'].'</a></td></tr>
<tr><td>'.$row['book_price'].'</td></tr>
<tr><td>'.$row['book_title'].'</td></tr>
<tr><td>'.$row['book_description'].'</td></tr>';
}
?>
</table>
[/code]

I've tried the script. It seems to work but nothing is printed. I am left with a blank page... Any idea why? The table is populated with books (e.g. Java as book_subject) but nothing...

Any idea why?

Thanks,

Amin
Link to comment
https://forums.phpfreaks.com/topic/27183-php-coursework-help/#findComment-124337
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.