I want to made a simple check list with html.
<input type="checkbox" name="" value=""> <br>
It won't be a massive list.
But the problem is, surely, it won't saved, except it was stored on a persistence.
Although I can add connection to a MySQL database, this time I just don't want to use MySQL at all.
So I was planning to save those checkbox states on a permanent file.
Not on $_SESSION.
Do you have any idea what should I do?
Related
I am making a basic post-box management system in PHP. the postman can add 2 inputs which are 'delivered by' and 'item number'. and a button for the postman to click to submit the inputs.
Now, when the submit button is clicked, I want PHP to record the date and time of when the inputs are being submitted (so that later on I can set a mechanism to track the item duration and see how long an item has been in the box-but this is not part of the question). How do I do that?
sorry I have just started learning PHP so my current code is still very basic, and I haven't start with the Box-function.php page yet:
The HTML page:
<form method="post" action="Box-function.php">
Delivered by : <input type="text" name="Delivered-by"> <br>
Item No : <input type="text" name="Item-no"> <br>
<input type = "submit">
</form>
Note: I have seen similar questions but those questions involve using MySQL while I am not using it. it's just pure PHP and HTML.
In the box-function.php page, you can get the current date and store it along with the other data.
Getting current date
Do the same when the order is delivered. The difference between the two times will tell you how long the package took to be delivered.
Also, as the comments under your post say, you will have to store the data somewhere. You can't retrieve it later if it isn't stored anywhere.
I'm a bit confused of do I need to prefix form input variables with i.e. ('car_', or 'bike_' corresponding to 'car_make', 'bike_make') or can I use same template for both forms without prefixing variables. And if so, do I still need to prefix the 'submit' field, or having different form name is enough to avoid data collision.
I have these two HTML forms on the same page:
<form action="" name="car_search_form" method="POST">
<input type="hidden" name="make" value="Audi" />
<input type="submit" name="car_do_search" value="Search Car" />
</form>
<form action="" name="bike_search_form" method="POST">
<input type="hidden" name="make" value="Schwinn" />
<input type="submit" name="bike_do_search" value="Search Bike" />
</form>
So, in the end I want to get correct value for $validCarMake via this code:
if(isset($_POST['car_do_search']))
{
$paramCarMake = isset($_POST['make']) ? sanitize_text_field($_POST['make']) : '';
$validCarMake = esc_sql($paramCarMake); // For SQL queries only
// TODO: Add data saving to database
}
Also, I want to understand the decision process of PHP engine. How it does deside which variable to choose - how it know on which button I clicked, and why not it does just submit all forms on the page? Also, if there would be any difference if I'd use "GET" method instead of "POST" besides that the one does put the variable values to URL? And how does the GET case it would process attached image to form submit then (as the maximum URL lenght is 255 chars as I know, and i.e. JPEG 100 kiB image contains thousands of chars. I'm asking this, because I also want to allow not just have that search on site's home page, but also allow to make search from a separate website's some kind of widget.
And the last question - if the HTML form processing differs somehow in PHP 7.X compared to PHP 5.X (i.e. PHP 5.4). I means does it caches somewhere the data, does it sends over the internet the attached images of the both forms and consumes network and server data, or it submit's only the data of the form on which I clicked the button.
As long as you keep the 2 input requests separate having the post arg "make" is completely fine. If you send the args in the same request the 2nd will override the first since it was last set.
As for how php decides on what is first it uses what is called order of precedence. This means what it comes to first it executes first unless explicitly told not to.
I want to understand the decision process of PHP engine. How it does decide which variable to choose - how it know on which button I clicked, and why not it does just submit all forms on the page?
When you click on a button, php will take the <button name="value"> value assigned in the name property of the input field or button clicked. This is how it can decide what's the form to submit. Consider that if you have two forms with the same name assigned to the submit button, the first one will override the second and php will only submit one form. This is because php execute operations with a logical order.
I have a form that uses Post to send info to a PHP page.
The PHP page;
Takes the form info.
Rearranges it.
Formats it.
Then turns it into a code string that's ultimately sent to another
page and performs some tasks using that info.
Form Code:
<form method="post" action="_php/buildMyPNR.php" name="GuestInfo"
onSubmit="return validateFormMethod1();">
<input type="text" name="AccountNumber" id="BID"
onkeypress="return isNumberKey(event)" size ="16"/>
<input type="hidden" name="requestID" id="RID" value="" />
..... bunch of other fields
<input type="submit" name="loadURL" id="submit" value="Submit"
onsubmit="return ValidateFields();" />
</form>
What I need to do is;
Generate a sequential number each time the page is used.
Pass that number with the post request (Sort of like a serial number
for the request), to another form say _php/buildMyPNR.php.
When _php/buildMyPNR.php loads, save the values of
AccountNumber and requestID to a database or similar.
Ultimately it would move on to _php/usageSummary.php, where the user can click
a button to return a list of AccountNumbers paired with the
requestID that was generated for the request.
Possibly download the list in an excel spreadsheet format, but it is
not absolutely necessary.
What would be the best way to accomplish this?
Mainly I need help with generating the requestID. I need them to be sequential so I assume that I would need to start with a number in my database like 00001, query that number from my form, add 1 to the returned value, then save the new value along with the AccountNumber when submit is pressed.
I have no experience with databases and any guidance would be greatly appreciated.
Ideally we'd see some schema and examples of code you've already tried...
However, you can use an Auto Increment field in your Database Table, which will accomplish the ID incrementing for you.
If you're using mysqli for your mysql database interaction (as you perhaps should be), then you can then retrieve this autonumber using;
$PassedRequestID = $mysqli->insert_id
Then pass this to your next page.
You will then need to query your database with something like (psuedo code);
SELECT Accounts.*, Requests.*
INNER JOIN Requests ON Requests.AccountID = Accounts.AccountID
WHERE Requests.RequestID = $PassedRequestID
For exporting to Excel, if you search for PHP export CSV using Google, there'll be plenty of examples there to choose from. However, as an example;
http://code.stephenmorley.org/php/creating-downloadable-csv-files/
I have a form for saving the attendance of students to the MySQL database.
Students' data is read from the database and create the data entry form.
The form is designed to store the code, name, presence status of each student and a short description in case of absence.
I have designed the data entry form, but seem to need some clues regarding the save action so that clicking on each save button, the appropriate data is stored in the attendance table of the database.
If you don't care about old IE (which has bugs in its support of <button>, I think version 7 fixes this those bugs) then (making sure you are in Standards mode):
<button type="submit" name="row_id" value="insert row id here">Save</button>
$row_id = $_POST['row_id'];
If you do care about old IE:
<input type="submit" name="row_id_row_id_here" value="Save">
and loop over the keys in $_POST looking for ones which match the regex /^row_id_(.*)/.
I have a Parent/Child form. For example, the parent table may have the following field
Number of projects completed
Have you ever worked with our company? (Yes/No radio button)
If the second option have 'Yes' value, then I need to fill the details form.
For example: "The project name done with our company, copy of contract to be uploaded etc."
I have the following logic,
The deatils form may have a ADD button to add deatils records. I think I can store the details data in JavaScript arrays? Can I store the
<input type="file" name="file_to_upload" />
in arrays ?
Then on the submit button, send the parent and child deatils to the database.
Is there any other method to accomplish the task ?
Please see the screen snap
I can only add one detail records at a time. My question is, where should I temporarily store the deatil list ?
yes, you can store the details data in javascript but you have to put that details in the form somehow, unless you send it via Ajax, but I am not sure if you can hold the image with javascript and then send it.
I think that you can also try a html array form, if you want to add a detail then just add another input with javascript, I think it looks something like this.
<input name="detail[0]" type="text"></input>
<input name="detail[1]" type="text"></input>
you can read something more about this here: http://roshanbh.com.np/2008/08/handling-array-html-form-elements-javascript-php.html.