Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 6 of 6

Thread: Code help

  1. #1
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default Code help

    This isnt writing to the database like it should. Can anyone find the problem with it? (I want to use POST with it, not GET)
    <?php
    require 'includes/connect.php';
    if($_GET["method"] === "post") {
    $name = addslashes($_POST["name"]);
    } else {
    $name = addslashes($_GET["name"]);
    }

    if(empty($name)) {
    echo 'No name in variable';
    exit;
    }
    $checkifExists = mysql_query("SELECT COUNT(*) FROM submissions WHERE name = '$name'");
    $checkifExists2 = mysql_fetch_array($checkifExists);
    if($checkifExists2['COUNT(*)'] === '1') {
    echo 'Unable to add, that already exists!';
    exit;
    }
    $addtoDB = mysql_query("INSERT INTO submissions (name, ip, votes) VALUES('$name', '$_SERVER[REMOTE_ADDR]' , '0')");
    echo 'Added to database';
    ?>

  2. #2
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    PHP Code:
    <?php
    include "includes/connect.php";

    $name mysql_real_escape_string($_REQUEST["name"]);

    if(empty(
    $name)) {
        exit(
    "No name in variable.");
    }

    $check_if_exists mysql_query("SELECT * FROM `submissions` WHERE `name`='$name'");
    $check_if_exists mysql_num_rows($check_if_exists);

    if(!
    $check_if_exists) {
        exit(
    "Unable to add, that already exists!");
    }

    $ip $_SERVER["REMOTE_ADDR"];

    mysql_query("INSERT INTO `submissions` (name, ip, votes) VALUES('$name', '$ip', '0')") or die(mysql_error());

    echo 
    'Added to database';
    ?>

  3. #3
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    PHP Code:
    <?php
    include "includes/connect.php";
     
    $name mysql_real_escape_string($_REQUEST["name"]);
     
    if(empty(
    $name)) {
        exit(
    "No name in variable.");
    }
     
    $check_if_exists mysql_query("SELECT * FROM `submissions` WHERE `name`='$name'");
    $check_if_exists mysql_num_rows($check_if_exists);
     
    if(!
    $check_if_exists) {
        exit(
    "Unable to add, that already exists!");
    }
     
    $ip $_SERVER["REMOTE_ADDR"];
     
    mysql_query("INSERT INTO `submissions` (name, ip, votes) VALUES('$name', '$ip', '0')") or die(mysql_error());
     
    echo 
    'Added to database';
    ?>
    Wow, thanks caleb. Genious! +Rep

  4. #4
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Quote Originally Posted by FlyDuo View Post
    Wow, thanks caleb. Genious! +Rep
    No problem

  5. #5
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Hmmm, still not working. Are you sure thats getting my variable from POST? It arrives in the form name=John or whatever. My Application is definatly working because its posting name=John or whatever to addtotext.php which is saving it to a text file. My connect.php is right too because its reading from the database using connect.php just not writing to it.

  6. #6
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Is it writing anything to the database?

    $_REQUEST gets it from POST, GET, or COOKIE.

Posting Permissions

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