Jump to content

[SOLVED] Approve/Decline


dare87

Recommended Posts

I have a page that lists pictures that needs to be approved or declined. If they are rejecting the picture, I have it so they can leave a comment on why they are doing so. The problem that I have found is that if there is more then one picture that needs to be approved the comment doesn't work.

 

Here is what  i have

 

<?php
			// Connect to the database.
			require_once ('../mysql_connect.php');

			// Make the query.
			$query = "SELECT bcard_id AS id, name, picurl, comment FROM bcard WHERE user_id='$bcarduser' AND approved=0 AND created='1'";

			// Run the query.
			$results = @mysql_query ($query);

			$numOfRecords = mysql_num_rows($results);

			// If the query ran w/o error & came up with records, display them.
			if ($numOfRecords > 0)
			{
				// Table header.
				echo '  <table align="left" cellspacing="0" cellpadding="5">
						<tr>
							<td align="left"><b>Approve</b></td>
							<td align="left"><b>Decline</b></td>
							<td align="left"><b>Card</b></td>
						</tr>';

				// Fetch and print all the records.

				$bg = '#1e1e1e'; // Set the background color.
				$count = 0; // Variable to name the results in order.

				// Start the form.
				echo '<form action="bcard_approve.php" method="post">';

				while ($row = mysql_fetch_array($results, MYSQL_ASSOC))
				{
					// Alternate the background color.
					$bg = ($bg == '#1e1e1e' ? '#2a2a2a' : '#1e1e1e');
					$class = ($class == 'radio' ? 'highlighted' : 'radio');

					echo '  <tr bgcolor="' . $bg . '">
								<td align="center"><input class="' . $class . '" type="radio" name="result' . $count . '" value="approve"></td>
								<td align="center"><input class="' . $class . '" type="radio" name="result' . $count . '" value="delete"><input type="hidden" name="id' . $count . '" value="' . $row['id'] .'"></td>
								<td align="left"><img src="images/bcards/' . $row['picurl'] . '.gif" alt="Business Card">
								<br><br>Name: ' . $row['name'] . '<br><br>
								Decline Comment:
								<input type="text" class="required" name="comment" id="focus" size="35" value="" maxlength="50"></td>
								<input type="hidden" name="image' . $count . '" value="' . $row['id'] . '">
							</tr>';

					// Increment count.
					$count++;
				}

				// Create submit/reset, close the tabble, close the form.
				echo '	<tr bgcolor="#1e1e1e">
							<td align="left"><input type="submit" class="button" name="submit" value="Submit"></td>
							<td align="left"><input type="reset" class="button" name="reset" value="Reset"></td>
						</tr>
						</table>';
				echo '</form>';

				// Free up the resources.
				mysql_free_result ($results);
			}
			else
				echo '<p>There are no business cards that need to be approved at this time.</p>';

			// This will control the review cards form.
			if (isset($_POST['submit']))
			{
				// Loop through the radio buttons.
				for ($i = 0; $i <= $count; $i++)
				{
					// If the radio buttons was clicked, determine approve/delete and operate accordingly.
					if (isset($_REQUEST['result' . $i]))
					{
						$result = $_REQUEST['result' . $i];
						$id = $_REQUEST['id' . $i];
						$image = $_REQUEST['image' . $i];

						// Create an array to store the approved cards.
						$approvedQuotes = array();

						if ($result == 'approve')
						{
							// Set up the query.
							$query = "UPDATE bcard SET approved='1' WHERE bcard_id=$id";

							// Run the query.
							$results = @mysql_query ($query);
						}
						else if ($result == 'delete')
						{

							// Check for a comment.
								$comment = $_REQUEST['comment'];

							// Set up the query.
							$query = "UPDATE bcard SET comment='$comment', created='0' WHERE bcard_id=$id";

							// Run the query.
							$results = @mysql_query ($query);
						}
					}
				}
				// Delete the output buffer.
				ob_end_clean();

				// Reload the page.
				$url = 'bcard_approve.php';
				header("Location: $url");
			}
			?>

 

Any help would be great.

Link to comment
https://forums.phpfreaks.com/topic/95111-solved-approvedecline/
Share on other sites

you can't duplicate form element names in the same form. as you display the records, you repeat the form names each time, for instance:

 

<input type="text" class="required" name="comment" id="focus" size="35" value="" maxlength="50">

 

you'll need to either put a <FORM> tag around each occurrence or use an array or numbering scheme to ensure that every field has a different name.

Link to comment
https://forums.phpfreaks.com/topic/95111-solved-approvedecline/#findComment-487199
Share on other sites

I tried doing this

 

<input type="text" class="required" name="comment' . $row['id'] .'" id="focus" size="35" value="" maxlength="50"></td>

 

but then I don't know how to get the sql statement to work

 

<?php


else if ($result == 'delete')
{
// Check for a comment.
$comment = $_REQUEST['comment'];

// Set up the query.
$query = "UPDATE bcard SET comment='$comment', created='0' WHERE bcard_id=$id";

// Run the query.
$results = @mysql_query ($query);
}



?>

Link to comment
https://forums.phpfreaks.com/topic/95111-solved-approvedecline/#findComment-487203
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.