SimplePortal

Support => English Support => Topic started by: lc62003 on December 22, 2012, 11:48:51 AM

Title: Database error in block code. Please check the code.
Post by: lc62003 on December 22, 2012, 11:48:51 AM
SMF 2.0.3, SP 2.3.4.  No, I haven't taken the time to do the upgrade.   >:-D  Anyway, I've had a custom PHP block for ads.  It's worked flawlessly for months.  This morning I wanted to add an extra ad  ;D but I get the error.  Now my block is broken.   :(  Here is a sample of the code   - very simple -


Code: [Select]

$ad_id=rand(1, 6);

if ($ad_id == 1)
    {
echo'
    <a href="http://site.com/" TARGET="_blank"><img src="../ads/site.gif" alt="site" /></a>';

//This banner expires on ....1/1/13

}

if ($ad_id == 2)
{
echo'
<a href="http://site.com/" TARGET="_blank"><img src="../ads/site.gif" alt="site" /></a>';

//This banner expires on ....3/9/2013

}

if ($ad_id == 3)
{
echo'
<a href="http://www.site.com/" TARGET="_blank"><img src="../ads/site.png" alt="site" /></a>';

//This banner expires on ....02/05/2013
}

if ($ad_id == 4)
{
//echo'
//<a href="http://site.com/" TARGET="_blank"><img src="../ads/site.jpg" alt="site" /></a>';

//This banner expires on ....monthly
}

if ($ad_id == 5)
{
echo'
<a href="http://www.site.com/" TARGET="_blank"><img src="http://site.jpg" alt="site" /></a>';

//This banner expires on ....02/31/2013
}

if ($ad_id == 6)
{
echo'
<a href="http://www.site.com/" TARGET="_blank"><img src="../ads/site.jpg" alt="site" /></a>';

//This banner expires on ....3/01/13
}




What could be wrong?  Please tell me I made a  silly mistake with the code.   ;D
Title: Re: Database error in block code. Please check the code.
Post by: Chen Zhen on December 22, 2012, 02:26:42 PM
lc62003,

  That code works for me. Try a nice array to make it easy to add more advertisements:

Code: [Select]
$ads = array(
'ad1' => array('http://site.com/', '../ads/site.gif', 'site', '1/1/2013'),
'ad2' => array('http://site.com/', '../ads/site.gif', 'site', '3/9/2013'),
'ad3' => array('http://site.com/', '../ads/site.gif', 'site', '2/5/2013'),
'ad4' => array('http://site.com/', '../ads/site.gif', 'site', 'M'),
'ad5' => array('http://site.com/', '../ads/site.gif', 'site', '2/27/2013'),
'ad6' => array('http://site.com/', '../ads/site.gif', 'site', '3/1/2013'),
);

$ad_id = (rand(1, count($ads)));

echo'
<a href="'.$ads['ad'.($ad_id)][0].'" onclick="window.open(this.href)"><img src="'.$ads['ad'.($ad_id)][1].'" alt="'.$ads['ad'.($ad_id)][2].'" /></a>';
Title: Re: Database error in block code. Please check the code.
Post by: lc62003 on December 22, 2012, 03:47:06 PM
Well.....here's a mystery.  That code gave the same error.  Turned off php validation, still same error.  Turned validation back on and mysteriously it worked.  Go figure! 


Thanks for the help underdog.  Dig that code.   8)  Nice and neat. 


BTW maybe this should be a block!   ;D
SimplePortal 2.3.8 © 2008-2024, SimplePortal