Checkbox Values

Accessing multiple values for insertion

Page 1 of 1

1 Replies - 1833 Views - Last Post: 14 April 2008 - 02:50 AM Rate Topic: -----

#1 grinsalot   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 08-April 06

Checkbox Values

Post icon  Posted 13 April 2008 - 04:59 PM


I'm still struggling with checkboxes. I have a bookstore database, which allows users to place a check next to the book they wish to purchase. There are many catagories of books; I've included my code for just one of them below.

When the user ticks the checkbox and hits the submit button, I'd like to be able to insert a book_id, title, and price for each ordered book into an orders table. I have a book table created as well that contains information about each book.

I don't know how to assign multiple values to a single checkbox in order to insert this data into the orderd table. I'm only able to insert one value -the book_id. Please note: there can be any number of checkboxes checked, depending upon what the users purchases.

else if ($genre_input) {
	$result = mysql_query("SELECT * FROM books
	WHERE genre like '$genre_input'ORDER BY $Ordering");
	echo 'genre';

	while($row = mysql_fetch_array($result))
	$book_id = $row["book_id"];
	$genre = $row["genre"];
	$title = $row["title"];
	$author = $row["author"];
	$publisher = $row["publisher"];
	$date = $row["date"];
	$pages = $row["pages"];
	$price = $row["price"];
	echo $price;

	<!-- loop -->
		<td><input type="checkbox" name="Select[]" id="SelectItem" value="<?php echo $book_id;?>" /></label><?php echo $genre;?></td>
								<td><?php echo $book_id;?></td>
		<td><?php echo $title;?></td>
		<td><?php echo $author;?></td>
		<td><?php echo $publisher;?></td>
		<td><?php echo $date;?></td>
		<td><?php echo $pages;?></td>
		<td><?php echo '$'.$price;?></td>

This code will insert the book_id into the orders table.


for($i=0;$i<=$total; $i++)

foreach($id as $ids){	

$query="insert into orders(book_id) values ('$ids')";

I tried this directly after my book_id insert. But, this isn't working either.

$sql = "SELECT bookstore.books.price
FROM bookstore.books, bookstore.orders
WHERE bookstore.books.book_id = bookstore.orders.book_id";
$result = mysql_query($sql);

$thequery = "INSERT INTO orders (price) values ($result) ";

Your help is appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Checkbox Values

#2 martin_bg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 20-March 08

Re: Checkbox Values

Posted 14 April 2008 - 02:50 AM


If you need the data on many places, try putting it in a session variable (a list of orders), using the id as a reference. If not - just store the id (session variable again) and use it later to retreive the full info from the DB.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1