well I have this problem with my script:
couldn't insert data!
well I use this check error message inside my code after the checking if data is inserted inside database or not.
anyway the code has two part html,php
the html is used to handle form and show registration process and the php to handle the registration part.
the data base I have called fleet at my localhost server with this table users, users has rows (id,username, password, firstname,lastname,dat_reg)
sorry for taking too long to explain everything but I need help to resolve the database error shown at top
here html file code:
and the register.php code:HTML Code:<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Registration Page</title> <link rel="stylesheet" href="stylesheets/foundation.css"> <link rel="stylesheet" href="stylesheets/app.css"> <link rel="stylesheet" href="formly.css"> </head> <body> <div class="row"> <h1>Registration page</h1><br/><br/> <form action='register.php' method='post' class="nice" id="ContactInfo" > <label>Enter Username:</label> <input type='text' name='username' class="medium input-text" /> <label for="password">Enter Password:</label> <input type='password' name='password' class="medium input-text" title="Try to make it hard to guess."/> <label>Repeat Password:</label> <input type='password' name='repeatpassword' class="medium input-text"/> <label>Enter firstname:</label> <input type='text' name='firstname' class="medium input-text"/> <label>Enter lastname:</label> <input type='text' name='lastname' class="medium input-text"/> <input type='submit' name='submit' value='register' class="white radius nice button"/> </form> </div> </body> </html>
PHP Code:
<?php
//include("config.php");
//form data for registration
$firstname = strip_tags($_POST['firstname']);
$lastname = strip_tags($_POST['lastname']);
$username = strtolower(strip_tags($_POST['username']));
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
$date = ("y-m-d");
$submit = $_POST['submit'] ;
if(isset($submit)){
if($firstname&&$username&&$password&&$repeatpassword){
//check if password = repeatpassword
if($password == $repeatpassword){
//check username length
if(strlen($username)>25||strlen($username)<3){
echo"the allowed username length between 3 and 25!";
}//end username check length
//start else for username length
else{
//checking password length
if(strlen($password)>25||strlen($password)<5){
echo"your password must be between 5 and 25!";
}//end checking password length
//start else for checking password length
else{
//encrypt the passwords
$password = md5($password);
$repeatpassword = md5($repeatpassword);
$connect= mysql_connect("localhost","root","")or die("could not connect database!");
mysql_select_db("fleet",$connect)or die("couldn't select database!");
$queryreg = "INSERT INTO users (id,username,password,firstname,lastname,date_reg) VALUES ('0','".$username."','".$password."','".$firstname."','".$lastname."','".$date."')";
mysql_query($queryreg , $connect)or die("couldn't insert data!");
echo "registration sucessful! back to member page <a 'href='member.php'>here</a>";
}//end else for checking password length
}//end else for username length
}//end check if password = repeatpassword
else{
echo"password and repeatpassword not match!";
}
}//end of checking fields
else
echo"Please fill in all feilds!";
}
?>



Reply With Quote

Bookmarks