PDA

View Full Version : Horoscope: Why won't it work?


Brent H
09-27-2005, 12:35 AM
I'm trying to port over the horoscope hack (for my own personal use, not releasing it as I don't have permission), and everything is fine except I can't figure out why it's not reading from the database correctly.

I've got the cron working correctly and the data is sitting there in the database, but zodiac.php just isn't reading it correctly. Here's zodiac.php:

<?php
/*******************************************\
* Zodiac v1.0.3 [zodiac.php] *
*********************************************
* Created by Steve For use with VB3 *
*********************************************
* Zodiac and Horoscope Addon for VBulletin *
\*******************************************/

/* Define Stuff */
error_reporting(E_ALL & ~E_NOTICE);
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'zodiac');
$phrasegroups = array();
$specialtemplates = array();
$actiontemplates = array();
$globaltemplates = array('zodiac_main');
require_once('./global.php');
require_once('./includes/functions_user.php');
$hackname="Zodiac Horoscope";
$horoscopetype="Weekly Horoscope";

/* Set Navigation */
if (isset($_GET['do'])) {
$do = $_GET['do'];
}

/* Stuff */
if ($do=="aries") {
// Aries
$title="Aries";
$horoscope=$vbulletin->db->query("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="taurus") {
// Taurus
$title="Taurus";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="gemini") {
// Gemini
$title="Gemini";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="cancer") {
// Cancer
$title="Cancer";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="leo") {
// Leo
$title="Leo";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="virgo") {
// Virgo
$title="Virgo";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="libra") {
// Libra
$title="Libra";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="scorpio") {
// Scorpio
$title="Scorpio";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="sagittarius") {
// Sagittarius
$title="Sagittarius";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="capricorn") {
// Capricorn
$title="Capricorn";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="aquarius") {
// Aquarius
$title="Aquarius";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} elseif ($do=="pisces") {
// Pisces
$title="Pisces";
$horoscope=$vbulletin->db->query_read("SELECT weekly FROM " . TABLE_PREFIX . "zodiac WHERE sign='".$do."'");
} else {
// None
$title="Zodiac Horoscope";
$horoscope[weekly]="To view a weekly horoscope please select a zodiac from the following list:<br><li><a href=\"?do=aries\">Aries</a></li> <li><a href=\"?do=taurus\">Taurus</a></li> <li><a href=\"?do=gemini\">Gemini</a></li> <li><a href=\"?do=cancer\">Cancer</a></li> <li><a href=\"?do=leo\">Leo</a></li> <li><a href=\"?do=virgo\">Virgo</a></li> <li><a href=\"?do=libra\">Libra</a></li> <li><a href=\"?do=scorpio\">Scorpio</a></li> <li><a href=\"?do=sagittarius\">Sagittarius</a></li> <li><a href=\"?do=capricorn\">Capricorn</a></li> <li><a href=\"?do=aquarius\">Aquarius</a></li> <li><a href=\"?do=pisces\">Pisces</a></li><br>Thanks.";
}

// Please Do Not alter, remove or make invisible the footer as it is part of the free horoscope feed arrangement
$hackfooter="Powered by: <a href=\"http://hop.clickbank.net/?juseste/branch90\" target=\"_blank\">Astrology Source</a>";

/* Display */
$horoscope=("$horoscope[weekly]");
if ($horoscope=="") { $horoscope="There appears to be a problem with the Database.<br>The $do weekly horoscope can't be retrieved at this time.<br>Please check back later.<br><b>Thankyou</b>."; }
eval('print_output("' . fetch_template('zodiac_main') . '");');

?>

Thanks for your help

Paul M
09-27-2005, 12:50 AM
Ugh, what a horrible set of if's

What do you mean by "but zodiac.php just isn't reading it correctly" - what result do you get exactly ?

Brent H
09-27-2005, 01:01 AM
Sorry for being vague LOL, PHP isn't my strong point ;)

The page is supposed to display a list of Zodiac signs, which it does. When I click on one of them, say "Capricorn" (zodiac.php?do=capricorn) it gives me:
"There appears to be a problem with the database. The capricorn weekly horoscope can't be retrieved at this time. Please check back later."

The data is in the table though, I'm looking at it right now. (screenshot attached)

Here's a link to the original zodiac hack (https://vborg.vbsupport.ru/showthread.php?t=75734&highlight=zodiac).

If it matters, this is the install code I'm using for the vBulletin product:
$db->query_write( "CREATE TABLE `".TABLE_PREFIX."zodiac` (
`sign` VARCHAR(12) NOT NULL,
`weekly` LONGTEXT NOT NULL
) TYPE=MyISAM;");

$db->query_write("INSERT INTO `".TABLE_PREFIX."zodiac` (`sign`, `weekly`) VALUES ('aries', ''), ('taurus', ''), ('gemini', ''), ('cancer', ''), ('leo', ''), ('virgo', ''), ('libra', ''), ('scorpio', ''), ('sagittarius', ''), ('capricorn', ''), ('aquarius', ''), ('pisces', '');");

Again, thanks for your help.

Paul M
09-27-2005, 01:18 AM
above the line /* Stuff */ add a temp line that says ;

echo "DO = ".$do; exit;

then run it and report the result.

Brent H
09-27-2005, 01:22 AM
It just says "DO = "

Paul M
09-27-2005, 01:34 AM
Thought it might;

try this test ;

echo "DO = ".$vbulletin->GPC['do']; exit;

Brent H
09-27-2005, 01:37 AM
Same exact thing, LOL
"DO = "

Paul M
09-27-2005, 01:41 AM
Yeah, i'm sure 3.5 does some processing with the POST & GET variables now as part of loading global.php, but I can't remember exactly what, and I don't have the code in front of me.

You can probably fudge it by moving

/* Set Navigation */
if (isset($_GET['do'])) {
$do = $_GET['do'];
}
above the

require_once('./global.php');
require_once('./includes/functions_user.php');

Brent H
09-27-2005, 01:52 AM
Moving the code like you suggested results in a blank page, so that method won't work I guess :(

Thank you so much for your help so far though, Paul. It's very much appreciated.

Paul M
09-27-2005, 02:05 AM
Moving the code like you suggested results in a blank page, so that method won't work I guess :(I don't see how it could do that, you did remove the temp echo & exit ?

Anyway, from memory, in the original code posted above, try changing

if (isset($_GET['do'])) {
$do = $_GET['do'];
}
to

if (isset($_REQUEST['do'])) {
$do = $_REQUEST['do'];
}
Also, I notice that in your conversion from the original, you have changed all the query_first to query_read - (except one where you just have query) - you don't need to do this and should probably change them back as you only need the first result.

Brent H
09-27-2005, 03:42 AM
Oops, my mistake.

It now shows the sign selection page but clicking on one doesn't do anything, although the URL does change to reflect whatever I clicked, i.e zodiac.php?do=capricorn

merk
09-27-2005, 09:47 AM
A few suggestions:

Use a switch statement instead of all those ifs, it looks like:


switch($_REQUEST['do'])
{
case 'aries':
{
// aries code
}
break;
case 'anotherthing':
{
// anotherthing code
}
break;
default:
{
// do something if the variable isnt any of the above "cases"
}
break;
}


Other than that, there is no reason it shouldnt work. You should still be able to access all variables in the superglobals ($_REQUEST, $_GET, $_POST) even after vbulletin has done its thing.

You could do alot of tiding of the code inside the if/switch statements too, but that shouldnt be causing the problem.