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 8 of 8

Thread: SQL Problem

  1. #1
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default SQL Problem

    I have the code:

    PHP Code:
    <?

    // Database Connect

    $host "localhost";
    $user "usr";
    $pass "pass";
    $db "usr";
    $cn mysql_pconnect($host$user$pass);
    if( !
    $cn )
    {
    echo 
    "Error connecting to database.";
    }
    mysql_select_db($db);



    //Check If form has been submitted

    if($_POST["B1"]) {



    // If Habbo Name hasn't been entered

    if($_POST[T1] = "") {
    die(
    "<font face='verdana' size='1'>You must enter a habbo name</font>");
    }


    // If Forum name hasn't been entered

    if($_POST[T2] = "") {
    die(
    "<font face='verdana' size='1'>You must enter a forum name</font>");
    }

    // If username is already in database

    $find_username mysql_query("SELECT * FROM event WHERE name = '$_POST[T1]'");
     
    $duplicate_username mysql_num_rows($find_username); 


    // If not, then enter user

    if ($duplicate_username == ) {
    $query mysql_query("INSERT INTO `event` (`name`, `forum`, `points`) VALUES('$_POST[T1]', '$_POST[T2]', '50')");
    echo 
    "<font face='verdana' size='1'>entered";

    // If in, show error

    } else {
    die(
    "<font face='verdana' size='1'>Habbo name already in database!</font>");
    }

    } else {

    ?>


    // Code for my page

    <?php ?>

    The code works etc (I removed the html code) but when i add the username check code, it always says Habbo name already in database no matter what.

    any help? thanks

  2. #2
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:

    Default

    u aint done a mysql_num_rows mate.

    Ur just checking the array for a number when it aint got that.

    PM me if u dont understand what im woffling about

    EDIT: NEW CODE

    PHP Code:
    <?

    // Database Connect

    $host "localhost";
    $user "usr";
    $pass "pass";
    $db "usr";
    $cn mysql_pconnect($host$user$pass);
    if( !
    $cn )
    {
    echo 
    "Error connecting to database.";
    }
    mysql_select_db($db);



    //Check If form has been submitted

    if($_POST["B1"]) {



    // If Habbo Name hasn't been entered

    if($_POST[T1] = "") {
    die(
    "<font face='verdana' size='1'>You must enter a habbo name</font>");
    }


    // If Forum name hasn't been entered

    if($_POST[T2] = "") {
    die(
    "<font face='verdana' size='1'>You must enter a forum name</font>");
    }

    // If username is already in database

    $find_username mysql_query("SELECT * FROM event WHERE name = '$_POST[T1]'");
     
    $all_usernames mysql_num_rows($find_username);
    $duplicate_username mysql_num_rows($all_usernames);


    // If not, then enter user

    if ($duplicate_username == ) {
    $query mysql_query("INSERT INTO `event` (`name`, `forum`, `points`) VALUES('$_POST[T1]', '$_POST[T2]', '50')");
    echo 
    "<font face='verdana' size='1'>entered";

    // If in, show error

    } else {
    die(
    "<font face='verdana' size='1'>Habbo name already in database!</font>");
    }

    } else {

    ?>


    // Code for my page

    <?php ?>
    Last edited by Jackboy; 17-01-2008 at 08:49 PM.

  3. #3
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    i dont understand what your woffling about as youve done the mysql_num_rows twice.
    Coming and going...
    Highers are getting the better of me

  4. #4
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default

    ^ doesnt work.

    And it does have num rows, here

    Code:
    $find_username = mysql_query("SELECT * FROM event WHERE name = '$_POST[T1]'");
     $duplicate_username = mysql_num_rows($find_username);
    edit: craig beat me

  5. #5

    Default

    I don't see why you'vwe given your query to insert the event or w.e a variable? I think the problem is you've wrapped your variable that represents the username in quotes but not the field you're checking, I don't know, try what i've done below and see if it works..
    PHP Code:
    <?

    // Database Connect

    $host "localhost";
    $user "usr";
    $pass "pass";
    $db "usr";
    $cn mysql_pconnect($host$user$pass);
    if( !
    $cn )
    {
    echo 
    "Error connecting to database.";
    }
    mysql_select_db($db);



    //Check If form has been submitted

    if($_POST["B1"]) {



    // If Habbo Name hasn't been entered

    if($_POST[T1] = "") {
    die(
    "<font face='verdana' size='1'>You must enter a habbo name</font>");
    }


    // If Forum name hasn't been entered

    if($_POST[T2] = "") {
    die(
    "<font face='verdana' size='1'>You must enter a forum name</font>");
    }

    // If username is already in database
    $find_username mysql_query("SELECT * FROM `event` WHERE `name` = '" $_POST['T1'] . "' ");
    $duplicate_username mysql_num_rows($find_username); 


    // If not, then enter user

    if ($duplicate_username == 0) {
    mysql_query("INSERT INTO `event` (`name`, `forum`, `points`) VALUES('$_POST[T1]', '$_POST[T2]', '50')");
    echo 
    "<font face='verdana' size='1'>entered";

    // If in, show error

    } else {
    die(
    "<font face='verdana' size='1'>Habbo name already in database!</font>");
    }

    } else {

    ?>

    // Code for my page

    <?php ?>

  6. #6
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default

    didnt work :s

  7. #7
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?

    // Database Connect

    $host "localhost";
    $user "usr";
    $pass "pass";
    $db "usr";
    $cn mysql_pconnect($host$user$pass);
    if( !
    $cn )
    {
    echo 
    "Error connecting to database.";
    }
    mysql_select_db($db);



    //Check If form has been submitted

    if($_POST["B1"]) {



    // If Habbo Name hasn't been entered

    if($_POST[T1] = "") {
    die(
    "<font face='verdana' size='1'>You must enter a habbo name</font>");
    }


    // If Forum name hasn't been entered

    if($_POST[T2] = "") {
    die(
    "<font face='verdana' size='1'>You must enter a forum name</font>");
    }

    // If username is already in database

    $find_username mysql_query("SELECT * FROM event");

    $duplicate_username 0
    while($countnums mysql_fetch_array($find_username))
    {
    if(
    $countnums[name] == $_POST[T1])
    $duplicate_username++;
    }


    // If not, then enter user

    if ($duplicate_username == ) {
    $query mysql_query("INSERT INTO `event` (`name`, `forum`, `points`) VALUES('$_POST[T1]', '$_POST[T2]', '50')");
    echo 
    "<font face='verdana' size='1'>entered";

    // If in, show error

    } else {
    die(
    "<font face='verdana' size='1'>Habbo name already in database!</font>");
    }

    } else {

    ?>


    // Code for my page

    <?php ?>
    That bypasses the mysql_num_rows thing, in case thats the reason it doesnt work as i dont see anything wrong with it :S
    Coming and going...
    Highers are getting the better of me

  8. #8
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by MrCraig View Post
    i dont understand what your woffling about as youve done the mysql_num_rows twice.
    Lmao at me. I meant to do an array.

Posting Permissions

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