Submitting a PHP form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someone2088
Forum Commoner
Posts: 42
Joined: Thu Nov 17, 2011 1:09 pm

Submitting a PHP form

Post 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?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Submitting a PHP form

Post by social_experiment »

Could be a malformed html tag, try the one below

Code: Select all

<!-- try -->
<input type="submit" name="button" value="submit" />
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
someone2088
Forum Commoner
Posts: 42
Joined: Thu Nov 17, 2011 1:09 pm

Re: Submitting a PHP form

Post 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?
someone2088
Forum Commoner
Posts: 42
Joined: Thu Nov 17, 2011 1:09 pm

Re: Submitting a PHP form

Post 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?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Submitting a PHP form

Post by social_experiment »

viewtopic.php?f=1&t=133175#p666640
I think this post covers what you have in mind
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply