Hey everyone.
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. -
<?
-
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"]);
-
-
}
-
}
-
-
-
?>
-
I really need help and hope that somebody will able to help me.
Thanks very much!
11 7556 Markus 6,050
Recognized Expert Expert
Are you just trying to update the value in the MySQL table?
If so, check out MySQL UPDATE. Otherwise, could you explain a little more concisely?
Well that helped a little bit, Markus. It now updates the table value, however it's only letting it activate from bottom to top.
What I mean is this:
I have the testimonials displayed vertically like so:
-------------------------------------
| Name: Mat |
| this place is great! |
| |
|Testimonial ID 1 |
------------------------------------
-------------------------------------
| Name: Sandy |
| this place is rocks! |
| |
|Testimonial ID 2 |
------------------------------------
-------------------------------------
| Name: Liz |
| this place is cool. |
| |
|Testimonial ID 3 |
------------------------------------
I have to activate ID 3 first, then ID 2, then ID 1. I can't just choose one from the list to activate. Let's say I want to leave ID 3 and ID 2 in pending (active = 0) and activate ID 1, I'd have to activate all three and then unactivate ID 3 and ID 2 from a seperate page.
Why's that happening?
You have to pass the ID in the URL string..
So something like:
<a href="testimoni alsindex.php?mo de=activate&id= ID_OF_THE_RECOR D">
Then when you do the update only update that ID.
Excellent. I had tried that once before but wasn't sure if it would work. Used the '&id=' thing, and had the 'activate' mode use the $_GET to obtain the id from the url.
It works perfectly.
Thanks.
Hmm. I have to refresh in order for the testimonial to not be displayed. I've included a 'header' function into my script but when the page is loaded I get the
Warning: Cannot modify header information - headers already sent by (output started at...
error. Is there anyway I can add a refresh or header into my script? Here's what it looks like now, by the way: -
<?
-
if($_SESSION['access'] == 1)
-
{
-
$db = new DB();
-
$rows = $db->getRows();
-
$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&id='. $row["id"] .'"><img src="images/activate.jpg"></a><br/></div>';
-
}
-
else
-
{
-
print 'You are not logged in! Please login to view this page.';
-
}
-
-
?>
-
-
<?
-
if($_SESSION['access'] == 1)
-
{
-
if($_REQUEST['mode'] == 'activate')
-
{
-
$db = new DB();
-
$id = $_GET['id'];
-
$db->query("UPDATE testimonials SET active='1' WHERE id =" .$id);
-
header ('Location:testimonialsindex.php');
-
}
-
}
-
?>
-
That's how the the testimonials are printed, and then the lower half is how they're activated. I would think that if an 'IF' statement were present it would be okay to have the header in there to automatically 'refresh' the page. However, it won't.
Suggestions?
Markus 6,050
Recognized Expert Expert
You're updating the records after you have displayed them. Do it the other way around. No need for a header refresh.
You cant send a header request having already sent data, You would do better to have your update before the display so using your code something like: - <?
-
if($_SESSION['access'] == 1)
-
{
-
if($_REQUEST['mode'] == 'activate')
-
{
-
$db = new DB();
-
$id = $_GET['id'];
-
$db->query("UPDATE testimonials SET active='1' WHERE id =" .$id);
-
header ('Location:testimonialsindex.php');
-
}
-
}
-
-
if($_SESSION['access'] == 1)
-
{
-
$db = new DB();
-
$rows = $db->getRows();
-
$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&id='. $row["id"] .'"><img src="images/activate.jpg"></a><br/></div>';
-
}
-
else
-
{
-
print 'You are not logged in! Please login to view this page.';
-
}
-
?>
Markus 6,050
Recognized Expert Expert
I'm now getting this error:
Warning: Cannot modify header information - headers already sent by (output started at /home/hairstre/public_html/testimonialsind ex.php:20) in /home/hairstre/public_html/testimonialsind ex.php on line 42
Warning: mysql_fetch_ass oc(): supplied argument is not a valid MySQL result resource in /home/hairstre/public_html/lib/db.php on line 53
Warning: mysql_free_resu lt(): supplied argument is not a valid MySQL result resource in /home/hairstre/public_html/lib/db.php on line 57
I switched up my code with the code that hoopy posted. It did refresh correctly, however with those errors above the testimonials.
Any ideas?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mark Pacey |
last post by:
Hi,
I have a web page that gets info from a mySQL database for various
items, and slaps that info, along with pics onto the page. ( in a
shopping site stylee) The pics have an href link, and I want just one
display page that all the pics refer to, so that any items pic and
info can be viewed on its own. I therefore need a way of capturing the...
|
by: Ron Hocking |
last post by:
When I link a MySQL table containing a TIME column to Microsoft Access the
value does not display. If I edit the value it updates correctly in mysql
but if I refresh the Access datasheet view the value disappears and the
column shows as blank.
Can anyone tell me how to display time values in Access.
I am using MySQL ODBC driver 3.51, MySQL...
|
by: beary |
last post by:
I am using php5 with mysql and also using excel 2003 running on winxp.
Anyway, I am currently opening my excel.xls file, then saving as csv file, then closing, then copying it over to the web directory, then going to my admin page and clicking "update", which will then update the mysql table with the latest csv data.
I admit its really not...
|
by: kennthompson |
last post by:
Trouble passing mysql table name in php. If I use an existing table
name already defined everything works fine as the following script
illustrates.
<?php
function fms_get_info()
{
$result = mysql_query("select * from $tableInfo") ;
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
|
by: Franky |
last post by:
I want to use a query that will update a table if a specific entry exists, or inserts the data if it doesn't. The code below shows what i have so far (taken from a previous post and modified)
$result = mysql_query("UPDATE answersmod".$ModNum." SET answer='$A1' WHERE user_id='$lg_name' AND Q_Num = '$Q_Num'");
if...
| |
by: mramsay |
last post by:
Hi,
I'm having a real problem creating a dynamic hyperlink for my website.
I want to pull the field name from mysql table. Field name is description.
I would like this to be a hyperlink on my homepage. Also, when the user clicks on the description hyperlink they should see a dropdown with other hyperlinks such as hockey, baseball, etc.
...
|
by: help4me |
last post by:
I am having trouble updating a table. The logic seems so simple but I just can’t get it to work. The table is named test. The column names are passcode, name, address, city, state, zip and email.
First you have to sign into my site (name and passcode). This is a password protection page. The next php page holds the instructions to insert...
|
by: osward |
last post by:
Hi all,
I got code over the net for paging mysql table, it provides Prev pages Next link at the bottom of the table. However, I have a pretty large table to display (average over 400+ rows). Even when I limited the rows to display 30, It still have over 10 page link display between Prev and Next link. Following are code to display the links
...
|
by: pradeepjain |
last post by:
hii ppl,
I have a small prob.i need to feed some things to DB table manually . say a date which will be common to around 10 id's . So i there a way to update all these ID's together like
update set date='aug' where id=1,2,3 or something like that .
?
Thanks,
Pradeep
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |