...

View Full Version : How to create database



ScorpionZ
01-22-2008, 07:09 AM
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

abduraooft
01-22-2008, 07:47 AM
Use google, meanwhile have a look at http://www.w3schools.com/php/php_mysql_insert.asp to get an intro.

ScorpionZ
01-22-2008, 08:07 AM
I did study that from this Web
But i need to understand Procedure
Which thing have to place at where
Thanks After all....

kbluhm
01-22-2008, 03:16 PM
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

// 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_query( sprintf(
'INSERT INTO `table` ( `username`, `password` ) VALUES ( \'&#37;s\', \'%s\' )',
$input['username'],
$input['password']
) );
// display success
$insertId = mysql_insert_id();
echo 'Inserted ID: ', $insertId;
}
else
{
// display errors
echo 'Errors! ', print_r( $errors, 1 );
}
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>

ScorpionZ
01-23-2008, 04:12 AM
Thanks a lot for Providing me Steps
Definitely it helps a lot
Thanks

ScorpionZ
01-26-2008, 07:28 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum