Results 1 to 2 of 2

Thread: creating sql form

  1. #1
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default creating sql form

    hi guys..
    i built two scripts i'm beginner in php . i need some help

    my first script is to add students details to database that i have done ..

    here is my first problem ..

    PHP Code:
    <?php

    // connect to database

    $h $_POST['host']; // database_name
    $u $_POST['user']; // database_user
    $p $_POST['pass']; // database_pass



    echo

    "<form method='POST' action='SQL.php' />
    Hostname : <input type='text' name='host' /><br />
    Username : <input type='text' name='user' /><br />
    Password : <input type='text' name='pass' /><br />
    <input type='submit' value='Login' />

    </form>"
    ;
    i'am not good in english sorry

    after creating form .. we should make certain steps right ,that to allow login to database, here is my problem

    someone please explain me in simple way to understand

    thank you

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    What you're doing here will require the user to 1) know the database credentials, and 2) enter them on every request.

    Some things to consider with this approach:

    1) You should limit the number of people that you pass out DB usernames/passwords to
    2) It would be a good idea for this account to have limited privileges (in case the username/password is leaked)
    3) You should use SSL to make sure the username/password cannot be stolen during the transaction.

    A more common approach is to store the database credentials in the script (or in a secure file on your server). Your users would log in to your site before being allowed to update the database.

    To answer your questions (if I understand correctly):
    PHP Code:
     <?php

    //------------------ connect to database
    # no, this does not create a database connection.
    # this only gets the host/username/password from the form
    # (IF the form was submitted - if not, it will create an error).

    $h $_POST['host']; // database_name
    $u $_POST['user']; // database_user
    $p $_POST['pass']; // database_pass



    echo

    "<form method='POST' action='SQL.php' />
    Hostname : <input type='text' name='host' /><br />
    Username : <input type='text' name='user' /><br />
    Password : <input type='text' name='pass' /><br />
    <input type='submit' value='Login' />

    </form>"
    ;
    You might try something like this instead:
    PHP Code:
    <?php

    // decide what to do

    // if the form was submitted
    if( !empty( $_POST ) ){
        
    // check each value:
        // if the value is not empty, use it: if not, leave it blank
        
    $h = !empty( $_POST['host'] )?  $_POST['host']: '';
        
    $u = !empty( $_POST['user'] )?  $_POST['user']: '';
        
    $p = !empty( $_POST['pass'] )?  $_POST['pass']: '';

        
    // one thing you're missing is the name of the database you wish to use.
        // for my example, I'll assume it's named "student".
        
    $d "student";

        
    // connect to the database.
        
    $DB = new mysqli$h,$u,$p,$d );

        
    // check for connection errors:
        
    if( $DB->connect_error ){
            
    // during development, you want to see the error message.
            // when your site is live, you should NEVER show error messages,
            // and you should NEVER use `exit` (or `die`) for error handling.
            
    exit( $DB->connect_error );
        }

        
    // now you are connected to the database.

    }

Similar Threads

  1. Creating a Registration form
    By arsenalbates in forum PHP
    Replies: 2
    Last Post: 01-28-2011, 04:46 AM
  2. creating xml file from php form
    By sukanya.paul in forum PHP
    Replies: 1
    Last Post: 12-02-2008, 09:57 AM
  3. Help creating order form
    By Twilightrose917 in forum Looking for such a script or service
    Replies: 44
    Last Post: 06-29-2008, 04:12 AM
  4. Please Help with Creating a form
    By asonda in forum PHP
    Replies: 1
    Last Post: 07-31-2007, 03:59 AM
  5. Creating a Form in Dreamweaver
    By chrislowthian in forum HTML
    Replies: 9
    Last Post: 05-15-2006, 05:44 PM

Bookmarks

Posting Permissions

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