2
Contributors
3
Replies
12
Views
3 Years
Discussion Span
Last Post by m1k3.mca
0

i finally made home page,user registration,login...(though the email is not getting stored in database...here is my code..

<?php include ('header.php'); ?> 


<?php
//Gets the form submitted data

@$register = $_GET['register'];

if($register == 1 && !empty($_POST)) // Checks if the form is submitted or not

{

//retrieve all submitted data from the form

$username = $_POST['username'];
$username = strip_tags($username); //strip tags are used to take plain text only, in case the register-er inserts dangours scripts.
$username = str_replace(' ', '', $username); // to remove blank spaces

$password = $_POST['password'];
$password = strip_tags($password); 
$password = md5($password); // md5 is used to encrypt your password to make it more secure.
$email = $_POST['email'];
$email = strip_tags($email);
$full_name = $_POST['full_name'];
$full_name = strip_tags($full_name);

$location = $_POST['location'];
$location = strip_tags($location);

$gender = $_POST['gender'];


$sql="SELECT id FROM users WHERE username='$username'"; // checking username already exists
$qry=mysql_query($sql);
$num_rows = mysql_num_rows($qry); 


//alert if it already exists
if($num_rows > 0) 
{
echo '
<div class="alert">
  <button type="button" class="close" data-dismiss="alert">&times;</button>
  <strong>username already exists!</strong> please choose another username
</div>
';
}

else 
{
// if username doesn't exist insert new records to database
 $success = mysql_query("INSERT INTO users(username, password, email, fullname, location, gender) VALUES ('$username','$password','$email','$full_name','$location','$gender')");


 //messages if the new record is inserted or not
if($success) { 
echo '
<div class="alert alert-success">
Registration Successful ! please login to your account
</div>
';
} 

else {
echo '
<div class="alert">
  <button type="button" class="close" data-dismiss="alert">&times;</button>
  <strong>Registration Unsuccessful! </strong> please try again
</div>
';


}

}

}
?>

<br/>

   <br/>
<?php
//hiding form once the registration is successful
 if(!@$success) 
 ?>

<form action="registerr.php?register=1" method="post" name="myForm" onsubmit="return(validate());">
  <fieldset>

    <legend>Sign Up Form</legend>
    <label>Username *</label>
    <input name="username" type="text" >
    <br/>
    <label>Password *</label>
    <input name="password" type="password" >
    </br>
    <label>email *</label>
    <input name="email" type="text" >
    <br/>
    <label>Full Name *</label>
    <input name="full_name" type="text" >
    <br/>
    <label>Location </label>
    <input name="location" type="text" >
    <br/>
    <label>Gender </label>
    <select name="gender">
  <option>Male</option>
  <option>Female</option>
</select>





  <!-- Ready made validation script, if you want any mandatory fields  (optional) --> 


  <script type="text/javascript">
<!--
function validate()
{
   if( document.myForm.username.value == "" )
   {
     alert( "Please provide your username!" );
     document.myForm.username.focus() ;
     return false;
   }
   if( document.myForm.password.value == "" )
   {
     alert( "Please provide your password!" );
     document.myForm.password.focus() ;
     return false;
   }
    if( document.myForm.email.value == "" )
   {
     alert( "Please provide your full name!" );
     document.myForm.email.focus() ;
     return false;
   }

   if( document.myForm.full_name.value == "" )
   {
     alert( "Please provide your full name!" );
     document.myForm.full_name.focus() ;
     return false;
   }

   return( true );
}
//-->
</script> 

    <br/>
    <button type="submit" class="btn">Signup</button>
  </fieldset>
</form>  
<?php  ?>















<?php include ('footer.php'); ?> 









<?php
//place this code on top of all the pages which you need to authenticate

//--- Authenticate code begins here ---
session_start();
//checks if the login session is true
if(!session_is_registered('username')){
header("location:hp.php");
}
$username = $_SESSION['username'];

// --- Authenticate code ends here ---
?>

<?php include ('header.php'); ?> 

<?php
$document_get = mysql_query("SELECT * FROM users WHERE username='$username'");
$match_value = mysql_fetch_array($document_get);
$fullname = $match_value['fullname'];
$location = $match_value['location'];
$gender = $match_value['gender'];
$email = $match_value['email'];
?>
<br/>

  <a class="btn btn-danger logout" href="logout.php" align="right" > Logout</a> </div>

 <fieldset>
    <legend>Welcome <?php echo $username; ?>, </legend>

    <br/>
    <br/>
<table class="table table-hover" style="border:0;width:50%">
<tr> <td> <b> Full Name:  </b> </td> <td> <?php echo $fullname; ?></td></tr>
<tr><td>  <b> Location:  </b> </td> <td> <?php echo $location; ?></td></tr>
<tr><td>  <b> Gender:  </b> </td> <td> <?php echo $gender; ?></td></tr>
<tr><td>  <b> Email </b> </td> <td> <?php echo $email; ?></td></tr>
</tr>

</table>
 </fieldset>
 <a href="services.php">Go to Your Album</a>

 <script>
 $('.logout').click(function(){
    return confirm("Are you sure you want to Logout?");
})
</script>
<?php include ('footer.php'); ?> 



<?php

include ('config.php'); 

// Getting username and password from login form
$username = $_POST['username']; 
$password = md5($_POST['password']);

// To protect MySQL injection
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM users WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

// Mysql_num_row is to count number of row from the above query
$count=mysql_num_rows($result);

// count is 1 if the above username and password matches
if($count==1){

// now redirect to dashboard page, we also store the username in session for further use in dashboard
session_register("username"); // session checker for pages
$_SESSION['username']= $username; // storing username in session

header("location:dashboard.php");
}

//if the username and password doesn't match redirect to homepage with message=1
else {
    echo '
    <script language="javascript" type="text/javascript">
window.location.href="index.php?message=1";
</script>';

}
?>



<?php

//Connection to the MySQL Server by - tutbuzz.com

define('DB_SERVER', 'localhost'); // Mysql hostname, usually localhost
define('DB_USERNAME', 'root'); // Mysql username
define('DB_PASSWORD', ''); // Mysql password
define('DB_DATABASE', 'phplogin'); // Mysql database name


$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());
?>
0

if possible den please check my code n lemme know,why email address is not getting stored...and i have no idea how to create "photo gallery"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.