Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Errors with PHP shoutbox
Old 02-25-2008, 06:16 PM Errors with PHP shoutbox
Novice Talker

Posts: 8
Trades: 0
Well I followed an online tut and the person didn't help me with my errors at all.

Heres my code:

[PHP]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="imagetoolbar" content="no">
<link rel="stylesheet" href="common.css" type="text/css">
<base target="_self">
<title>Chat</title>
</head>
<body class="shoutboxbody" style="overflow-x: hidden;">
<?
$filename = "./shoutdb.txt";
$usemask = "yes";
$link_mask = "[link]";
$email_mask = "[email]";
/*
Smileys
*/
$smileydir = './images/';
/*
Define Smileys
*/
$smileys = array (
"[]" => "smile.gif",
"[)]" => "lol.gif",
"[]" => "sad.gif",
);
/*
Prepare Smileys
*/
function alter_smiley(&$item1, $key, $prefix) {
$item1 = " <img alt=\"\" src=\"$prefix$item1\" align=\"middle\" border=\"0\" />";
}
/*
Bad Words Filter
*/
function removeBadWords(&$text) {
$badwords = array(
"/fu.ck/",
"/sh.it/"
);
for ($i=0;$i<count($badwords);$i++)
$text = preg_replace($badwords[$i], "[]", $text);
}
/*
Save posts to database
*/
extract($_POST);
/*
Display Errors
*/
$errorMsg = "";
/*
Excutes script once submit is clicked
*/
if($submit) {
if(!$name) $errorMsg.="You need to enter a name!<br>";
elseif(!$shout) $errorMsg.="You need to enter text to send!<br>";
elseif(($name=="Name") || ($shout=="Message")) $errorMsg.="Say something!<br>";
else {
if($site) $author = "<a href='$site'>$name</a>";
else $author = $name;
$handle = fopen($filename,"a");
$date = strftime("%D");
$time = strftime("%T");
$ipaddr = $REMOTE_ADDR;
removeBadWords($shout);
/*
Write the code to txt file
*/
$data = "$date | $time | $author | $ipaddr | $shout\,";
fwrite($handle, "$data");
fclose($handle);
}
}
echo $errorMsg;
echo "<table class=\"SB_formarea\" width=\"100%\" border=\"0\">\n";
echo "<tr><td>\n";
echo "<form method=\"post\" action=\"shout.php\">\n";
echo "<div align=\"center\"><input type=\"text\" name=\"name\" size=\"16\" value=\"Name\" maxlength=\"14\" title=\"Name\" class=\"SB_input\"><br>\n";
echo "<input type=\"text\" name=\"shout\" size=\"16\" value=\"Message\" maxlength=\"1024\" title=\"Message\" class=\"SB_input\"><br>\n";
echo "<input type=\"submit\" name=\"submit\" value=\":: send ::\" class=\"SB_button\">\n";
echo "<input type=\"button\" name=\"refresh_it\" value=\"::\" class='SB_button' onclick=\"window.open('shout.php','_self');\">\n";
echo "</div></td></tr></form></table>\n";
$shouts = file($filename);
$rowColor = 0;
$count = 0;
array_walk ($smileys, 'alter_smiley', $smileydir);
krsort($shouts);


