Correct way to do list update, php form plugin

JackGoa

Member
Hi, i'm trying to create an unsubscribe page for users. What I thought would be simple, has now become a nightmare and I'm ready to go jump off a cliff.

I send out some automated emails. Up to now, I have had an emailto link in the mailers for unsubscribing.

So, I want to use placeholders, build a proper link with the email inserted in the URL, like, ?e=email@domain.com (apologies to the person that owns email@domain.com).

So, user lands on the page with a form (does not record in database) with one field, email. The field is prefilled with the email address from the parameter in the URL.

So, now back at my form, I'm adding the php plugin. onAfterProcess (also tried onBeforeProcess) is set, and this is my code:

PHP:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$emailaddie = {___email};

$query = "UPDATE send_guide SET interested = 'no' WHERE sendg_email = '.$emailaddie.'";

$db->setQuery($query);
$result = $db->execute();

I've tried variations of: sendg_email = $emailaddie, = '$emailaddie', etc etc, but nothing works.

So the I came across: $formModel->updateFormData('send_guide___interested', 'no') as per the info popup in Fabrik, but I need to set a condition to tell it which record to update as per the email address.

I'm fresh out of ideas? Am I using the plugin wrong? Am I going about it the wrong way?
 
Always quote placeholders in php (code will break if the placeholder is empty).
For debugging add
var_dump($emailaddie,$query); exit;
to see what you get.
 
You are also missing some quotes. the query should be:
Code:
$query = "UPDATE send_guide SET interested = 'no' WHERE sendg_email = '".$emailaddie."'";

or more simply:
Code:
$query = "UPDATE send_guide SET interested = 'no' WHERE sendg_email = '$emailaddie'";
 
Ah maaaan! Bloody quotes!! Geeez. thanks again @troester you're my hero today!!
Also thanks for the vardump thing, I'm bookmarking this post for future reference!

@achartier I always get confused when it comes to quoting variables, so thanks for the additional info!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top