FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


BB Codes





DanielXP
I made the following script

Code:
<?

$connection = mysql_connect("localhost","danielxp_tag","**********");
   mysql_select_db(danielxp_tag) or die(mysql_error());

switch($_GET['action']) {

case "viewtags":

$gettags = mysql_query("select * from shoutbox order by id desc limit 10");
while($t=mysql_fetch_array($gettags))
{      
   //getting each variable from the table
   $id=$t["id"];
   $name=$t["name"];
   $message=$t["message"];
 
 
function BBCODE($bbcode)
{
//the bbcode tags..
$bbc_a=array(":D",":)","8)",":S",":arrow:",":'(",":!:",":lol:",">(",":l",":?:",":P",":(",":O",";)");

//bbcode gets converted to..
$bbc_b=array("<img border='0' src='Images/biggrin.gif'>","<img border='0' src='Images/smile.gif'>","<img border='0' src='Images/cool.gif'>","<img border='0' src='Images/confused.gif'>","<img border='0' src='Images/arrow.gif'>","<img border='0' src='Images/cry.gif'>","<img border='0' src='Images/exclaim.gif'>","<img border='0' src='Images/lol.gif'>","<img border='0' src='Images/mad.gif'>","<img border='0' src='Images/neutral.gif'>","<img border='0' src='Images/question.gif'>","<img border='0' src='Images/razz.gif'>","<img border='0' src='Images/sad.gif'>","<img border='0' src='Images/surprised.gif'>","<img border='0' src='Images/wink.gif'>");

$bbc_num=count($bbc_a);
$loop=0;
while($loop<$bbc_num)
{
$bbcode=str_replace($bbc_a[$loop], $bbc_b[$loop], $bbcode);
$loop++;
}


return $bbcode;
}
 

$message2 = "$message";
$message2 = BBCODE($message2);


echo "<b>";
echo "$name";
echo ":";
echo "</b>";
echo "<br>";
echo "$message2";
echo "<hr>";
}
break;


default:
echo "<center>";
echo "<table width=\"210\" border=\"3\" cellspacing=\"0\" cellpadding=\"0\">

  <tr>
    <td width=\"210\" height=\"237\"><iframe name=\"tags\" border=\"0\" frameborder=\"0\" width=\"200\" height=\"237\" align=\"center\" src=\"index.php?action=viewtags\"></iframe></td>
  </tr>
 
  <tr>
    <td height=\"100\"><form action=\"index.php?action=tagit\" method=\"post\">
   Name: <input type=\"text\" name=\"name\" /><br>
Message: <textarea type=\"text\" name=\"message\" rows=\"6\" cols=\"23\"></textarea>
<input type=\"submit\" name=\"submit\" value=\"Tag\">
</form></td>
  </tr>
</table>";
echo "</center>";
echo "<style type=\"text/css\">
body {background-color: transparent}
</style>";
break;

case "tagit":
$name = htmlspecialchars($_POST['name']);
$message = nl2br(htmlspecialchars($_POST['message']));

If (!$name){
   print "You must enter your name!";
   } elseif (!$message){
   print "You must enter a message!";
}
else
{
$result=MYSQL_QUERY("INSERT INTO shoutbox (name,message)".
      "VALUES ('$name', '$message')");
echo "<center>";
echo "Message added!<br><br>You will be redirected in 3 seconds.";
echo "</center>";
echo "<meta http-equiv=\"Refresh\" content=\"3; URL=index.php\"/>";
echo "<style type=\"text/css\">
body {background-color: transparent}
</style>";
}
break;

}
?>


it display 1 post ok but then under it theres a BB code error

Fatal error: Cannot redeclare bbcode() (previously declared in /home/danielxp/domains/scripting4habbo.com/public_html/tag/index.php:19) in /public_html/tag/index.php on line 19

I don'y have a clue what to do
mathiaus
your creating the function on each result of the while loop you have. You need to move it outside of the while and just call it, quick example

Quote:
function bbcode() {
function code stuff here
}

while {
get info from db
bbcode();
}


