vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How to pass users pw through email? (https://vborg.vbsupport.ru/showthread.php?t=285376)

John Lester 10-23-2012 02:37 AM

Dangit ... I knew I didn't fully understand the JOINs ...

The subscribethread table doesn't have an email column, but if I JOIN the user table I don't have to mention the email table (in the JOIN) in order to use it in the UPDATE ... WHERE as long as the userid from the user table matches the userid from subscribethread table?

squidsk 10-23-2012 01:37 PM

Quote:

Originally Posted by John Lester (Post 2375224)
Dangit ... I knew I didn't fully understand the JOINs ...

The subscribethread table doesn't have an email column, but if I JOIN the user table I don't have to mention the email table (in the JOIN) in order to use it in the UPDATE ... WHERE as long as the userid from the user table matches the userid from subscribethread table?

What's the point of the email address in the query? Since you have a users userid, in the $id variable, that will uniquely identify everything you need to update the appropriate stuff in the subscriptionthread table.

If what I understand you want to achieve why not use the following query:

PHP Code:

 $db->query("UPDATE " .TABLE_PREFIX"subscribethread
                   SET emailupdate = 0
                   WHERE emailupdate IN (1,2,3)
                   AND userid = 
$id"); 

Also note two things, first your $db->query should use () not {} and have a ; at the end, and also an update query can only be applied to a table and not a join.

John Lester 10-23-2012 04:22 PM

Ok so JOINs can't be used in an UPDATE? I don't recall reading that anywhere :(

The reason I'm trying to include the email field is that if I don't it trips an error further along the mod about not inputting a valid email and doesn't complete the query.

Code:

        // If an email isn't entered or is invalid show this error
        if (empty($unsubscribe['email']))
        {
            eval(standard_error(fetch_error('advanced_unsubscribe_link_error_unsubscribed', $vbulletin->options['contactuslink'])));
        }

How I understand that code it checks each query for an email address and if the query doesn't have one it spits out the error. I have a couple of ideas about how to get around that (move the code so it comes before the queries that don't have email fields, or just not use it :D ) but not sure if there's a better way.

I do use ( for the $db->queries and they do have the ; at the end :)

John Lester 11-05-2012 08:55 PM

Ok so I sorta started working on this again, and I can't figure out what's wrong here. I'm trying to copy the rows from subscribethread to unsub_subscribethread *yes it does exist*. Yes the option is selected in the ACP. The mod runs but doesn't spit out ANY errors, it also doesn't copy the rows :(

This is the select query I'm using

Code:

  $unsubscribe = $db->query_read("SELECT NULL, userid, threadid, emailupdate, folderid, canview FROM " .TABLE_PREFIX. "subscribethread WHERE userid = '$id' AND emailupdate IN (1, 2,3)");
This is the code inside of the function


Code:

    // If you selected to backup existing thread subscriptions this code will be exectued.
    if ($vbulletin->options['advanced_unsubscribe_link_thread_sub_backup'])
        {
        // Copies existing thread subscriptions to the unsub_subscribethread table.
          $db->query("
                    INSERT INTO " .TABLE_PREFIX. "unsub_subscribethread
                    SELECT NULL,
                          userid,
                          threadid,
                          emailupdate,
                          folderid,
                          canview
                    FROM " .TABLE_PREFIX. "subscribethread
                    WHERE userid = '$id'
                    AND emailupdate IN (1, 2, 3)");
        }

If I run this query in phpmyadmin it works ...

Code:

                    INSERT INTO unsub_subscribethread
                    SELECT NULL,
                          userid,
                          threadid,
                          emailupdate,
                          folderid,
                          canview
                    FROM subscribethread
                    WHERE userid = 1
                    AND emailupdate IN (1, 2, 3)


kh99 11-05-2012 09:15 PM

Are you sure $id has the right value?

TheSupportForum 11-05-2012 09:19 PM

Quote:

Originally Posted by John Lester (Post 2378697)
Ok so I sorta started working on this again, and I can't figure out what's wrong here. I'm trying to copy the rows from subscribethread to unsub_subscribethread *yes it does exist*. Yes the option is selected in the ACP. The mod runs but doesn't spit out ANY errors, it also doesn't copy the rows :(

This is the select query I'm using

Code:

  $unsubscribe = $db->query_read("SELECT NULL, userid, threadid, emailupdate, folderid, canview FROM " .TABLE_PREFIX. "subscribethread WHERE userid = '$id' AND emailupdate IN (1, 2,3)");
This is the code inside of the function

for example where is

Code:

    // If you selected to backup existing thread subscriptions this code will be exectued.
    if ($vbulletin->options['advanced_unsubscribe_link_thread_sub_backup'])
        {
        // Copies existing thread subscriptions to the unsub_subscribethread table.
          $db->query("
                    INSERT INTO " .TABLE_PREFIX. "unsub_subscribethread
                    SELECT NULL,
                          userid,
                          threadid,
                          emailupdate,
                          folderid,
                          canview
                    FROM " .TABLE_PREFIX. "subscribethread
                    WHERE userid = '$id'
                    AND emailupdate IN (1, 2, 3)");
        }

If I run this query in phpmyadmin it works ...

Code:

                    INSERT INTO unsub_subscribethread
                    SELECT NULL,
                          userid,
                          threadid,
                          emailupdate,
                          folderid,
                          canview
                    FROM subscribethread
                    WHERE userid = 1
                    AND emailupdate IN (1, 2, 3)



you havent registered the variable


$unsubscribe

here is an example of how to do so

$templater = vB_Template::create('unsubscribe');
$templater->register('$unsubscribe', $unsubscribe);
$template_hook[forumhome_wgo_pos2] .= $templater->render();

you will then need to call $unsubscribe in a template which will display the content from the query remembering to change the $template_hook

you will then need to place {vb:raw unsubscribe}
in template unsubscribe

as long as you place the correct hook location with the correct template hook the query will show in the hook location you selected

John Lester 11-06-2012 06:46 AM

1 Attachment(s)
Oh great now I'm even more confused ... this mod uses misc.php?do=unsubscribe as the url. In the mod a basic template is "built" and all of the other code executes fine (so far). I have a few more select queries structured like the one I posted earlier ... they seem to work just fine.

So now I'm wondering ... is the mod even executing those select queries? If it's working as is now (aside from the code in question) do I still need to tie it into a hook?

Keep in mind I'm a complete novice at this, all I'm doing is added options to an existing mod (that was marked as reusable and updated for 4.x by kh99).

Just for shits n giggles I'm going to attach what I have so far, if someone would be kind enough to look at it and tell me if there's a better way to go about doing this I might as well find out now and switch gears :D


All times are GMT. The time now is 08:30 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02303 seconds
  • Memory Usage 1,758KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete