To get record of two dates - php

I want two dates if I post start date and end date from submit form. I have attendance record table. I want to retrieve this table. How can I do that?
This is my code. It redirects to test.php. How can I retrieve another page? Who can help me kindly?
<form method="post" class="form-horizontal" role="form" action="test.php">
<!--Start Date-->
<div class="col-lg-12">
<div class="form-group required">
<label for="startdate" class="control-label">Start Date:</label>
<input class="form-control" placeholder="Choose Date " type="text" id="datepicker-8" name="startdate" required="required" />
</div>
</div>
<!--End Date-->
<div class="col-lg-12">
<div class="form-group required">
<label for="enddate" class="control-label">End Date:</label>
<input class="form-control" placeholder="Choose Date " type="text" id="datepicker-9" name="enddate" required="required" />
</div>
</div>
<!--Create Button-->
<div class=""> <br/>
<input class="btn btn-success" type="submit" value="Search" />
</div>
</form>

You need to first get both start date and end date in vairable using $_REQUEST like that way.
$start_data = $_REQUEST['startdate'];
$end_data = $_REQUEST['enddate'];
Now you need to use sql query to fetch data from table :
$query = mysql_query("select * from table_name where startdate='$start_data' AND enddate='$end_data'");
while($row=mysql_fetch_array($query)) {
// Print your variable here
}

in test.php:
<?php
var_dump($_POST);
Then submit your form. You will see all the fields and values that were contained in the form. You can access individual fields like so: $startdate = $_POST['startdate']
Good luck!

When you click the submit button the page will be redirected to test.php file, the content which you will write in test.php will be shown. Now to retrieve date from post u can use $startdate=$_POST['startdate'] simillarly for $enddate=$_POST['enddate']. After this use queries to fetch the data from database using the startdate and enddate variable

Related

datepicker problem on passing value when submit for second time

i have an issue on passing value thru datepicker. i have an appointment system which i use datepicker. i need to get the date and pass the value (on the same page) to my query and check it with my mysql database whether the date available or not. First pick date is ok and it send the right value, but when i try pick another date and submit it, it passing the first date that i choose. Is anyone know what is the problem?
<?php
if (isset($_POST['check']))
{
$appdate = $_POST['appdate'];
}
?>
<form method="post" enctype="multipart/form-data" id="form" name="form">
<div class="form-group row">
<div class="col-md-6">
<label for="jenis">Date Appointment</label>
<input name="appdate" readonly="readonly" id= "appdate" type="text" class="form-control datepicker" data-format="dd-mm-yyyy" data-lang="en" data-RTL="false">
<span class="help-block" id="error" style="color:red"></span>
</div>
<div class="col-md-6">
<label for="jenis"> <br></label>
<input type="submit" name="check" id="check" value="Check" class="btn btn-3d btn-pink"/>
</div>
</div>
<?php
if (isset($_POST['check']))
{
$appdate = $_POST['appdate'];
?>
<div>
<p><?php echo $appdate; ?></p>
</div>
<?php
}
?>
</form>

Remove null variables from url

I have this form, when I press the submit button i will get redirected to select.inc.php.
But sometimes I dont want to fill out every field of the form but all the "variables"(?) are still getting appended to the URL.
When I only enter an id and will press the button the url will look like this: localhost/inc/select.inc.php?id=1?username=?email=?password=?rank=.
What I want is this: localhost/inc/select.inc.php?id=1
<form action="inc/select.inc.php" method="GET">
<h1 id="h1-select">Select</h1>
<div class="row">
<input type="text" name="id" placeholder="Id">
</div>
<div class="row">
<input type="text" name="username" placeholder="Username">
</div>
<div class="row">
<input type="text" name="email" placeholder="E-Mail">
</div>
<div class="row">
<input type="password" name="password" placeholder="Password">
</div>
<div class="row">
<input type="text" name="rank" placeholder="Rank">
</div>
<div class="row">
<button type="submit" name="submit">Select</button>
</div>
</form>
I want this to show stuff from the MySQL database on a page like when I want to list all users with the rank "1".
If you want to remove all empty strings (you get them as empty strings, not null), you can run $_GET through array_filter():
$_GET = array_filter($_GET, function ($val) {
return $val !== '';
});
Now the $_GET-param will only contain non empty strings.
If you don't need to keep 0 either, you can just do:
$_GET = array_filter($_GET);
That removes any param where the value is falsy

