I have a very mysterious problem make every <form method="POST"> not working on a single file, for x reason the POST method get transformed into a GET method making the form element useless. I don't know if it's authorized but i make a video about this "problem" here since no one really understand what i'm meanning.
If you have potential idea why it is working on the test folder but not on the admin folder even if both code are the same please let me know it.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="POST" action="php/SetSanction.php">
<div>
<div>
<div>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;">
<div class="form-group">
<label for="daySelect">Day:</label>
<select class="form-control" name="daySelect" id="daySelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>
<div class="form-group">
<label for="monthSelect">Month:</label>
<select class="form-control" name="monthSelect" id="monthSelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>
<div class="form-group">
<label for="yearSelect">Year:</label>
<select class="form-control" name="yearSelect" id="yearSelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>
</div>
</div>
<div>
<label>Reason</label>
<textarea name="reasonInput" id="reasonInput" class="form-control" placeholder="..." rows="3" maxlength="400"></textarea>
</div>
</div>
<div class="modal-footer">
<input type="submit" value="Set">
</div>
</div>
</form>
</body>
</html>
And the PHP File (SetSanction.php)
<?php
print_r($_POST); // THIS ARRAY SHOULD BE EMPTY BECAUSE POST NOT WORKING
if ($_SERVER['REQUEST_METHOD'] === 'POST') /*NOT WORK BECAUSE IT'S NOT POST REQ*/ {
$daySelected = $_POST['daySelect'];
$monthSelected = $_POST['monthSelect'];
$yearSelected = $_POST['yearSelect'];
$reasonInput = $_POST['reasonInput'];
echo "Day: " . $daySelected . "<br>";
}
If you are rewriting the urls to remove the extensions, this will break the form because the form action won't be a valid url.
Best option would be to exclude the form action url / file from the .htaccess file.
Something like this in your case:
RewriteCond %{REQUEST_URI} !^/php/SetSanction\.php$
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 days ago.
Improve this question
I keep searching why when i use <form method="post"> it's not making a POST request, name="" of all elements called in the PHP file are all defined correctly and the post array is empty, it told me it's not making post request. Since this is non-sence error with no answer, i make this question.
So here my HTML (PS: i never used element so sorry if i'm wrong on that)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="POST" action="php/SetSanction.php">
<div>
<div>
<div>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;">
<div class="form-group">
<label for="daySelect">Day:</label>
<select class="form-control" name="daySelect" id="daySelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>
<div class="form-group">
<label for="monthSelect">Month:</label>
<select class="form-control" name="monthSelect" id="monthSelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>
<div class="form-group">
<label for="yearSelect">Year:</label>
<select class="form-control" name="yearSelect" id="yearSelect">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
</select>
</div>
</div>
</div>
<div>
<label>Reason</label>
<textarea name="reasonInput" id="reasonInput" class="form-control" placeholder="..." rows="3" maxlength="400"></textarea>
</div>
</div>
<div class="modal-footer">
<input type="submit" value="Set">
</div>
</div>
</form>
</body>
</html>
And SetSanction php file
<?php
print_r($_POST); // THIS ARRAY SHOULD BE EMPTY BECAUSE POST NOT WORKING
if ($_SERVER['REQUEST_METHOD'] === 'POST') /*NOT WORK BECAUSE IT'S NOT POST REQ*/ {
$daySelected = $_POST['daySelect'];
$monthSelected = $_POST['monthSelect'];
$yearSelected = $_POST['yearSelect'];
$reasonInput = $_POST['reasonInput'];
echo "Day: " . $daySelected . "<br>";
}
So I have this code that creates a drop down box to select a month, another drop down box to select the day, then a text field to type in a year. My question is what to do next in php to be able to select a certain month, day, and year to where, when i click "calculate," it will display what day of that year it is?
So for example, if i choose January 4 2015, when i click calculate, i want it to display 4 since it is the 4th day of the calendar year. How do I do that?
<form action="calc.php" method="post">
Month: <select name="month">
<option value="january">January</option>
<option value="february">February</option>
<option value="march">March</option>
<option value="april">April</option>
<option value="may">May</option>
<option value="june">June</option>
<option value="july">july</option>
<option value="august">August</option>
<option value="september">September</option>
<option value="october">October</option>
<option value="november">November</option>
<option value="december">December</option>
</select>
Day: <select name="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input name="entry" type="text" size="10" placeholder="Year">
<input type="submit" value="Calculate">
</form>
You can use date:
echo date("z", strtotime('2015-01-04'));
But it returns:
The day of the year (starting from 0)
So you need to add 1 to the result.
you can try the below code to get the day of the date . here i am using the same page for the post. if you are using another page for posting (i mean action page) use the php inside that file,
HTML
<form action="#" method="post">
Month: <select name="month">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">july</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
Day: <select name="day">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input name="year" type="text" size="10" placeholder="Year">
<input type="submit" name="submit" value="Calculate">
</form>
PHP
<?php
if(isset($_POST['submit']))
{
$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
echo date("l", strtotime($date));
}
?>
I'm having trouble getting my form's post data to come through. As this code stands, the file uploads, but I don't have any post data for the other form fields. I noticed that if I get rid of multipart/form-data enctype, it will not upload (obviously) but I DO get the post data to come through for the other fields. Any ideas on why this is?
The page where this code occurs is index.php?page=page1&upload=1
<form enctype="multipart/form-data" action="?page=page1&upload=2" method="post">
Select Location: <select name="location">
<option>Select Location</option>
<option value="N">North</option>
<option value="S">South</option>
<option value="E">East</option>
<option value="W">West</option>
</select><br />
Upload File: <input name="ufile" type="file" id="ufile" size="50" /><br />
<b><u>Sunday</u></b> Date: <select name="month">
<option> - Month - </option>
<option value="01">January</option>
<option value="02">Febuary</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="day">
<option> - Day - </option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="year">
<?php
$optionyear = date("Y",time());
$currentyear = $optionyear;
while($optionyear != 1990) {
echo "<option value=\"".$optionyear."\"";
if($optionyear == $currentyear) {
echo " selected";
}
echo ">".$optionyear."</option>";
$optionyear--;
}
?>
</select><br />
<input type="submit" name="Submit" value="Upload" /><br />
</form>
Thanks!
U can get your upload data with $_FILES[] and other data with $_POST[]
Try
echo "<pre>";
print_r($_POST);
print_r($_FILES['ufile']);
echo "</pre>";
By the way where is close tag for <form> element?
I have a Combobox (<select><option></option></select>) and It consists of 31 numbers, the following code :
<select name='Bday' id='Bday' >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
I want the page number is 25 received, Combobox to view it. for example , if the address of page http//test.php?page=25,combobox view 25... No change in the combobox code!
Create your select options in a loop, and in each iteration check if the current value equals the one you get from the page get variable.
For brevity i have used the ternary operator in this example:
<?php $pageno = isset($_GET['page'])?$_GET['page']:''; ?>
<select name='Bday' id='Bday' >
<?php for($i=1;$i<=31;$i++):?>
<option value="<?php echo $i;?>" <?php echo $i==$pageno? 'selected':'';?> ><?php echo $i;?></option>
<?php endfor;?>
</select>
I have some info that is listed out. One of those fields is submit_date which has the date an application was submitted. On top of this list, I wanted to make a form where with drop down menus we could choose an initial date and a final date and then the list would only show applications submitted between that time range. I got the sql to work and made the form but for some reason whenever I click submit the entire list disappears.
<form name="yearRange" action="index.php" method="post">
Year1:
<select name="year1">
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
</select>
Month1:
<select name="month1">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
Day1:
<select name="day1">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
Year2:
<select name="year2">
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
</select>
Month2:
<select name="month2">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
Day2:
<select name="day2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if ($DBConn->numRows() > 0) { ?>
<div align="center">
<table border="1" align="center">
<tr>
<td> </td>
<td> </td>
<td><strong>Name</strong></td>
<td><strong>Submit Date</strong></td>
</tr> <?php
$date1="";
$date2="";
if(isset($_POST['year1']) && isset($_POST['year2']) && isset($_POST['month1']) && isset($_POST['month2']) && isset($_POST['day1']) && isset($_POST['day2']))
{
$date1 = $_POST['year1']."-".$_POST['month1']."-".$_POST['day1'];
$date2 = $_POST['year2']."-".$_POST['month2']."-".$_POST['day2'];
}
else{
echo "error";
}
$query = "select * from table1 where submit_date > '$date1' AND submit_date < '$date2'";
$sortQuery = mysql_query($query);
while ($row1=mysql_fetch_assoc($sortQuery))
{
?>
<tr>
<td valign="top"><?php echo $row1['lname'] . ", " . $row1['fname'] . " " . $row1['mname']; ?></td>
<td valign="top"><?php echo date('Y-m-d', strtotime($row1['submit_date'])); ?></td>
<?php } ?>
</tr> <?php
?>
</table>
</div>
<?php
} ?>