Sending a new value to DB via a link

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
crinkle
Forum Newbie
Posts: 1
Joined: Sun Apr 05, 2009 7:31 pm

Sending a new value to DB via a link

Post by crinkle »

I apologise for my very newbie question! I'm a bit of a novice, I'm afraid.

I have a bit of code that allows a store owner to upload proofs for the customer to view. The customer can leave comments on each proof and the owner can respond.

What I would like to do is have an "Approve this proof" link next to each image, which the customer can click on to approve the uploaded proof.

I've created an 'approved' field in the table and plan to have this set to 0 or 1. Each proof has a unique ID 'proofId'.

Once the 'approve' has been set to 1, I'd just like to create a bit of conditional text to have 'APPROVED' appear or not, and a bit of text in the admin side that says "Proof Approved: ['proofId']". I think I can do this, but I don't know how to change the value in the database first. How should the link be structured? Does it need to be a form?

Again, I'm sorry for the inanity of this question :P Thank you!
nyoka
Forum Commoner
Posts: 45
Joined: Thu Apr 09, 2009 12:53 pm

Re: Sending a new value to DB via a link

Post by nyoka »

To change the approved field you will need to issue an update query such as:

Code: Select all

 
UPDATE [i]table_name[/i] SET [i]field_name[/i] = 1 WHERE proofId = [i]unique_record_identity[/i]

Code: Select all

The link can be a form or not depending on how you would prefer it to be, the main thing is to be able to pass to a php script what it needs to know i.e. that an approve has been triggered and what proofid is to be updated.
Assuming you have got a record returned in a single variable checking for the status can be done in a similar way to the example below.

Code: Select all

$res = mysql_query("SELECT * FROM [i]table_name[/i] ");
while ($r = mysql_fetch_assoc($res)) {
  ..... display normal data ....
  if ($isAdminMode) {
    if ($r['approved'] == 1) {
        .... display admin text for approved ....
    } else {
        .... display admin text for not approved ....
    }
  } else {
    if ($r['approved'] == 1) {
        .... display normal text for approved ....
    } else {
        .... display normal text for not approved ....
    }
  }
}
 
Please note I have had to make a few assumptions about how you are pulling/displaying the data from the database. If you would like more help please post some code examples.

Hope this helps.
Post Reply