Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-22-2008, 07:09 AM   PM User | #1
ScorpionZ
New Coder

 
Join Date: Jun 2007
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
ScorpionZ can only hope to improve
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
ScorpionZ is offline   Reply With Quote
Old 01-22-2008, 07:47 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Use google, meanwhile have a look at http://www.w3schools.com/php/php_mysql_insert.asp to get an intro.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 01-22-2008, 08:07 AM   PM User | #3
ScorpionZ
New Coder

 
Join Date: Jun 2007
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
ScorpionZ can only hope to improve
Thanks

I did study that from this Web
But i need to understand Procedure
Which thing have to place at where
Thanks After all....
ScorpionZ is offline   Reply With Quote
Old 01-22-2008, 03:16 PM   PM User | #4
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,503
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
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>
__________________
ZCE

Last edited by kbluhm; 01-23-2008 at 03:44 AM..
kbluhm is offline   Reply With Quote
Old 01-23-2008, 04:12 AM   PM User | #5
ScorpionZ
New Coder

 
Join Date: Jun 2007
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
ScorpionZ can only hope to improve
Thanks

Thanks a lot for Providing me Steps
Definitely it helps a lot
Thanks
ScorpionZ is offline   Reply With Quote
Old 01-26-2008, 07:28 AM   PM User | #6
ScorpionZ
New Coder

 
Join Date: Jun 2007
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
ScorpionZ can only hope to improve
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
ScorpionZ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:13 PM.


Advertisement
Log in to turn off these ads.