+ Reply to Thread
Results 1 to 2 of 2

Thread: [php] simple shout script with mysql database

  1. #1
    bokepwap is offline Junior Member bokepwap is on a distinguished road
    Join Date
    Jun 2008
    Posts
    14

    Default [php] simple shout script with mysql database

    juat simple script with database MySQL

    first you need make a table in your mysql database
    for example, table name is contoh_tabel_shout.
    make this table with PHPMyAdmin
    PHP Code:
     CREATE TABLE `contoh_tabel_shout` (
    `
    idINT11 UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `
    usernameCHAR32 NOT NULL ,
    `
    timeINT11 NOT NULL ,
    `
    textTEXT NOT NULL
    ENGINE MYISAM 
    there are 4 fields:
    - id
    - username
    - time
    - text

  2. #2
    bokepwap is offline Junior Member bokepwap is on a distinguished road
    Join Date
    Jun 2008
    Posts
    14

    Default

    This is the shout.php script code:

    Code:
    <?php
    $serper_host = 'localhost'; // database host
    $serper_username = 'username_database'; // database username
    $serper_password = 'password_database'; // database password
    $serper_database = 'nama_database'; // database name
    $nama_tabel = 'contoh_tabel_shout'; // database table name
    
    mysql_connect($serper_host, $serper_username, $serper_password)
    or die("Could not connect: " . mysql_error());
    mysql_select_db($serper_database);
    
    
    if ($_SERVER['REQUEST_METHOD']=='POST')
    {
    $username = htmlspecialchars(addslashes(stripslashes($_POST['username'])));
    $text = htmlspecialchars(addslashes(stripslashes($_POST['text'])));
    $query = mysql_query("
    INSERT INTO $nama_tabel
    (username, time, text)
    VALUES
    ('$username', ".time().", '$text')
    ");
    if (!$query)
    {
    die ("Ga bisa masukin post baru".mysql_error());
    exit;
    }
    }
    
    $result = mysql_query("
    SELECT username, time, text
    FROM $nama_tabel
    ORDER BY time DESC
    LIMIT 0,5
    ");
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    printf("%s [%s]: &nbsp;
    %s
    <br/>
    ",
    $row['username'],
    gmdate('d m/H:i', $row['time']+(7*3600)),
    $row['text']
    );
    }
    ?>
    <br/><br/>
    <form action="<?=$_SERVER['PHP_SELF']?>?" method="post">
    <div>
    Username:<br/><input type="text" name="username" size="16"/>
    <br/>
    Text:<br/><input type="text" name="text" size="40"/>
    <br/>
    <input type="submit" value="Shout!"/>
    </div>
    </form>
    <?php
    mysql_free_result($result);
    ?>
    

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 02-11-2010, 01:09 PM
  2. I need a simple PHP news script?
    By George in forum PHP
    Replies: 0
    Last Post: 02-08-2010, 12:40 AM
  3. Replies: 2
    Last Post: 01-31-2010, 11:27 PM
  4. Replies: 0
    Last Post: 01-31-2010, 08:34 AM
  5. Replies: 0
    Last Post: 01-10-2010, 01:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts