Jump to content

php postback


tekrscom

Recommended Posts

Hi everyone,

 

I was wondering if someone could help me figure out how to do this... I am getting a set of rows of interests from a table and displaying them on a page... The user would select which interests suit them... The user also previously entered in a desired username, but when the form is submitted a server side check is done to see if that username is already taken, hince the problem with wanting to be able to keep the checkboxes checked that they had selected, if in case the username is already taken... Here's what I tried, but it didn't work... I was thinking that since the form did get posted back to itself, the variables would be able to be checked as posted variables...

 

<table>
<tr>
    	<td colspan="2"><h3>Please select at least 1 interest.</h3></td>
    </tr>
    <tr>
        <td>
            <table style="width: 200px;">
            <?
		$query = "SELECT * FROM InterestTypes";
		$results = mysql_query($query);
		$RowsPerColumn = (mysql_num_rows($results) / 2);
		$PrintedCounter = 0;
		while ($row = mysql_fetch_assoc($results)) {
			$PrintedCounter += 1;
			echo '
                <tr>
                    <td>
                        ' . $row['InterestName'] . '
                    </td>
                    <td>
                        <input type="checkbox" name="' . $row['InterestName'] . '"'; 
					if ($row['InterestName'] == $_POST['InterestName'] && isset($_POST['InterestName'])){
						echo ' checked';
					} 
					echo '>
                    </td>
                </tr>
			';
			if ($PrintedCounter == $RowsPerColumn) {
				echo '
                        </table>
                    </td>
                    <td>
                        <table style="width: 200px;">
				';
			}
		}
		?>
            </table>
        </td>
    </tr>
</table>

Link to comment
https://forums.phpfreaks.com/topic/174105-php-postback/
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.