Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20
  1. #11
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Use this

    PHP Code:
    <?php
    $hostname 
    = ("localhost");
    $database = ("database");
    $username = ("username");
    $password = ("password");
    mysql_connect($hostname$username$password);
    mysql_selectdb($database);
    function 
    clean($string)
    {
    // This is from KP2 - Thanks!
    $string str_replace("\""""$string);
    $string nl2br($string);
    $string htmlentities($string);
    $words = array("UNION",
    "SELECT FROM",
    "ORDER BY",
    "INSERT INTO",
    "TRUNCATE",
    "DROP TABLE",
    "CREATE TABLE",
    "DROP DATABASE"); // All the queries we want to stop
    $string preg_replace("/$words/i"""$string);
    return 
    $string;
    }
    switch(
    $_GET["act"])
    {
    default:
    if(isset(
    $_POST["credits"]))
    {
    if(
    is_numeric($_POST["credits"]))
    {
    for(
    $i=0$i<"8"$i++)
    {
    $randnum mt_rand(0,61);
    if(
    $randnum 10)
    {
    $randstr .= chr($randnum+48);
    }
    else if(
    $randnum 36)
    {
    $randstr .= chr($randnum+55);
    }
    else
    {
    $randstr .= chr($randnum+61);
    }
    }
    $string strtolower($randstr);
    $value clean($_POST["credits"]);
    mysql_query("INSERT INTO `credits` (`value`, `string`) VALUES ('$value', '$string')");

    echo 
    'You have created ' $_POST["credits"] . ' Credits! - Your code is ' $string ' Have fun!';
    } else {
    echo 
    'Your amount of credits is not a number';
    }
    }
    else {
    ?>
    Add credits (ammount)
    <br />
    <form action="check.php" method="POST">
    <input name="credits" type="text" />
    <input type="submit" value="Submit!" />
    </form>
    <?php
    }
    break;
    case 
    submit:
    {
    if(isset(
    $_POST["credit"]))
    {
    $credits clean($_POST["credit"]);
    $sql mysql_query("SELECT * FROM `credits` WHERE `string` = '$credits'");
    if(
    mysql_num_rows($sql) == "1")
    {
    $fetch mysql_fetch_array($sql);
    $value $fetch["value"];
    echo 
    "Correct voucher code! Also, if you wanted it to add the the users credits, add a mysql insert for the user to earn some credits, with the credit value as $value";
    mysql_query("DELETE FROM `credits` WHERE `credits`.`value` = '$value' AND CONVERT(`credits`.`string` USING utf8) = '$credits'");
    } else {
    echo 
    "Invalid code";
    }
    } else
    {
    echo 
    'Redeem credits<br />
    <form action="check.php?act=submit" method="POST">
    <input name="credit" type="text" />
    <input type="submit" value="Submit!" />
    </form>'
    ;
    }
    }
    break;
    }
    ?>
    Call it create.php

    And for the database:

    CREATE TABLE `credits` (
    `value` VARCHAR( 225 ) NOT NULL ,
    `string` VARCHAR( 225 ) NOT NULL
    ) ENGINE = MYISAM ;

    It creates a credit code, then a user types in the code at create.php?act=submit then you need to add a thing which updates their credits by the ammount, then it deletes it.

    Have fun (edit mysql details aswell!)

    Edit: ignore my crap coding
    Last edited by Blob; 29-05-2007 at 03:08 PM.

  2. #12
    Join Date
    Jan 2007
    Posts
    651
    Tokens
    0

    Default

    Code:
    <?php
    
    $answerto = 'Hello';
    
    if ($_GET['action'] == 'send'){
    
    $text = $_POST['text']
    
    if ($text == $answerto){
    echo('Hello too you too.');
    }else{
    echo('What?');
    }
    }
    ?>
    You mean a chat bot basically ?
    Last edited by Mr Macro; 29-05-2007 at 03:20 PM.
    James


    Connected to reality through a proxy server.

  3. #13
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by Mr Macro View Post
    Code:
    <?php
    
    $answerto = 'Hello';
    
    if ($_GET['action'] == 'send'){
    
    $text = $_POST['text']
    
    if ($text == $answerto){
    echo('Hello too you too.');
    }else{
    echo('What?');
    }
    }
    ?>
    You mean a chat bot basically ?
    No..??

  4. #14
    Join Date
    Jan 2007
    Posts
    651
    Tokens
    0

    Default

    oh I also forgot too put the form in
    James


    Connected to reality through a proxy server.

  5. #15
    Join Date
    Nov 2006
    Location
    Shropshire
    Posts
    1,590
    Tokens
    357
    Habbo
    MailOffice

    Latest Awards:

    Default

    Hummm that code didnt work ?

    When i type in credits

    It didnt come up with the text what its suppose to !

    PLEASE HELP ! I NEED BADLY !

    (TO THE FIRST CODE)

    Second Code :
    Worked but was not what need

    I NEED IT SO
    If i Type in a Numba it will react

    DOESNT HAVE TO BE MYSQL

    So i type in like cola , Then it will recognise that i want a cola and type back heres your cola or A Message popup sayin heres your cola

    OR HERES YA CREDITS !

    ANYWAYS THANSK FOR HELPING +REP !
    Last edited by Naythi.; 29-05-2007 at 10:27 PM.


    .xo

  6. #16
    Join Date
    Jun 2004
    Location
    London
    Posts
    116
    Tokens
    0

    Default

    Reina to use IFs you need "==", "=" is for declaring variables.
    You could use a switch function:

    PHP Code:
    <?
    $credits 
    = ?? GET DATA FROM FILETABLEGETPOST ETC?

    $x $_POST['drink']; // Gets drink value

    switch($x) {

    case 
    'cola'
    echo 
    "You have chosen cola?<br />";
    $credits $credits+1;
    echo 
    "You now have:" $credits " credits ";
    break;

    case 
    'blood'
    echo 
    "You have chosen Blood?";
    $credits $credits+1;
    echo 
    "You now have:" $credits " credits ";
    break;

    default:
    echo 
    "You chosen an unknown drink";
    break;

    }

    ?>
    Last edited by *; 30-05-2007 at 10:15 AM.

  7. #17
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by nayc001 View Post
    Hummm that code didnt work ?

    When i type in credits

    It didnt come up with the text what its suppose to !

    PLEASE HELP ! I NEED BADLY !

    (TO THE FIRST CODE)

    Second Code :
    Worked but was not what need

    I NEED IT SO
    If i Type in a Numba it will react

    DOESNT HAVE TO BE MYSQL

    So i type in like cola , Then it will recognise that i want a cola and type back heres your cola or A Message popup sayin heres your cola

    OR HERES YA CREDITS !

    ANYWAYS THANSK FOR HELPING +REP !
    On my one, you type in how many credits and it makes a code for it, and puts it in mysql. Then you go to create.php?act=submit and type in that code, and then it says if you got it right, and then you need to add a mysql insert to add the credits to the user

  8. #18
    Join Date
    Jul 2006
    Location
    Athens
    Posts
    842
    Tokens
    0

    Default

    Quote Originally Posted by * View Post
    Reina to use IFs you need "==", "=" is for declaring variables.
    You could use a switch function:
    I ain't stupid. Don't tel me how to code when the code was correct


  9. #19
    Join Date
    Jun 2004
    Location
    London
    Posts
    116
    Tokens
    0

  10. #20
    Join Date
    Jan 2006
    Location
    Cambridge
    Posts
    1,911
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Reina View Post
    I ain't stupid. Don't tel me how to code when the code was correct
    lol ur

    Jokzzz
    EDTALKING


Page 2 of 2 FirstFirst 12

Posting Permissions

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