quickly changing your code the below should work
http://frihost.pastebin.com/31
DanielXP
There is not code in the paste bin Confused
mathiaus
Their having database problems

Code:
<?

$connection = mysql_connect("localhost","danielxp_tag","**********");
mysql_select_db(danielxp_tag) or die(mysql_error());

function BBCODE($bbcode) {
   //the bbcode tags..
   $bbc_a=array(":D",":)","8)",":S",":arrow:",":'(",":!:",":lol:",">(",":l",":?:",":P",":(",":O",";)");

   //bbcode gets converted to..
   $bbc_b=array("<img border='0' src='Images/biggrin.gif'>","<img border='0' src='Images/smile.gif'>","<img border='0' src='Images/cool.gif'>","<img border='0' src='Images/confused.gif'>","<img border='0' src='Images/arrow.gif'>","<img border='0' src='Images/cry.gif'>","<img border='0' src='Images/exclaim.gif'>","<img border='0' src='Images/lol.gif'>","<img border='0' src='Images/mad.gif'>","<img border='0' src='Images/neutral.gif'>","<img border='0' src='Images/question.gif'>","<img border='0' src='Images/razz.gif'>","<img border='0' src='Images/sad.gif'>","<img border='0' src='Images/surprised.gif'>","<img border='0' src='Images/wink.gif'>");

   $bbc_num=count($bbc_a);
   $loop=0;
   while($loop<$bbc_num) {
      $bbcode=str_replace($bbc_a[$loop], $bbc_b[$loop], $bbcode);
      $loop++;
   }
   
   return $bbcode;
}

switch($_GET['action']) {
   case "viewtags":

      $gettags = mysql_query("select * from shoutbox order by id desc limit 10");
      while($t=mysql_fetch_array($gettags)) {     
            //getting each variable from the table
            $id=$t["id"];
            $name=$t["name"];
            $message=$t["message"];
 
         $message2 = "$message";
         $message2 = BBCODE($message2);


         echo "<b>$name:</b><br />$message2<hr />";
      }
   break;
   case "tagit":
      $name = htmlspecialchars($_POST['name']);
      $message = nl2br(htmlspecialchars($_POST['message']));

      if(!$name){
            print "You must enter your name!";
         } elseif(!$message) {
            print "You must enter a message!";
      } else {
         $result=MYSQL_QUERY("INSERT INTO shoutbox (name,message)".
      "VALUES ('$name', '$message')");
         echo "<center>";
         echo "Message added!<br><br>You will be redirected in 3 seconds.";
         echo "</center>";
         echo "<meta http-equiv=\"Refresh\" content=\"3; URL=index.php\"/>";
         echo "<style type=\"text/css\">
body {background-color: transparent}
</style>";
      }
   break;
   default:
      echo "<center>";
      echo "<table width=\"210\" border=\"3\" cellspacing=\"0\" cellpadding=\"0\">

  <tr>
    <td width=\"210\" height=\"237\"><iframe name=\"tags\" border=\"0\" frameborder=\"0\" width=\"200\" height=\"237\" align=\"center\" src=\"index.php?action=viewtags\"></iframe></td>
  </tr>
 
  <tr>
    <td height=\"100\"><form action=\"index.php?action=tagit\" method=\"post\">
   Name: <input type=\"text\" name=\"name\" /><br>
Message: <textarea type=\"text\" name=\"message\" rows=\"6\" cols=\"23\"></textarea>
<input type=\"submit\" name=\"submit\" value=\"Tag\">
</form></td>
  </tr>
</table>";
      echo "</center>";
      echo "<style type=\"text/css\">
body {background-color: transparent}
</style>";
}
?>
DanielXP
Thanks works great

change a few thing back to how i made them coz thats how i code Very Happy
Related topics
FTP Codes
UBB Code / Smiley Parsing
BB Codes
Was there any point to sending men to the moon?
phpBB allowing HTML in sigs?
BB Codes
BB Code :|
PM Logout
How to realize "BB-Code"
UBB-codes voor op website
Moderators && Payed Option?
Can we ban "lulzy" English?
bb code help - regex
BB Codes usage is a little weird :S
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.