here is my coding:
<?php
// only validate form when form is submitted
if(isset($POST['submit_button'])){
$first_name_input = $POST['first_name_input'];
$last_name_input = $POST['last_name_input'];
$username_input = $POST['username_input'];
$password_input = $POST['password_input'];
$email_input = $POST['email_input'];
$error_msg='';
if(trim($username_input)=='' || strlen(trim($username_input)) < 6 || strlen(trim($username_input)) > 15) {
$error_msg.="Please enter a username between 6 to 15 characters long<br>";
}
if(trim($password_input)=='' || strlen(trim($password_input)) < 4) {
$error_msg.="Please enter a password at least 4 characters long<br>";
}
if(trim($email_input)=='') {
$error_msg.="Please enter an email<br>";
} else {
// check if email is a valid address in this format [email]username@domain.com[/email]
if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email_input)) $error_msg.="Please enter a valid email address<br>";
}
// display error message if any, if not, proceed to other processing
if($error_msg==''){
//other processs goes here like process the form to database.
//Create a variable to hold the name of the database on which the table resides:
$db_name = "test";
//Create a variable to hold the name of the table you're populating with this script:
$table_name = "auth_user";
//dd the connection information as you have been:
$connection = mysql_connect("localhost", "root", "root")
or die(mysql_error());
//Select the database as you have learned:
$db = mysql_select_db($db_name, $connection) or die(mysql_error());
//Create the SQL statement. The first parenthetical statement gives the names of the fields to populate (in order), and the second parenthetical statement sends the actual strings:
$sql = "INSERT INTO $table_name (username, password, email, address, tel, intro)
VALUES ('$POST[username]',password('$POST[password]'),'$POST[email]', '$POST[address]', '$POST[tel]','$POST[intro]')";
//Note The PASSWORD() function inserts a hash of the password, not the password itself. This alleviates the security risk of having plain-text passwords sitting in your database, because all the script needs to do is match the two hashes.
//Create a variable to hold the result of the mysql_query() function, as you have learned:
$result = mysql_query($sql,$connection) or die(mysql_error());
echo ("sucessfull");
//Close your PHP block, and then add HTML:
} else {
echo "<font color=red>$error_msg</font>";
}
}
?>
<form method="POST" action="testing.php">
<table border="1" cellpadding="7" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
<tr>
<td width="16%" align="right">First Name</td>
<td width="84%">
<input type="text" name="first_name_input" size="20" value="<?php echo $POST['first_name_input']; ?>"></td>
</tr>
<tr>
<td width="16%" align="right">Last Name</td>
<td width="84%">
<input type="text" name="last_name_input" size="20" value="<?php echo $POST['last_name_input']; ?>"></td>
</tr>
<tr>
<td width="16%" align="right">Username</td>
<td width="84%">
<input type="text" name="username_input" size="20" value="<?php echo $POST['username_input']; ?>"> (between
6 to 15 characters)</td>
</tr>
<tr>
<td width="16%" align="right">Password</td>
<td width="84%">
<input type="password" name="password_input" size="20" value="<?php echo $POST['password_input']; ?>">
(must be at least 4 characters)</td>
</tr>
<tr>
<td width="16%" align="right">Email</td>
<td width="84%">
<input type="text" name="email_input" size="20" value="<?php echo $_POST['email_input']; ?>"></td>
</tr>
<tr>
<td width="16%" align="right"> </td>
<td width="84%">
<input type="submit" value=" Register " name="submit_button"></td>
</tr>
</table>
</form>
what i must say is, this is just a testing coding, and it will insert empty data into database if input is correct.
but my question is, if my resgistration is success, i do not want this page display the from, how can i do? please help me.
thanks