Home General Chat
If you need urgent support, call 999 or go to your nearest A&E. To contact our Crisis Messenger (open 24/7) text THEMIX to 85258.
Options

What kinda script would this be?

Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
All I want is something that will allow users to visit the website, then paste whatever text they want into a box, and once the text has been pasted the script generates a link so they can send it their friends so they can view the pasted text.

Comments

  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    just a simple form with a textarea and a input text (to input username) send the form is send to a php scripts that generate an html page, this page is same on your server and then simply display the link to that page... Quite simple and straight forward...

    Otherwise can have the same but save the data into the database and have the username in the link (http://yourdomain.com/view.php?user=name) that page then query the db and retrieve the content for the username...
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    Something like this http://www.rorpaste.com/ | http://pastebin.com

    I'm not to great with PHP so would need a ready made script.
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    Don't have time right now but will post you the PHP part later if you want...
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    ok mate cheers
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    www.hotscripts.com probably has one.
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    Already looked bu tI dunno what I am looking for really.
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    ok mate cheers

    which one you want, one using db or one creating html files?

    Also do you want it to be so one user can have mutliple message or just one per user?
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    I'd prefer it using a db/single user.
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    This is the code that will store the data in database and display the link...
    Just did it quite basic... Haven't done the view.php script, can do if you don't know how to retrieve the data from the database...

    This script has been tested and work
    <?
    
    // I am assuming you have PHP and MySQL
    // Script have been tested.
    
    /* MySQL table structure
    
    CREATE TABLE `user_data` (
    `id` INT( 6 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `user` VARCHAR( 255 ) NOT NULL ,
    `msg` LONGTEXT NOT NULL
    ) TYPE = MYISAM ;
    
    */
    
    // MySQL settings (can be in a external file called sql.php)
    // Edit with your MySQL details
    $dbserver = "localhost";
    $dbuser = "########";
    $dbpass = "########";
    $db = "########";
    // require("sql.php"); if you want save setting in an external file
    
    // Check if form have been submitted with required variables
    if($_POST['submit'] && $_POST['user'] && $_POST['msg']){
    
            // Variables assignement
            $user = $_POST['user'];
            $msg = $_POST['msg'];
            $msg = nl2br($msg); // Insert <br /> tag where needed
            $display = "";
    
            // Connect to db
            $c = mysql_connect($dbserver,$dbuser,$dbpass);
            mysql_select_db($db);
            
            // We are checking if the user already use the sevice
            $sql = mysql_query(" SELECT * FROM `user_data` WHERE `user`='$user' ");
            $nb = mysql_num_rows($sql);
            
            // Check if user already use the service
            if($nb > 0){
            
                    // User already used it so don't store the data and create error message
                    $display = "<font color=\"#ff0000\"><b>Sorry you can not use this service twice</b></font>";
                    
            }else{
            
                    // Insert data into data base.
                    mysql_query(" INSERT INTO `user_data` (`id`,`user`,`msg`) VALUES ('','$user','$msg') ") or die ("couldn't insert data");
                    // Create success message
                    $display = "<font color=\"00ff00\"><b>Message successful stored</b></font><br>";
                    // Create link
                    $link = "http://mydomain.com/view.php?user=".$user;
                    $link = "<a href=\"".$link."\">".$link."</a>";
                    
            }
                    
    }
    
    if($display){ echo $display."<br/>"; }
    if($link){ echo $link."<br/><br/>"; }
    
    ?>
    
    <form action="script.php" method="post">
    User: <input type="text" name="user" size="20"><br />
    Message: <textarea name="msg" cols="20" rows="5">Type your message here...</textarea><br />
    <input type="submit" name="submit" value=" SEND ">
    </form>
    

    You can also download the file for it here
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    Fantastic mate, although I gets the following error.
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/my_username/public_html/hobo/paste.php on line 47
    couldn't insert data
    


    If you could do the view.php, that would be great.

    By the way, do you know the best resource for learning PHP?
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    Here is view.php
    <?

    // view.php

    // MySQL settings (can be in a external file called sql.php)
    // Edit with your MySQL details
    $dbserver = "localhost";
    $dbuser = "########";
    $dbpass = "########";
    $db = "########";
    // require("sql.php"); if you want save setting in an external file

    $user = $_REQUEST;

    // Connect to db
    $c = mysql_connect($dbserver,$dbuser,$dbpass);
    mysql_select_db($db);

    // We are checking if the user already use the sevice
    $sql = mysql_query(" SELECT * FROM `user_data` WHERE `user`='$user' ");
    $row = mysql_fetch_array($sql);

    extract($row);

    ?>

    Username: <? echo $user; ?><br /><br />
    Message: <? echo $msg; ?><br /><br />

    For the erro message have you created the database table properly?

    Cos tested the script and worked perfectly on my server...
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    I got it, works now. Cheers for this dude!
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    I got it, works now. Cheers for this dude!

    No problemo ;)
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    No problemo ;)
    "SELECT * FROM" is bad stylistically, as well as technically.

    SELECT msg FROM ....

    and I'd suggest changing the mysql_fetch to
    $row=mysql_fetch_object($result);

    and then use "$row->msg" instead of "$msg"
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    This is the code that will store the data in database and display the link...
    You should make sure that you use addslashes() on any strings supplied by the site visitor and used in SQL queries (unless you KNOW the magic convert stuff is in place.
  • Options
    White NoiseWhite Noise Posts: 624 Incredible Poster
    Big Gay wrote:
    "SELECT * FROM" is bad stylistically, as well as technically.

    SELECT msg FROM ....

    and I'd suggest changing the mysql_fetch to
    $row=mysql_fetch_object($result);

    and then use "$row->msg" instead of "$msg"
    Big Gay wrote:
    You should make sure that you use addslashes() on any strings supplied by the site visitor and used in SQL queries (unless you KNOW the magic convert stuff is in place.

    everyones a critic eh
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    everyones a critic eh
    I've seen worse from <strike>web monkeys</strike>professional programmers; but they shouldn't go uncorrected.
  • Options
    Former MemberFormer Member Posts: 1,876,323 The Mix Honorary Guru
    Never said it was perfect, frankly here it aint for a client, did it in a rush and those day I do more Plato development that php and never been a expert in PHP tbh. Thanks for the correction tho BigGay it is for sure a more efficient way of doing it.
Sign In or Register to comment.