39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
error_reporting(E_ERROR);
|
|
$host="localhost"; // Host name
|
|
$username="root"; // Mysql username
|
|
$password=""; // Mysql password
|
|
$db_name="scdb"; // Database name
|
|
$tbl_name="members"; // 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");
|
|
|
|
// username and password sent from signup form
|
|
$myusername=$_POST['myusername'];
|
|
$mypassword=$_POST['mypassword'];
|
|
|
|
$sql="SELECT * FROM $tbl_name 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 "grower-main.php"
|
|
$_SESSION['myusername']="myusername";
|
|
$_SESSION['mypassword']="mypassword";
|
|
header("location:../growers/$myusername/mobile.php");
|
|
}
|
|
else {
|
|
$errorMessage = 'Sorry, wrong user id / password';
|
|
}
|
|
?>
|
|
|
|
<form name="form1" method="post" action="">
|
|
<p><input type="text" name="myusername" id="myusername" placeholder=" Grower ID"></p>
|
|
<p><input type="password" name="mypassword" id="mypassword" placeholder=" Password"></p>
|
|
<p class="submit"><input type="submit" name="Submit" value="Login"></p>
|
|
</form>
|