Jump to content

retreiving data from loginpage and storing in database


mee

Recommended Posts

hi,

I have created a login page this is my code

<?php

if (!isset($_SESSION)) {

session_start();

}

 

$host="localhost"; // Host name

$username="root"; // Mysql username

$password=""; // Mysql password

$db_name="Marketing"; // Database name

$tbl_name="Marketinglogin"; // Table name

 

 

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

$myusername=$_POST['myusername'];

$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)

$myusername = stripslashes($myusername);

$mypassword = stripslashes($mypassword);

$myusername = mysql_real_escape_string($myusername);

$mypassword = mysql_real_escape_string($mypassword);

 

$sql="SELECT * FROM Marketinglogin WHERE username='$myusername' and password='$mypassword'";

$result=mysql_query($sql);

 

// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row

 

if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"

session_register("myusername");

session_register("mypassword");

if ($myusername == "sandeep") {

header("location:Marketingadmin.php");

} else {

header("location:Marketingemployeeform.php");

}

}

else

{

echo "wrong password";

}

?>

Marketingemployee form has some fields..here when we click submit button all the fields as well as the loginusername has to be stored in the database

 

<?php

if (!isset($_SESSION)) {

session_start();

}

 

$con = mysql_connect("localhost","root", "");

if (!$con)

{die('Could not connect to DB: ' . mysql_error() );}

mysql_select_db ("Marketing", $con);

$date = $_POST['year'].$_POST['month'].$_POST['dt'] ;

$_SESSION['myusername']=$_POST['myusername'];

$myusername=$_SESSION['myusername'];

$sql="INSERT INTO Marketingemployeetable (Employeeid, Date,Sector,Place,Contactpersonname,Contactaddress,Mobileno)VALUES ( '$myusername','$date','$_POST[project]','$_POST[place]','$_POST[Contactpersonname]','$_POST[Contactaddress]','$_POST[Mobileno]')";

if (!mysql_query($sql,$con))

{die ('Error: ' . mysql_error());}

echo "Record added";

mysql_close($con)?>

 

please help me out here

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.