Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to create database

    Hi this is Scorp,

    I m using PHP with My SQL
    Now I have Created Database with name
    test_db at
    http://localhost/phpmyadmin/
    with table name test_emp with 5 diffrent fields

    I have created a form on HTML with 5 fields

    Now how to do this all
    How to connect it and then when i write on the fields and press submit button
    it should save into Database.
    How to do this all
    Can anyone Suggest a Tutorial so as to do this demo.
    I will be Thankful
    Regards
    Scorp

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Use google, meanwhile have a look at http://www.w3schools.com/php/php_mysql_insert.asp to get an intro.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks

    I did study that from this Web
    But i need to understand Procedure
    Which thing have to place at where
    Thanks After all....

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Procedure is all logical. What logic would you like to follow?

    • Load the page
    • Was there data posted?
      • Yes
        • Sanitize the data.
        • Is it formatted as you'd like?
          • Yes
            • Insert the data... then display a success message, kick back to the form, etc.

          • No
            • Display an error, kick back to the form, etc.


        • exit() from loading.

      • No
        • Display the insert form that posts back to the current file.



    That's about as simple as it gets. Here's a very simple example:
    PHP Code:
    <?php

    // Whatever file is bringing everything together
    // ie: database connection, etc...
    require './global.php';

    // Form was submitted?
    if ( !empty( $_POST ) )
    {
        
    // fix slashes
        
    $input get_magic_quotes_gpc() ? array_map'stripslashes'$_POST ) : $_POST;
        
    // track errors
        
    $errors = array();
        
    // check inputs
        
    if ( !isset( $input['username'] ) OR !isset( $input['password'] ) )
        {
            
    $errors[] = 'Missing inputs, possible hack attempt.';
        }
        else
        {
            
    // username
            
    if ( !ctype_alnum$input['username'] ) )
            {
                
    $errors[] = 'Bad username, must be alphanumeric only.';
            }
            
    // password
            
    if ( !ctype_print$input['password'] ) )
            {
                
    $errors[] = 'Bad password, contains illegal characters.';
            }
        }
        
    // any errors?
        
    if ( empty( $errors ) )
        {
            
    // insert
            
    $input array_map'mysql_real_escape_string'$input );
            
    mysql_querysprintf(
                
    'INSERT INTO `table` ( `username`, `password` ) VALUES ( \'%s\', \'%s\' )',
                
    $input['username'],
                
    $input['password']
            ) );
            
    // display success
            
    $insertId mysql_insert_id();
            echo 
    'Inserted ID: '$insertId;
        }
        else
        {
            
    // display errors
            
    echo 'Errors! 'print_r$errors);
        }
        exit;
    }

    // Display form

    ?>

    <form action="<?php echo basename__FILE__ ); ?>" method="post">

        <p>
            Username:
            <input type="text" name="username" />
        </p>

        <p>
            Password:
            <input type="password" name="password" />
        </p>

        <p>
            <input type="submit" name="submit" value="Save This Info" />
        </p>

    </form>
    Last edited by kbluhm; 01-23-2008 at 03:44 AM.

  • #5
    New Coder
    Join Date
    Jun 2007
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks

    Thanks a lot for Providing me Steps
    Definitely it helps a lot
    Thanks

  • #6
    New Coder
    Join Date
    Jun 2007
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to Compare database Value

    Hi
    i have created a Form of SignUp in PHP
    there is a Field of "Login Name" and "Password" with both have individual
    buttons " Check Availibility"

    Well I just need some code to get help regarding this scenario
    "when i enter a new Login it just check that Input Login in Database and result in "Alert Box"
    If it exist it gives message "Not Available"
    if dont exist it gives message "Available"

    I will be Thankful
    Regards
    Scorp


  •  

    Posting Permissions

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