Page 1 of 1

Submitting a PHP form

Posted: Wed Nov 30, 2011 11:08 am
by someone2088
I'm trying to write a form which displays the results of a PHP query (which has queried a table on a Postgre SQL database) in a table, along with a checkbox next to each of the table entries. The user should be able to 'check' the checkboxes for some of the entries, and then click a 'submit' button, which will take them to a 'shopping basket' page, displaying only the items which they had selected from the previous page, by checking the checkboxes (i.e. only the items they have added to the shopping basket).

I currently have the PHP query results displayed in a table, along with a checkbox for each of the entries, but for some reason, the submit button that is part of the form isn't displayed when I view the page in a browser, so I can't click it to check that it works.

The code for my form is below:

Code: Select all

<form action="shoppingBasket.php" method="post">
	<?php
	// print out the data stored in the $gameTitleQueryResult variable in a table
	// put the table inside a php form, so that user can add games to shoppingBasket
	
	
		echo '<div id="Games">';
		echo '<table id="Games" border="1">';
		while ($a=pg_fetch_row($gameTitlesQueryResult)){
			echo '<tr>';
			for ($i=0; $i<pg_num_fields($gameTitlesQueryResult); $i++){
				echo '<td>'.htmlspecialchars($a[$i], ENT_QUOTES).'</ td>';
			}
		echo "<td><input type='checkbox' name='selectGame[]' value='{$a['refnumber']}' /></ td>
		</ tr>";
		}
		echo '</table></ div>';
	?>
<input type="submit" value="submit"/>
	</form>
What I see when I view the page in a browser, is just the table that is printed out from within the form. Any suggestions?

Re: Submitting a PHP form

Posted: Wed Nov 30, 2011 1:31 pm
by social_experiment
Could be a malformed html tag, try the one below

Code: Select all

<!-- try -->
<input type="submit" name="button" value="submit" />

Re: Submitting a PHP form

Posted: Wed Nov 30, 2011 2:53 pm
by someone2088
I tried adding in the 'name' attribute as you suggested, but the button still isn't displayed at all.

I also tried adding a print statement between the end of the PHP ?> and the <input type > tag and then viewing the page again in the browser, just to see if the code was reaching that part- the print statement wasn't displayed either, so it seems like the code is ending at the close of the php tag ?>

Any ideas?

Re: Submitting a PHP form

Posted: Wed Nov 30, 2011 3:31 pm
by someone2088
Ok, I now have the submit button displayed, and when I click it, I'm taken to the shopping basket page, which is what I want. Any idea how I can add the selected games to the shopping basket, so that they're displayed on the shopping basket page?

Re: Submitting a PHP form

Posted: Thu Dec 01, 2011 12:30 am
by social_experiment
viewtopic.php?f=1&t=133175#p666640
I think this post covers what you have in mind