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 7 of 7
  1. #1
    Join Date
    Apr 2008
    Location
    Derby
    Posts
    4,668
    Tokens
    262

    Latest Awards:

    Default php MySQL help! Please!!

    Ok, So i have this form and a PHP processing file, their extremely simple (Ive added no security as of yet!)

    Everytime I press submit the form does what its supposed to do but 'password' doesnt insert into the database: can anyone help me??
    Thanks in advance!

    HTML Code:
    <html>
    <form id="register" method="post" action="newuser.php">
     
    Username:<br />
    <input type="text" name="username" /><br /><br />
     
    Password:<br />
    <input type="password" name="password" /><br /><br />
    Rank:<br />
    <input type = "radio" name = "rank" value = "1" /> Admin <br/>
    <input type = "radio" name = "rank" value = "2" /> Forum <br/>
    <input type = "radio" name = "rank" value = "3" /> News <br/>
    <input type = "radio" name = "rank" value = "4" /> Events <br/>
    <input type = "radio" name = "rank" value = "5" /> Radio <br/>
     
    <input type="submit" name="submit" value="Create" />
    </form>
    </html>
    Thats the form
    This is the PHP:

    PHP Code:
    <?php
    include ("config.php");
     
    $user = ($_POST['username']);
    $password = ($_POST['password']);
    $rank = ($_POST['rank']);
     
    mysql_query("INSERT INTO users (username, password, rank) 
    VALUES ('
    $user', '$password', '$rank')");
    ?>
    Excuse the basic-ness!

    +rep for any help, and my upper most gratitude!
    Back for a while

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

    Latest Awards:

    Default

    PHP Code:
    <?php
    include "config.php";  // first off, you don't need the ()'s around include.

    $username $_POST['username'];
    $password $_POST['password'];
    $rank $_POST['rank'];

    /*
    You don't need the ()'s around these either, it's pointless.
    $user = ($_POST['username']);
    $password = ($_POST['password']);
    $rank = ($_POST['rank']);
    */

    mysql_query("INSERT INTO `users` (username, password, rank) VALUES('$username', '$password', '$rank')") or die(mysql_error());
    ?>
    Try this, tell me what happens.

  3. #3
    Join Date
    Apr 2008
    Location
    Derby
    Posts
    4,668
    Tokens
    262

    Latest Awards:

    Default

    Thanks!!! That works!

    Another VERY quick question!

    I want to make it so some pages are only available for rank '2' or rank '3'

    So how would i go about checking if the user is rank 3 and then displaying the data, and if there not then not displaying the data??

    Thanks again! Btw, what did i do wrong before other than the ()'s?
    Back for a while

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

    Latest Awards:

    Default

    Not really sure what was wrong, it didn't output an error. I put ``(s) around the `users` table.

    Well you need to get the user's rank from the database..

    PHP Code:
    $username "Caleb"// you can get this from a session, wherever.
    $logged mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
    $logged mysql_fetch_array($logged);

    if(
    $logged["rank"] != "1") {
        
    // not an admin.
        
    exit("Not an admin."); // you can redirect to an error page, include something here, doesn't matter, just exit.
    }

    // aha.. they are an admin.. show the content.

    echo "Secret Stuff."
    You can put the $logged part somewhere else, and use it cross-site.

  5. #5
    Join Date
    Apr 2008
    Location
    Derby
    Posts
    4,668
    Tokens
    262

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    Not really sure what was wrong, it didn't output an error. I put ``(s) around the `users` table.

    Well you need to get the user's rank from the database..

    PHP Code:
    $username "Caleb"// you can get this from a session, wherever.
    $logged mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
    $logged mysql_fetch_array($logged);
     
    if(
    $logged["rank"] != "1") {
        
    // not an admin.
        
    exit("Not an admin."); // you can redirect to an error page, include something here, doesn't matter, just exit.
    }
     
    // aha.. they are an admin.. show the content.
     
    echo "Secret Stuff."
    You can put the $logged part somewhere else, and use it cross-site.
    if i was to put $logged in my config.php and include it in on everypage would it still work?
    Back for a while

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

    Latest Awards:

    Default

    It wouldn't work on the register pages, and things where you are not logged in, so that's really not the best place to put it.

    You could first determine if the user is logged in or not, and if he is.. then do the $logged procedure.

  7. #7
    Join Date
    Apr 2008
    Location
    Derby
    Posts
    4,668
    Tokens
    262

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    It wouldn't work on the register pages, and things where you are not logged in, so that's really not the best place to put it.

    You could first determine if the user is logged in or not, and if he is.. then do the $logged procedure.
    Ok!
    Thanks for your help so much!
    Ive managed to fulfil the task i needed, so i cant thank you enough!!
    Back for a while

Posting Permissions

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