I got an HTML-form with a drop-down list of products. When you select a product, you will have a new input field appear. For each product type input fields are different. For example: a book will have a new input field of weight, DVD will have a new input field of size and furniture will have inputs of HxWxL dimensions.
So here is the question: how is it better to submit a form to MySQL with different product types so that they are saved in one table? Without the use of if-else and switch statements.
P.S. I am sorry if this question might be asked before here.
P.S.S. And yes, code/name and price inputs are by default with each new product type.
Here is my database related code:
<?php
$mysqli = new mysqli('localhost', 'root', '', 'things') or die(mysqli_error($mysqli));
if (isset($_POST['save'])) {
$code= $_POST['code'];
$name = $_POST['name'];
$price = $_POST['price'];
$mysqli->query("INSERT INTO products (code, name, price) VALUES('$code', '$name', '$price')") or die($mysqli->error);
And here is my form:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add</title>
<link rel="stylesheet" href="css/add.css">
</head>
<body>
<h1>Add</h1>
<hr>
<?php require_once 'connect.php'; ?>
<div class="container">
<!--FORM-->
<form id="form" action="connect.php" method="POST">
<!--CODE-->
<div id="form-group">
<label for="code" id="code-label"> Code</label>
<input type="text" id="code" name="code" required>
</div>
<!--NAME-->
<div id="form-group">
<label for="name" id="name-label"> Name </label>
<input type="text" id="name" name="name" required>
</div>
<!--PRICE-->
<div id="form-group">
<label for="price" id="price-label"> Price </label>
<input type="number" id="price" name="price" required>
</div>
<div id="form-group">
<label for="product-type" id="product-type-label"> Type Switcher </label>
<select name="product-type" id="product-type" onchange="showHide()">
<option selected hidden value="">Type Switcher</option>
<option value="dvd">DVD</option>
<option value="furniture">Furniture</option>
<option value="book">Book</option>
</select>
</div>-->
<!--HIDDEN INPUTS-->
<div id="size" style="display: none">
<div id="form-group">
<label for="size" id="size-label"> Size </label>
<input type="number" name="size" required>
</div>
</div>
<div id="height" style="display: none">
<div id="form-group">
<label for="height" id="height-label"> Height </label>
<input type="number" name="height" required>
</div>
</div>
<div id="width" style="display: none">
<div id="form-group">
<label for="width" id="width-label"> Width </label>
<input type="number" name="width" required>
</div>
</div>
<div id="length" style="display: none">
<div id="form-group">
<label for="length" id="length-label"> Length </label>
<input type="number" name="length" required>
</div>
</div>
<div id="weight" style="display: none">
<div id="form-group">
<label for="weight" id="weight-label"> Weight </label>
<input type="number" name="weight" required>
</div>
</div>
<button type="submit" name="save">Save</button>
</form>
</div>
<script src="javascript/scripts.js"></script>
</body>
</html>
Related
<div class="form-group col-md-12" style="display:flex;">
<label style="margin-right:10px;">Items<span class="text-danger">*</span></label>
<select style="margin-right:10px;" name="product_id" id="product_id" class="btn btn-primary" type="text">
#foreach ($listitem as $ll)
<option id="itemname" value="{{$ll->id}}">{{$ll->name}} -- {{number_format($ll->price)}}</option>
#endforeach
</select>
<label style="margin-right:10px;">Qty<span class="text-danger">*</span></label>
<input type="number" class="form-control" required name="qty">
</div>
<div class="form-group col-md-12">
<label>Price : </label>
<label for="">{{number_format($ll->price)}}</label>
</div>
How do I get the item dropdown menu id database and I will call it the id for a price where id = id from the value dropdown item name that every time I choose the dropdown item the id will change too so the price will also change depends on the id database from the drop-down menu.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<title></title>
</head>
<body>
<script>
$(document).ready(function (){
$('.selectedOption').on('click',function(){
var price = $(this).find(':selected').data('price');
$('#priceLable').text(price);
})
});
</script>
<div class="form-group col-md-12" style="display:flex;">
<label style="margin-right:10px;">Items<span class="text-danger">*</span></label>
<select style="margin-right:10px;" name="product_id" id="product_id" class="btn btn-primary selectedOption" type="text">
{{-- #foreach ($listitem as $ll)--}}
<option id="itemname" value="1" data-price="100">Name1 -- 100</option>
<option id="itemname" value="2" data-price="150">Name2 -- 150</option>
{{-- #endforeach--}}
</select>
<label style="margin-right:10px;">Qty<span class="text-danger">*</span></label>
<input type="number" class="form-control" required name="qty">
</div>
<div class="form-group col-md-12">
<label>Price : </label>
<label for="" id="priceLable">0</label>
</div>
</div>
</body>
</html>
NOTE: I have hardcoded values you can add them dynamically
First add data-price="{{number_format($ll->price)}}" attribute to options in select
Assign ID to label <label for="" id="priceLable">{{number_format($ll->price)}}</label>
Then write a jQuery code to get value from the data attribute of the selected item and set it to label...
<script>
$(document).ready(function (){
$('.selectedOption').on('click',function(){
var price = $(this).find(':selected').data('price');
$('#priceLable').text(price);
})
});
I am currently implementing an upload the image function on my semester website project. However, the problem I am getting is when I upload an image and proceed to re-upload another image. the images stack on each other and when I refresh it doesn't remove all the images uploaded at all.
Image for Context:
<?php
include 'config.php';
session_start();
if (isset($_POST['submit'])) {
$email = $_POST['email'];
$name = $_POST['name'];
$rating = $_POST['rating'];
$contact = $_POST['contact'];
$category = $_POST['category'];
$feedback = $_POST['feedback'];
$sql = "INSERT INTO feedback(email,name,contact,category,feedback) VALUES('$email','$name','$contact','$category','$feedback')";
$result = mysqli_query($conn, $sql);
if ($result) {
header('location: feedback.php');
}
$sql2 = "INSERT INTO rate(rating) VALUES('$rating')";
$result = mysqli_query($conn,$sql2);
if($result){
header('location: feedback.php');
}
}
if(isset($_POST['upload'])){
$filename = $_FILES['uploadfile']['name'];
$tempname = $_FILES['uploadfile']['tmp_name'];
$folder = "./image/".$filename;
$sql3 = "INSERT INTO image(filename)VALUES('$filename')";
mysqli_query($conn,$sql3);
move_uploaded_file($tempname,$folder);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="feedbackphp.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/rateYo/2.3.2/jquery.rateyo.min.css">
</head>
<body>
<section class="contact">
<div class="container-lg">
<div class="text-center mt-5">
<h2>Feedback Form</h2>
<p class="lead">We Would like to hear your Feedback!</p>
</div>
<div class="row justify-content-center my-5">
<div class="col-lg-6">
<form action="" method="post" enctype="multipart/form-data">
<label for="email" class="form-label">Email Address</label>
<input type="email" name="email" class="form-control" id="email" placeholder="Enter your Email">
<label for="name" class="form-label mt-2">Name</label>
<input type="text" name="name" class="form-control" id="name" placeholder="Enter your Name">
<label for="contact" class="form-label mt-2">Contact</label>
<input type="text" name="contact" class="form-control" id="contact" placeholder="Enter your Contact">
<label for="subject" class="form-label mt-2">Category</label>
<select class="form-select" name="category" id="subject">
<option value="">Select One</option>
<option value="Club Maintainence & Equipment">Club Maintainence & Equipment </option>
<option value="Club Cleanliness">Club Cleanliness</option>
<option value="Membership Issues">Membership Issues</option>
<option value="General/Others">General/Others</option>
</select>
<label for="rating" class="form-label mt-2">Rate Us!</label>
<div class="rateyo" id="rating"
data-rateyo-rating="0"
data-rateyo-num-stars="5"
data-rateyo-score="3">
</div>
<span class="result">0</span>
<input type="hidden" name="rating">
<br>
<label for="query" class="form-label mt-2">Feedback Message </label>
<textarea id="query" name="feedback" class="form-control" style="height:140px" placeholder="Enter Feedback Message here..."></textarea>
<label class="form-label mt-2">Upload File</label>
<div class="form-group mt-2">
<input class="form-control" type="file" name="uploadfile">
</div>
<br>
<div class="form-group">
<button class="btn btn-primary" type="submit" name="upload">Upload</button>
</div>
<div id="display-image">
<?php
$query = "SELECT * FROM image";
$result = mysqli_query($conn,$query);
while($data = mysqli_fetch_assoc($result)){
?>
<img src="./image/<?php echo $data['filename'];?>">
<?php
}
?>
</div>
<div class="mb-4 text-center mt-2">
<button type="submit" name="submit" class="btn btn-primary">Submit Feedback</button>
</div>
</form>
</div>
</div>
</div>
</section>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rateYo/2.3.2/jquery.rateyo.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src="fbphp.js" type="text/javascript"></script>
</body>
</html>
You are selecting all images
$query = "SELECT * FROM image LIMIT 1";
Use the query about to set a limit to 1;
then using this will prevent you from using the while loop
Hope this will help
I'm trying to write a php script that takes the input from this form and creates an array with a unique key for each input box/text boxes content.
<div class="container">
<div class="row">
<div class="col-3 mx-auto">
<form action="adminhandler.php">
<div class="form-group">
<label for="product name">Enter product name</label>
<input type="text" class="form-control" id="productName" aria-describedby="emailHelp" placeholder="" name="productname">
</div>
<div class="form-group">
<label for="product name">Select product category</label>
<select name="select" class=" custom-select">
<option selected>Open this select menu</option>
<option value="1">Formal Shoes</option>
<option value="2">Sneakers</option>
<option value="3">Tracksuits</option>
<option value="3">Clothing</option>
<option value="3">Accessories</option>
</select>
</div>
<div class="form-group">
<label for="product price">Enter product price(Naira)</label>
<input type="text" class="form-control" id="productPrice" aria-describedby="emailHelp" placeholder="" name="price">
</div>
<div class="form-group">
<label for="product name">Select image</label>
<input type="file" class="form-control-file" id="productimage" aria-describedby="emailHelp" placeholder="">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
I think you want to use a form as an array and then pass the same data as an array.If you are using the $_POST, you will need to use the name attribute of HTML. And use something like this :
<input name="person[1][first_name]" value="jane" />
This when passing through PHP will be sent as Array.
Here is the reference :
http://php.net/manual/en/reserved.variables.post.php
An Excerpt from one of the contributors :
<form>
<input name="person[0][first_name]" value="john" />
<input name="person[0][last_name]" value="smith" />
<input name="person[1][first_name]" value="jane" />
<input name="person[1][last_name]" value="jones" />
</form>
When Trying To Process Values using PHP
<?php
var_dump($_POST['person']);
//will get you something like:
array (
0 => array('first_name'=>'john','last_name'=>'smith'),
1 => array('first_name'=>'jane','last_name'=>'jones'),
)
?>
When i click on Add buttton it adds the dropdown selected text to the bottom textbox. and again when i change the value of dropdown and click on add. It rewrites the in textbox. I want to concatenate with previous value of the textbox with comma saparated whenever i click on add
Im new to php.
<?php
if(isset($_POST["in_submit"]))
{
$i1=$_POST['name'];
$i2=$_POST['dose'];
$i3 = $i1."*".$i2;
}
?>
<html>
<head>
<title>
</title>
</head>
<body>
<form action="#" class="form-horizontal" method="post" accept-charset="utf-8">
<label for="inputEmail3" class="col-md-4 control-label">Name</label>
<select name="name" class="form-control" style="width:30%;">
<option value="Select">--SELECT--</option>
<option value="abc">abc</option>
<option value="def">def</option>
</select>
<input type="text" name="dose" value="" class="form-control"/>
<div class="col-sm-2">
<input type="submit" name="in_submit" value="Add" class="btn-danger" style="height:30px;width:60px;padding-top:2px;border-radius:5px"/>
</div>
</form>
<div class="col-sm-7">
<input type="text" name="text" value="<?php if(isset($i3)){ echo $i3;}?>" class="form-control" readonly />
</div>
</body>
</html>
Is because $i2=$_POST['dose']; is always empty
value="<?php if(isset($i3)){ echo $i3;}?>"
should be part of dose
After some changes You don't need to use dose you can concatenate like this -> if you get the solution then vote up.
<?php
if(isset($_POST["in_submit"]))
{
$i1=$_POST['name'];
$i2=$_POST['text'];
if($i2!=''){
$i3 = $i2.",".$i1;
}else{
$i3 = $i1;
}
}
?>
<html>
<head>
<title>
</title>
</head>
<body>
<form action="#" class="form-horizontal" method="post" accept-charset="utf-8">
<label for="inputEmail3" class="col-md-4 control-label">Name</label>
<select name="name" class="form-control" style="width:30%;">
<option value="Select">--SELECT--</option>
<option value="abc">abc</option>
<option value="def">def</option>
</select>
<div class="col-sm-2">
<input type="submit" name="in_submit" value="Add" class="btn-danger" style="height:30px;width:60px;padding-top:2px;border-radius:5px"/>
</div>
<div class="col-sm-7">
<input type="text" name="text" value="<?php if(isset($i3)){ echo $i3;}?>" class="form-control" readonly />
</div>
</form>
</body>
</html>
Iam creating a page. The sign up works fine and takes me to home page but after logging out and trying to login again. The login button redirects me back to the registration page.
Please Help! I have checked through over and over and cant find any error.
login.php
<?php
if(isset($_POST['Login']))
{error_reporting(1);
$connection = mysqli_connect('localhost','root','','uni-saga');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$user=$_POST['username'];
$pass=$_POST['password'];
$que1=mysqli_query($connection,"select * from users where Email='$user' and Password='$pass'");
$count1=mysqli_num_rows($que1);
if($count1>0)
{
session_start();
$_SESSION['tempsagauser']=$user;
$que6=mysqli_query("select * from users where Email='$user'");
$rec6=mysqli_fetch_array($que6);
$userid=$rec6[0];
$que2=mysqli_query($connection,"select * from user_profile_pic where user_id=$userid");
$count2=mysqli_num_rows($que2);
if($count2>0)
{
$que3=mysqli_query($connection,"select * from user_secret_quotes where user_id=$userid");
$count3=mysqli_num_rows($que3);
if($count3>0)
{
$que4=mysqli_query($connection,"select * from user_secret_quotes where user_id=$userid");
while($rec=mysqli_fetch_array($que4))
{
$que2=$rec[3];
$ans2=$rec[4];
}
if($que2=="" && $ans2=="")
{
header("location:saga_files/saga_step/saga_step3/Secret_Question2.php");
}
else
{
session_start();
$_SESSION['sagauser']=$user;
$query1=mysqli_query($connection,"select * from users where Email=$user");
$rec1=mysqli_fetch_array($query1);
$userid=$rec1[0];
mysqli_query($connection,"update user_status set status='Online' where user_id='$userid'");
header("location:saga_files/saga_home/Home.php");
}
}
else
{
header("location:saga_files/saga_step/saga_step2/Secret_Question1.php");
}
}
else
{
while($rec=mysqli_fetch_array($que1))
{
$Gender=$rec[4];
}
if($Gender=="Male")
{
header("location:saga_files/saga_step/saga_step1/Step1_Male.php");
}
else
{
header("location:saga_files/saga_step/saga_step1/Step1_Female.php");
}
}
}
else
{
$que5=mysqli_query($connection,"select * from users where Email='$user'");
$count5=mysqli_num_rows($que5);
if($count5>0)
{
header("location:Invalid_Password.php");
}
else
{
header("location:Invalid_Username.php");
}
}
}
?>
index.php
<?php
include("Login.php");
include("saga_files/saga_index_file/saga_SignUp_file/SignUp.php");
?>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>UniSaga</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/ionicons.min.css" />
<link rel="stylesheet" href="css/font-awesome.min.css" />
<!--Google Font-->
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,400i,700,700i" rel="stylesheet">
<!--Favicon-->
<link rel="shortcut icon" type="image/png" href="images/fav.png"/>
</head>
<script>
function time_get()
{
d = new Date();
mon = d.getMonth()+1;
time = d.getDate()+"-"+mon+"-"+d.getFullYear()+" "+d.getHours()+":"+d.getMinutes();
}
</script>
<header id="header-inverse">
<nav class="navbar navbar-default navbar-fixed-top menu">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index-register.html"><img src="images/logo.png" alt="logo" /></a>
</div>
</div>
</nav>
</header>
<div id="lp-register">
<div class="container wrapper">
<div class="row">
<div class="col-sm-5">
<div class="intro-texts">
<h1 class="text-white">UniSaga</h1>
<p>Connect With Students from other Your University and Other Universities and get the latest news on what is Happening Around these learning Institutions. <br /> <br />What Are You Waiting For. Join Now And Experience It Like Never Before.</p>
</div>
</div>
<div class="col-sm-6 col-sm-offset-1">
<div class="reg-form-container">
<div class="reg-options">
<ul class="nav nav-tabs">
<li class="active">Register</li>
<li>Login</li>
</ul><!--Tabs End-->
</div>
<!--Registration Form Contents-->
<div class="tab-content">
<div class="tab-pane active" id="register">
<h3>Register Now !!!</h3>
<p class="text-muted">Its Free and Always Will Be.</p>
<!--Register Form-->
<form method="post" name="registration_form" id='registration_form' class="form-inline">
<div class="row">
<div class="form-group col-xs-6">
<label for="first_name" class="sr-only">First Name</label>
<input id="first_name" class="form-control input-group-lg" type="text" name="first_name" title="Enter first name" placeholder="First name"/>
</div>
<div class="form-group col-xs-6">
<label for="last_name" class="sr-only">Last Name</label>
<input id="last_name" class="form-control input-group-lg" type="text" name="last_name" title="Enter last name" placeholder="Last name"/>
</div>
</div>
<div class="row">
<div class="form-group col-xs-12">
<label for="email" class="sr-only">Email</label>
<input id="email" class="form-control input-group-lg" type="text" name="email" title="Enter Email" placeholder="Your Email"/>
</div>
<div class="form-group col-xs-12">
<label for="remail" class="sr-only">Re-Enter Email</label>
<input id="remail" class="form-control input-group-lg" type="text" name="remail" title="Enter Email" placeholder="Re-Enter Your Email"/>
</div>
</div>
<div class="row">
<div class="form-group col-xs-12">
<label for="password" class="sr-only">Password</label>
<input id="password" class="form-control input-group-lg" type="password" name="password" title="Enter password" placeholder="Password"/>
</div>
</div>
<div class="row">
<p class="birth"><strong>Date of Birth</strong></p>
<div class="form-group col-sm-3 col-xs-6">
<label for="month" class="sr-only"></label>
<select name="day" class="form-control" id="Day">
<option value="Day" disabled selected>Day</option>
<script type="text/javascript">
for(i=1;i<=31;i++)
{
document.write("<option value='"+i+"'>" + i + "</option>");
}
</script>
</select>
</div>
<div class="form-group col-sm-3 col-xs-6">
<label for="month" class="sr-only"></label>
<select name="month" class="form-control" id="Month">
<option value="Month" disabled selected>Month</option>
<script type="text/javascript">
var m=new Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
for(i=1;i<=m.length-1;i++)
{
document.write("<option value='"+i+"'>" + m[i] + "</option>");
}
</script>
</select>
</div>
<div class="form-group col-sm-6 col-xs-12">
<label for="year" class="sr-only"></label>
<select name="year" class="form-control" id="Year">
<option value="Year" disabled selected>Year</option>
<script type="text/javascript">
for(i=2000;i>=1960;i--)
{
document.write("<option value='"+i+"'>" + i + "</option>");
}
</script>
</select>
</div>
</div>
<div class="form-group gender">
<select name="sex" style="width:120;height:35;font-size:18px;padding:3;">
<option value="Select Sex:"> Select Sex: </option>
<option value="Female"> Female </option>
<option value="Male"> Male </option>
</select>
</div>
<div class="row">
<div class="form-group col-xs-6">
<label for="campus" class="sr-only">Campus</label>
<input id="campus" class="form-control input-group-lg reg_name" type="text" name="campus" title="Enter campus" placeholder="Your campus"/>
</div>
<div class="form-group col-xs-6">
<label for="county" class="sr-only"></label>
<select name="county" class="form-control" id="county">
<option value="county" disabled selected>County</option>
<option value="Baringo">Baringo</option>
<option value="Bomet">Bomet</option>
<option value="Bungoma">Bungoma</option>
<option value="Busia">Busia</option>
<option value="Elgeyo">Elgeyo Marakwet</option>
<option value="Embu">Embu</option>
<option value="Garissa">Garissa</option>
<option value="Homa">Homa Bay</option>
<option value="Isiolo">Isiolo</option>
<option value="Kajiado">Kajiado</option>
<option value="Kakamega">Kakamega</option>
<option value="Kericho">Kericho</option>
<option value="Kiambu">Kiambu</option>
<option value="Kilifi">Kilifi</option>
<option value="Kirinyaga">Kirinyaga</option>
<option value="Kisii">Kisii</option>
<option value="Kisumu">Kisumu</option>
<option value="Kitui">Kitui</option>
<option value="Kwale">Kwale</option>
<option value="Laikipia">Laikipia</option>
<option value="Lamu">Lamu</option>
<option value="Machakos">Machakos</option>
<option value="Makueni">Makueni</option>
<option value="Mandera">Mandera</option>
<option value="Meru">Meru</option>
<option value="Migori">Migori</option>
<option value="Marsabit">Marsabit</option>
<option value="Mombasa">Mombasa</option>
<option value="Muranga">Muranga</option>
<option value="Nairobi">Nairobi</option>
<option value="Nakuru">Nakuru</option>
<option value="Nandi">Nandi</option>
<option value="Narok">Narok</option>
<option value="Nyamira">Nyamira</option>
<option value="Nyandarua">Nyandarua</option>
<option value="Nyeri">Nyeri</option>
<option value="Samburu">Samburu</option>
<option value="Siaya">Siaya</option>
<option value="Taita">Taita Taveta</option>
<option value="Tana">Tana River</option>
<option value="Tharaka">Tharaka Nithi</option>
<option value="Trans">Trans Zoia</option>
<option value="Turkana">Turkana</option>
<option value="Uasin">Uasin Gishu</option>
<option value="Vihiga">Vihiga</option>
<option value="Wajir">Wajir</option>
<option value="West">West Pokot</option>
</select>
</div>
</div>
<button type="submit" name="signup" id="sign_button" class="btn btn-primary" / onClick="time_get()" >Register Now</button>
</form>
</div>
<div class="tab-pane" id="login">
<h3>Login</h3>
<p class="text-muted">Log into your account</p>
<!--Login Form-->
<form method="post" name="Login_form" id='Login_form'>
<div class="row">
<div class="form-group col-xs-12">
<label for="my-email" class="sr-only">Email</label>
<input id="my-email" class="form-control input-group-lg" type="text" name="username" title="Enter Email" placeholder="Your Email"/>
</div>
</div>
<div class="row">
<div class="form-group col-xs-12">
<label for="my-password" class="sr-only">Password</label>
<input id="my-password" class="form-control input-group-lg" type="password" name="password" title="Enter password" placeholder="Password"/>
</div>
</div>
<p>Forgot Password</p>
<button name="Login" id="login_button" class="btn btn-primary">Login Now</button>
</form><!--Login Form Ends-->
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-sm-offset-6">
<!--Social Icons-->
<ul class="list-inline social-icons">
<li><i class="icon ion-social-facebook"></i></li>
<li><i class="icon ion-social-twitter"></i></li>
<li><i class="icon ion-social-googleplus"></i></li>
<li><i class="icon ion-social-pinterest"></i></li>
<li><i class="icon ion-social-linkedin"></i></li>
</ul>
</div>
</div>
</div>
</div>
<!--preloader-->
<div id="spinner-wrapper">
<div class="spinner"></div>
</div>
<!-- Scripts
================================================= -->
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.appear.min.js"></script>
<script src="js/jquery.incremental-counter.js"></script>
<script src="js/script.js"></script>
</body>
</html>
<?php
include("saga_files/saga_index_file/saga_erorr_file/saga_erorr.php");
?>
</body>
</html>
1) Your session doesn't preserve its state, e.g. it's closed immediately after your login.php page finished processing. That happens because you're calling session_start() inside your code in login.php. So, you must move your session_start() to the first line in login.php. No code should reside before it.
And use it ONLY ONCE! (You use session_start twice)
See: PHP session for tracking unique page views
2) Also: Login_form needs an action attribute (login.php). Otherwise the form is posted to the page were it resides, e.g to index.php. So:
<form method="post" action="login.php" name="Login_form" id="Login_form">
3) And there is a typo here (/):
<button type="submit" name="signup" id="sign_button" class="btn btn-primary" / onClick="time_get()" >Register Now</button>
Good luck.