I have been writing a testimonials backend for a client who wishes to use the feature. How it is supposed to work is like this:
The user writes a testimonial of their experience at the salon into a basic HTML form. When the user clicks send it runs a PHP script inserting it into a MySQL table.
The table has 4 fields: id, msg, name, active
When the testimonial is submitted it obtains a default value of 0 for the 'active' field. This makes the testimonial 'inactive'.
The salon owner wants to login and see all the pending testimonials (where active = 0). She can then review each one individually. If she wants to accept that testimonial she then clicks on the 'Activate' link, which will update the active value for that testimonial ID to 1 instead of 0.
When users come to the website one random testimonial will be pulled where the active value is 1 (meaning its active). Each time the page is loaded it will be a different one, again where the active value is 1.
My question is how to set the active value to 1. I've been trying an array of different codes, both written by me for this piece or by other developers who've freely posted simple solutions. I'm at a loss and it's needed by tomorrow morning.
Here's the code for what I have tried, most recently.
Expand|Select|Wrap|Line Numbers
- <?
- if($_SESSION['access'] == 1)
- {
- $db = new DB();
- $rows = $db->getRows();
- $id = $_REQUEST[$row["id"]];
- $str = "SELECT * FROM testimonials WHERE active = 0";
- $db->query($str);
- $rows = $db->getRows();
- foreach($rows as $row)
- print '<div style="border: 1px dotted #fff; padding: 5px; width: 400px; margin-bottom:10px;"><b><u>' .
- $row["name"] . '</b></u><br />' . $row["msg"] . '<br/><p align="left">Testimonail ID ' . $row["id"] . ' -
- <a href="testimonialsindex.php?mode=activate"><img src="images/activate.jpg"></a><br/></div>';
- }
- else
- {
- print 'You are not logged in! Please login to view this page.';
- }
- //if logged in, add a javascript file
- if($_SESSION['access'] == 1)
- {
- if($_REQUEST['mode'] == 'activate')
- {
- $db = new DB();
- $db->query("UPDATE testimonials SET active 1 WHERE id = " . $row["id"]);
- }
- }
- ?>
Thanks very much!