I am wondering where my mistake is. I've been looking at different solutions on why the $_POST is empty, and none have come up with an answer as to why it is happening.
i have tried the following changes in HTML method="GET" and method="POST" - neither works action="test.php" / action="localhost/test.php" / action="c:\xampp\htdocs\test.php"
Here is the HTML Form code
<form name="Driftslog" action="localhost/test.php" method="POST">
Init: <input type="text" id="Init" size="5" maxlength="5" autocomplete="on" required> <br></br>
LID: <input type="text" id="LID" size="8" maxlength="8" required><br></br>
Ticket-ID: <input type="text" id="TicketID" size="20" maxlength="15" required><br></br>
Kunde: <input type="text" id="Kunde" size="25" maxlength="50" required><br></br>
Start tid: <input type="datetime" id="StartTid" size="15" value="" required> <br></br>
Slut tid: <input type="datetime" id="SlutTid" size="15" value="" required><br></br\
Tilkald <input type="checkbox" id="Tilakd"><br></br>
Planlagt <input type="checkbox" id="Planlagt"><br></br>
Andet <input type="checkbox" id="Andet"><br></br>
<input type="submit" value="Opret">
</form>
and here is my PHP file test.php in this PHP file i tried various changes. i commented out the entire IF section and just tried to print the variable to see what was in it, using var_dump($_POST) /print_r and a for each loop. all came back empty
it is like the HTML does not pass the data to the php file
The only thing that works in the php file is the last echo and page redirect
<?php
if(isset($_POST['submit']))
{
$Init = trim($_POST["Init"]);
$LID = trim($_POST["LID"]);
$TicketID = trim($_POST["TicketID"]);
$Kunde = trim($_POST["Kunde"]);
$StarttTid = trim($_POST["StartTid"]);
$SlutTid = trim($_POST["SlutTid"]);
$data = [ $Init, $LID, $TicketID, $Kunde, $StartTid, $SlutTid, "\n"];
$f = fopen("db.csv","a");
fputcsv($f, $data);
fclose($f);
print $TicketID;
}
echo "oprettet med success";
header("Refresh:3; url=http://localhost");
exit();
?>
Problem -
Your form values do not make it to your PHP.
Solution -
Example -
index.html -
<form name="Driftslog" action="localhost/test.php" method="POST">
Init: <input type="text" id="Init" name="Init" size="5" maxlength="5" autocomplete="on" required> <br></br>
LID: <input type="text" id="LID" name="LID" size="8" maxlength="8" required><br></br>
Ticket-ID: <input type="text" id="TicketID" name="TicketID" size="20" maxlength="15" required><br></br>
Kunde: <input type="text" id="Kunde" name="Kunde" size="25" maxlength="50" required><br></br>
Start tid: <input type="datetime" id="StartTid" name="StartTid" size="15" value="" required> <br></br>
Slut tid: <input type="datetime" id="SlutTid" name="SlutTid" size="15" value="" required><br></br\
Tilkald <input type="checkbox" id="Tilakd" name="Tilakd"><br></br>
Planlagt <input type="checkbox" id="Planlagt" name="Planlagt"><br></br>
Andet <input type="checkbox" id="Andet" name="Andet"><br></br>
<input type="submit" value="Opret">
</form>
test.php -
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$Init = trim($_POST["Init"]);
$LID = trim($_POST["LID"]);
$TicketID = trim($_POST["TicketID"]);
$Kunde = trim($_POST["Kunde"]);
$StarttTid = trim($_POST["StartTid"]);
$SlutTid = trim($_POST["SlutTid"]);
$data = [ $Init, $LID, $TicketID, $Kunde, $StartTid, $SlutTid, "\n"];
$f = fopen("db.csv","a");
fputcsv($f, $data);
fclose($f);
print $TicketID;
}
echo "oprettet med success";
header("Refresh:3; url=http://localhost");
exit();
?>
In yourinput
fields you are missing thename=''
attributes
To read fields from the post request the input fields must have thename
attribute.
Change your HTML to something like this:
<form name="Driftslog" action="localhost/test.php" method="POST">
Init: <input type="text" id="Init" name="Init" size="5" maxlength="5" autocomplete="on" required> <br></br>
LID: <input type="text" id="LID" name="LID" size="8" maxlength="8" required><br></br>
Ticket-ID: <input type="text" id="TicketID" name="TicketID" size="20" maxlength="15" required><br></br>
Kunde: <input type="text" id="Kunde" name="Kunde" size="25" maxlength="50" required><br></br>
Start tid: <input type="datetime" id="StartTid" name="StartTid" size="15" value="" required> <br></br>
Slut tid: <input type="datetime" id="SlutTid" name="SlutTid" size="15" value="" required><br></br\
Tilkald <input type="checkbox" id="Tilakd" name="Tilakd"><br></br>
Planlagt <input type="checkbox" id="Planlagt" name="Planlagt"><br></br>
Andet <input type="checkbox" id="Andet" name="Andet"><br></br>
<input type="submit" name="submit" value="Opret">
</form>
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.