duplicate record insert on page refresh php

Whenever I entered value first time and add record its added perfectly but whenever I refresh my browser by pressing F5 it shows message
"the page that you're looking for used information that you entered..." and insert duplicate record.
HTML code define below:
<?php include("Connection.php"); ?>
<form role="form" method="post">
<div class="col-md-6">
<div class="form-group">
<label>Type Name</label>
<input name="emptype" class="form-control" placeholder="Employee ID">
</div>
<div class="form-group">
<label>Type Description</label>
<input name="typedecs" class="form-control" placeholder="First Name">
</div>
</div>
<div class="col-md-12 text-right">
<button type="submit" name="addtype" class="btn btn-primary">Add Type</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</form>
below is my PHP Code
<?php
$emptype=$_POST['emptype'];
$typedesc=$_POST['typedecs'];
if(isset($_POST['addtype']))
{
$query=mysql_query("insert into emptype(typename,typedesc)values('$emptype','$typedesc')")or die("<script>alert('Error');</script>");
echo '<script>showAlert();window.setTimeout(function () {HideAlert();},3000);</script>';
Does something i missing? Please Help.
suggestion: use mysqli_* or PDO instead of mysql_* functions, but you have written code in it so i gave the code also in it.
Just run a select query to check if the record already exists in database if exists then do not insert it again.
$query=mysql_query("SELECT * FROM emptype WHERE typename = '$emptype' AND typedesc='$typedesc') or die(mysql_error());
if (mysql_num_rows($query)<=0)
{
$query=mysql_query("insert into emptype(typename,typedesc)values('$emptype','$typedesc')")or die("<script>alert('Error');</script>");
}
One option could be to Test if the value is already in your database.
Source : example from PHP.net - mysql_query
// Formulate Query
// This is the best way to perform an SQL query
// For more examples, see mysql_real_escape_string()
$query = sprintf("SELECT * FROM emptype
WHERE typename='%s' AND typedesc='%s'",
mysql_real_escape_string($emptype),
mysql_real_escape_string($typdesc));
// Perform Query
$result = mysql_query($query) or die(mysql_error());
// Get num rows
$num_rows = mysql_num_rows($result);
// If $num_rows is False - It's not a duplicate
if(!$num_rows)
...
Consider using PDO PHP.net - PDO - mysql functions are depreciated.
i think it is because the php script (insert query) is at the same page of the HTML form, so when you refresh the page you tell the browser to call the php script again with previous data. so to prevent that separate the HTML form from the php so you code should be like:
1- HTML.php
<?php include("Connection.php"); ?>
<form role="form" method="post" action="Action.php">
<div class="col-md-6">
<div class="form-group">
<label>Type Name</label>
<input name="emptype" class="form-control" placeholder="Employee ID">
</div>
<div class="form-group">
<label>Type Description</label>
<input name="typedecs" class="form-control" placeholder="First Name">
</div>
</div>
<div class="col-md-12 text-right">
<input type="submit" value="submit">
</div> </form>
2- Action.php
<?php include("Connection.php");
$emptype=$_POST['emptype'];
$typedesc=$_POST['typedecs'];
if(isset($_POST['addtype']))
{
$query=mysql_query("insert into emptype(typename,typedesc)values('$emptype','$typedesc')")or die("<script>alert('Error');</script>");
echo '<script>showAlert();window.setTimeout(function () {HideAlert();},3000);</script>'; echo "<meta http-equiv='refresh' content='0;url=html.php'>";
?>
this will make html.php page call Action.php page when the submit button is pressed then the php script will be executed then it will redirect you to the html.php page again

php form submit in div fails

after many days of trying to get a previously working php form converted to submitting the variables inside a new div I realized that I'm missing something. Other posts show javascript, but Iv'e never used that before and don't understand the need. The new page draws correctly, but the php variables are not being received on the destination page.
HTML for the submit,
<form action="entrance2.php">
<div class="medium-12 columns m-b20"><h4 class="heading">Existing users log-in here :-</h4></div>
</div>
<div class="row">
<div class="user medium-12 columns text-center m-b15"><img src="images/user-img.png" alt=""/></div>
</div>
<div class="row">
<div class="medium-10 columns medium-offset-1"><label for="User Name"></label>
<input id="OwnerEmaili" type="text" placeholder="User Name" name="UserName"></div>
</div>
<div class="row">
<div class="medium-10 columns medium-offset-1"><label for="Password"></label>
<input id="OwnerPasswordi" type="password" placeholder="Password" name="Password"></div>
</div>
<div class="row">
<div class="medium-12 columns text-center"><button class="grd-button">Log In</button></div>
<input type="submit" id="save" name="save" value = "Submit"/>//simple submit for testing
<div class="grd-button1" onClick="document.forms['submit-form'].submit();"></div>
</form></div>
</div>
</div>
Receiving page,
<?php
$p_OwnerEmaili=$_POST["OwnerEmaili"];
$p_OwnerPasswordi=$_POST["OwnerPasswordi"];
echo "$p_OwnerEmaili;$p_OwnerPasswordi";
Only shows the ;.
Is javascript required to submit from inside a div?
You're accessing the wrong items.
You'll need to set your forms input name attributes to this if you want to access them the way you currently have in your php script:
<input id="OwnerEmaili" type="text" placeholder="User Name" name="OwnerEmaili">
And
<input id="OwnerPasswordi" type="password" placeholder="Password" name="OwnerPasswordi">
That will allow you to access them as you do in your PHP script.
You can always check what values have been sent to your php script by using var_dump() or print_r().
<?php print_r($_POST); ?>
Would've shown you that you had UserName & Password set instead of what you wanted.
As Ghost pointed out in the comments, your form will always send user input via GET if you dont specify a method in it. So set this in your form tag:
<form action="entrance2.php" method="post">

PHP Multiple GET methods in one your

I'm making a tool to pull eve API data and I use a GET form to take the data and get access to the key ID and code to access the data. This then pulls the first character ID on the key and grabs all that character data.
for example the url is:
whatever.com/APIChecker/?keyID=123456&code=ABCDEFGHIJKL
I pull these variables out via the session variables that they create.
What I'm now trying to do is now have a for loop which puts up buttons for each character on the key so you can flick between characters, I'm trying and have tried get and post methods hidden in the button but can't seem to get my desired result. It seems to not be taking out the variable that i'm trying to pass and adding it into the $_SESSION array or the $_POST or the $_GET - i've tried print_r on all these variables but I can't get any output.
Here is my primary form thats on my main page:
<form method="get" action="APIChecker/" >
<legend> Submit an API Key</legend>
<div class="control-group">
<label class="control-label">Key ID:</label>
<div class="controls">
<input type="text"
class="input-small"
name="keyID""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Verification Code:</label>
<div class="controls">
<input type="text"
class="input-xxlarge"
name="vCode"
/>
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Submit API</button>
</div>
</div>
What I'm trying to do now is get another session variable from another page - which updates a variable and refreshes the page with the keyID and code unaltered.
As in:
whatever.com/APIChecker/?keyID=123456&code=ABCDEFGHIJKL **&charID=654321**
so $_SESSION['keyID'] = 123456
& $_SESSION['code'] = ABCDEFGHIJKL
& $_SESSION['charID'] = 654321
what I've tried is:
<form method="get" action="" >
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">
<input type="hidden"
name="charID"
value="$charID"
/>
</button>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Submit API</button>
</div>
</div>
</form>
You can't output PHP values directly in HTML like this: value="$charID"
Try this instead:
value="<?php echo $charID; ?>"

Categories