Jump to content

Help please


muhaa

Recommended Posts

Hi guys i was wondering i followed a tutorial a while back for a shout box and was wondering if any on would be able to add a couple of extra functions for me as im not so good with php im looking to add some smileys and some thing like setcookie so that it remembers the name part of the user so they dont have to keep typing there name every time they make a new post here is the following code i have for now.

Any help would be much Apriciated.Thanx

 

<?php  
// You just need to configure these 4 variables to match your server.  
$db_host = "**"; // mySQL database host  
$db_user = "**"; // mySQL database user  
$db_password = "**"; // mySQL database password  
$db_name = "**"; // the name of your mySQL database  
// If a user has submitted a post, we want to :  
// 1. Validate it  
// 2. Strip unwanted html  
// 3. Make sure messages and names aren't too long  
// 4. Add it to our database.  
if($_POST['submit']) {  
// 1. Validate it, by checking all the form inputs were filled in  
    if(!$_POST['author']) {  
        echo 'Error ! : No name entered';  
        die;  
    }  
    
    if(!$_POST['message']) {  
        echo 'Error ! : No message entered';  
        die;  
    }  
// 2. Strip unwanted HTML  
// Look up the strip_tags() function at  
// http://www.php.net/manual/en/function.strip-tags.php for more info  
    $message = strip_tags($_POST['message'], '');  
    $author = strip_tags($_POST['author'], '');  
// 3. Make sure messages and names aren't too long  
// We will use the strlen() function to count the length.  
    $message_length = strlen($message);  
    $author_length = strlen($author);  
    if($message_length > 150) {  
        echo "Error ! : Your message was too long, messages must be less than 150 chars";  
        die;  
    }  
    if($author_length > 150) {  
        echo "Error ! : Your name was too long, names must be less than 150 chars";  
        die;  
    }  
// 4. Add it to our database.  
// If the script hasn't died yet due to an error in the inputted data  
// we need to add the data to the database  
// Lets connect to our database.  
    mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());  
// Select the database.  
    mysql_select_db($db_name) or die(mysql_error());  
// Lets define the date format we want to enter to our database  
// go here for more details  
// http://www.php.net/manual/en/function.date.php  
    $date = date("h:i A dS M");  
// This will produce 11:02 25th Aug  
// Set the query as $query  
    $query = "INSERT INTO shoutbox (message, author, email, date, ip)  
VALUES ('$message','$author','$email','$date','$_SERVER[REMOTE_ADDR]')";  
    mysql_query($query);  
    mysql_close();  
    // Show thanks message and take them back to the main shoutbox  
    echo "Ur post has been adedd<BR>";  
    echo "<A HREF=\"shoutbox.php\">View the shoutbox</A>";  
// If they haven't submitted a post, we want to :  
// 1. Show the latest shouts  
// 2. Show the shout post form  
} else {  
// 1. Show the latest shouts  
// Lets connect to our database.  
    mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());  
// Select the database.  
    mysql_select_db($db_name) or die(mysql_error());  
// Set the query as $query, and get the last 10 posts.  
    $query = "SELECT message, author, email, date, ip  
FROM shoutbox order by id DESC LIMIT 10";  
    $result = mysql_query($query);  
    echo "<TABLE>";  
    while($r=mysql_fetch_array($result))     
    {  
// To modify the appearance, edit this :  
        echo "<TR>  
            <TD><font size='2'>  
Posted $r[date] by  
$r[author]</A></font></TD>  
        </TR>  
        <TR>  
            <TD><font size='3'>$r[message]</font></TD>  
        </TR>  
        <TR>  
            <TD><HR></TD>  
        </TR>";  
         
    }  
    echo "</TABLE>";  
// 2. Show the shout post form  
?>  
    <FORM METHOD=POST ACTION="shoutbox.php">  
    <p> </p> 
    <p> </p> 
    <p> </p> 
    <TABLE align="center">  
    <TR>  
        <TD>Name :</TD>  
        <TD><INPUT TYPE="text" NAME="author"></TD>  
    </TR>  
  
    <TR>  
        <TD height="46">Message :</TD>  
        <TD><textarea name="message" cols="90"></textarea></TD>  
    </TR>  
    <TR>  
        <TD> </TD>  
        <TD><INPUT TYPE="submit" name="submit" value="post"></TD>  
    </TR>  
    </TABLE>  
    </FORM>  
    <div align="center"> 
      <?php  
}  
?> 
    </div>

Link to comment
https://forums.phpfreaks.com/topic/40379-help-please/
Share on other sites

Duno mate it has php and mysql lol.Any where that is better i supose mate.Lol im not looking to pay for

Some one to do it mate im just looking to get either pointed in the right direction ..Or any one that has free time that fancys helping some one out.Im sure it dont need much code adding for the functions im wanting m8 a few lines if any thing for the smilies and a few lines for the setcookie.

Link to comment
https://forums.phpfreaks.com/topic/40379-help-please/#findComment-195388
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.