$link_search = array("/\</",
"/\>/",
"/\]/",
"/\[/",
"#([\n ])([a-z0-9\-_.]+?)@([^, \n\r]+)#i",
"#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^, \n\r]*)?)#i",
"/(?<!<a href=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i");
if ($usemask=='yes')
$link_replace = array("&lt;",
"&gt;",
">",
"<",
"\\1<a href=\"<A href="mailto:\\2@\\3\">".$email_mask."</a">mailto:\\2@\\3\">".$email_mask."</a>",
"\\1<a href=\"
Eddie12390 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-25-2008, 06:30 PM Re: Errors with PHP shoutbox
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
A that's not the complete code, please post the complete code. B What errors are you having?
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 02-25-2008, 07:17 PM Re: Errors with PHP shoutbox
Novice Talker

Posts: 8
Trades: 0
Thats all the code I got from the tutorial, and the shoutbox doesnt show up
Eddie12390 is offline
Reply With Quote
View Public Profile
 
Old 02-25-2008, 07:19 PM Re: Errors with PHP shoutbox
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Can you link to this tutorial?
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 02-25-2008, 09:09 PM Re: Errors with PHP shoutbox
Novice Talker

Posts: 8
Trades: 0
Well I decided to follow another tutorial, and yet again, problems

Heres the 3 files the tutorial had me make:

Shoutbox.php:
PHP Code:
<?php 
include(“connect.php”
If(isset(
$_POST[‘posted’])) 

$name $_POST[‘name’]; 
$message $_POST[‘message’]; 
$time time(); 
$ip $_SERVER[‘REMOTE_ADDR‘
$check_name_length strlen($name); // checks length 
$check_message_length strlen($message); // checks length 
If($check_name_length => 30) || if($check_message_length => 250// if statements for 
length 

echo 
“Please fill in the textboxes properly.
** else { 
mysql_query(“INSERT INTO shoutboxidipnametimemessageVALUES (“NULL”,”$ip”
“$name”“$time”“$message”)) or die (“Failed to add shout”); 
** 
**
<
form method="POST" act'ion="shoutbox.php"> 
Name: <input type="text name="name"><br>  
Message: <input type="text" name="message"><br><br> 
<input type="hidden" name="posted" value="true"> 
<input type="submit" value="Shout!">
Show_Shouts.php
PHP Code:
<?php 
include(“connect.php”); 
$query Mysql_query(“SELECT FROM shoutbox DESC id LIMIT 5”); 
while(
$r Mysql_fetch_array($query

$time $r[‘time’]; 
$name $r[‘name’]; 
$message $r[‘message’]; 
** 
echo 
“Shout by $name at $time:
echo 
$message
?>
And Connect.php: (I got rid of my user and assword etc. on purpose)
PHP Code:
<?php 
$connect 
mysql_connect(“host”,”username”,”password”) or die(“Failed to connect to host”
$db mysql_select_db(“database”) or die(“Failed to connect to database“); 
?>
Eddie12390 is offline
Reply With Quote
View Public Profile
 
Old 02-25-2008, 09:27 PM Re: Errors with PHP shoutbox
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
First make sure you have a database created and setup and in the connect.php file. Second you have a few errors that need fixed. Mainly you forgot to close things. Third, don't use Word or anything like that, please just use notepad, you had curly quotes, which could cause an issue. Also you had a few functions in upper case and that could cause an issue too.
PHP Code:
<?php include("connect.php"
If(isset(
$_POST['posted'])){
    
$name $_POST['name']; 
    
$message $_POST['message']; 
    
$time time(); 
    
$ip $_SERVER['REMOTE_ADDR'
    
$check_name_length strlen($name); // checks length 
    
$check_message_length strlen($message); // checks length 
    
If($check_name_length => 30) || if($check_message_length => 250){ 
        echo 
"Please fill in the textboxes properly.";}
    else{ 
        
mysql_query("INSERT INTO shoutbox( id, ip, name, time, message) VALUES (NULL,'$ip','$name','$time','$message')") or die ("Failed to add shout");}
else{ echo 
'<form method="POST" action="shoutbox.php"> 
Name: <input type="text" name="name"><br>  
Message: <input type="text" name="message"><br><br> 
<input type="hidden" name="posted" value="true"> 
<input type="submit" value="Shout!">'
;?>
PHP Code:
<?php include("connect.php"); 
$query mysql_query("SELECT * FROM shoutbox DESC id LIMIT 5"); 
while(
$r mysql_fetch_array($query){
    
$time $r['time']; 
    
$name $r['name']; 
    
$message $r['message']; 
    echo 
"Shout by ".$name." at ".$time.":"
    echo 
$message;
}
?>
Notice how colorful mine is compared to yours?
PHP Code:
<?php $connect mysql_connect("localhost","username","password") or die("Failed to connect to host");
$db mysql_select_db("database") or die("Failed to connect to database");?>
Try that and see how it goes, if it doesn't work link to the tutorial so we can see what it is that's going wrong.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>

Last edited by Arenlor; 02-25-2008 at 09:28 PM.. Reason: Forgot to close the php BBCODE
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 02-25-2008, 11:06 PM Re: Errors with PHP shoutbox
Sydpix's Avatar
Drinker I Smoke

Posts: 424
Name: Denny
Location: In a can...
Trades: 0
Just download this http://www.sydpixel.com/Downloads/floodbox.zip


See it in action http://www.davelefebre.com/
__________________
.
Village Idiot

Sydpix is offline
Reply With Quote
View Public Profile Visit Sydpix's homepage!
 
Old 02-26-2008, 05:53 PM Re: Errors with PHP shoutbox
Novice Talker

Posts: 8
Trades: 0
Sydpix: I wanted to learn something from it, otherwise I would have already downloaded 1 :P

Arenlor: I had the database set up a while ago because i have a forum with phpBB3, I ran the SQL query so thats already setup. Thx for the code help
Eddie12390 is offline
Reply With Quote
View Public Profile
 
Old 02-26-2008, 08:19 PM Re: Errors with PHP shoutbox
Sydpix's Avatar
Drinker I Smoke

Posts: 424
Name: Denny
Location: In a can...
Trades: 0
I find it quite interesting, only one referrer from this site and someone leaves a dirty message in the shoutbox....

Interesting....
__________________
.
Village Idiot

Sydpix is offline
Reply With Quote
View Public Profile Visit Sydpix's homepage!
 
Reply     « Reply to Errors with PHP shoutbox
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31175 seconds with 12 queries