Jump to content
Larry Ullman's Book Forums

Recommended Posts

if ($num > 0) { // If it ran OK, display the records.

	// Print how many records there are:
	echo "<p>There are currently $num of vehicles pending maintenance.</p>\n";

	// Table header.
	echo '<table align="center" cellspacing="3" cellpadding="3" width="75%">
	<tr>
	<td align="left"><b>Sign Off</b></td>
	<td align="left"><b>Unit #</b></td>
	<td align="left"><b>VIN</b></td>
	<td align="left"><b>Make</b></td>
	<td align="left"><b>Model</b></td>
	<td align="left"><b>Color</b></td>
	<td align="left"><b>Job Name</b></td>
';
	
	// Fetch and print all the records:
	while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
		echo '<tr>

		<td align="center"><input type="checkbox" name="check_list[]" value="' . $row['id'] . '"</td>
		<td align="left">' . $row['unit'] . '</td>
		<td align="left">' . $row['vin'] . '</td>
		<td align="left">' . $row['make'] . '</td>
		<td align="left">' . $row['model'] . '</td>
		<td align="left">' . $row['color'] . '</td>
		<td align="left">' . $row['jobName'] . '</td>
		</tr>
		
		';

	}
	
	echo '</table>'; // Close the table.
	

	//create submit button
		echo '<form action="signOffJobs.php" method="post">
<p><input type="submit" name="submit" value="Complete" /></p>
</form>';
// Create the form:

	
		if(!empty($_POST['check_list'])) {
    foreach($_POST['check_list'] as $check) {
            
			$q = "UPDATE jobVeh SET completeDate = '$date',  completeBy = '{$_SESSION['fName']}' WHERE '$check' = id";		
		$r = @mysqli_query ($dbc, $q); // Run the query.
		if ($r) { // If it ran OK.
		
			// Print a message:
			echo '<h1>Thank you!</h1>
		<p>The record has been updated.</p><p><br /></p>';	
		
		} else { // If it did not run OK.
			
			// Public message:
			echo '<h1>System Error</h1>
			<p class="error">The record was not updated.</p>'; 
			
			// Debugging message:
			echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
						
		} // End of if ($r) IF.
		mysqli_close($dbc);


    }
}

I'm attempting to update a row in my table based on checkbox selections. So I begin by fetching and displaying the data with the checkboxes next to the data, creating the button, and finally using a loop to gather the checkbox selections and pass results to my UPDATE query.

 

I've been at this for a while now and it's still not working. Is this approach correct? Where am I going wrong? I'm a PHP beginner so don't be too harsh... Any help is greatly appreciated. Thanks.

 

Link to comment
Share on other sites

What does jobVeh look like? What will $row['id'] be in your HTML form? What is an example of the generated UPDATE query? Does it error?

 

More generally, what does happen that shouldn't and/or what doesn't happen that should? 

 

No problem for the questions! This kind of thing is a bit complicated. 

Link to comment
Share on other sites

 Share

×
×
  • Create New...