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!


Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default PHP Form = mySQL

    I was wondering if anybody knows how I can have the data that's get's put in a form to go into a database.

    What type of form? View http://lab.jspace.netai.net
    Note that nothing on that form gets logged because I don't know how. It's just using $_POST.

  2. #2
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    You can't view it (like View Source).

    If you want, post a form and I'll create the handler.
    Vouches
    [x][x]

  3. #3
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    The code is below but I'm not sure if you understand what I mean, when you press submit I want it to go to index.php?page=registered like it is already but how do I make it so the data in the forms creates a table like.

    • Name
    • Email
    • Password


    register.php (PHP-Includes = index.php):
    PHP Code:
    <h3>Account Register</h3>

    <
    form action="index.php?page=registered" method="post"><br>
    Username: <input type="text" name="username" /><br>
    Email: <input type="text" name="email1" /><br>
    Email (Verify): <input type="text" name="email2" /><br>
    Password: <input type="password" name="password" /><br>
    Password (Verify): <input type="password" name="password2" /><br>
    <
    input type="submit" value="Register" /><input type="reset" value="Reset" />
    <
    br
    Registered.php:
    PHP Code:
    Thank you for registering, <?php echo $_POST["username"]; ?>!<br>
    <br>
    A verification email has been sent to <b><?php echo $_POST["email2"]; ?></b> so that we can confirm the email you provided is valid!<br>

  4. #4
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Use the insert command,

    config.php:

    PHP Code:
    <?php
    define
    ("dbhost""localhost"); // Where the database is hosted
    define("dbuser""root"); // The database's user
    define("dbpass""password"); // The database's user's password
    define("dbname""database"); // The name of the database

    mysql_connect(dbhostdbuserdbpass) or die (mysql_error());
    mysql_select_db(dbname) or die (mysql_error());
    ?>
    form.php:

    PHP Code:
    <?php
    require_once("config.php"); // MySQL connection details
    // Functions
    function clean($string){
    $string stripslashes($string);
    $string htmlentities($string);
    $string mysql_real_escape_string($string);

    return 
    $string;
    }
    // Check if form is submitted
    if(isset($_POST['submit'])){
    $username clean($_POST['username']);
    $email clean($_POST['email']);
    $message clean($_POST['message']);

    mysql_query("INSERT INTO `table` (`username`, `email`, `message`) VALUES ('' . $username . '', '' . $email . '', '' . $message . '')") or die (mysql_error());
    }
    ?>
    That a quick 1 I made up there and then so its untested and will need editting

    If you want me to edit it to work with your post above, let me know but its worth having a go at getting it working by yourself

    Hope it helps.

    Lew.
    Im not here to be loved, I love to be hated :-}


  5. #5
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    Thanks, I can't be bothered doing it through hosting so I'll try it on my other computer later via, xampp.

  6. #6
    Join Date
    Apr 2010
    Location
    Newcastle
    Posts
    655
    Tokens
    50

    Default

    Just noticed Lew's insert query is a little wrong, here's a fix:
    PHP Code:
    mysql_query("INSERT INTO `table` (`username`, `email`, `message`) VALUES ('{$username}', '{$email}', '{$message}');") or die (mysql_error()); 

  7. #7
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Apolva View Post
    Just noticed Lew's insert query is a little wrong, here's a fix:
    PHP Code:
    mysql_query("INSERT INTO `table` (`username`, `email`, `message`) VALUES ('{$username}', '{$email}', '{$message}');") or die (mysql_error()); 
    Thanks for the correction but to my knowledge, both work just as well as each other?

    Lew.
    Im not here to be loved, I love to be hated :-}


  8. #8
    Join Date
    Apr 2010
    Location
    Newcastle
    Posts
    655
    Tokens
    50

    Default

    Quote Originally Posted by Lewiie15 View Post
    Thanks for the correction but to my knowledge, both work just as well as each other?

    Lew.
    You used two single quotes as opposed to a single and double.

  9. #9
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    I'm trying to teach myself PHP so I haven't got that far as I'm still creating the tables via php script and I created the database easily and now I want to know why my tables aren't being created.

    Here's my code.
    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","root","");
    if (
    $con)
    {
    echo 
    "-<u>Connected to mySQL!</u> <br />";
    }
    else  
    {
      die(
    'Could not connect: ' mysql_error());
      }

    // Create table

    mysql_select_db("jacksphp"$con);
    if (
    $con)
    {
    echo 
    "-<u>Database Connected<u>";
    }
    else
    {
    die(
    'Error connecting to database: ' mysql_error());
    }
    $sql "CREATE TABLE Persons
    (
    Firstname varchar(15),
    Username varchar(15),
    Email varchar(15),
    Password vachar(15),
    )"
    ;

    // Execute query
    mysql_query($sql,$con);

    mysql_close($con);
    ?>

  10. #10
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    It drives me mad how I can't edit my posts. I'll try and get this merged but can somebody tell me what's wrong with these codes? Note: for the first one the ?> at the end was added in as the code continues on.

    PHP Code:
    <?php
    $con 
    mysql_connect($POST_["host"],$POST_["username"],$POST_["password"]);
    if (
    $con)
    {
    echo 
    "-<u>Connected to mySQL.</u> <br />";
    }
    else  
    {
      die(
    'Could not connect: ' mysql_error());
      }
    ?>
    Note: $POST_ is coming from a form.

    and

    PHP Code:
    <?php

    //Install Directory Existence Check
    if file_exists("test.php");
    {
    echo 
    "Please delete install directory after installation!";
    }
    else
    {
    die();
    }
    ?>
    Last edited by Shibby-Shabs; 04-09-2010 at 07:15 AM.

Page 1 of 2 12 LastLast

Posting Permissions

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