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_(.*)/.
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 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?
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/
First of all, I am using PHP and MySQL in the Joomla Framework (but not interested at this point in the Joomla MVC structure).
I have a list of data from a database (Table A) and next to that I have added a checkbox. When I click on a checkbox, I want the data from the enabled checkbox to be sent (insert a copy of) to a new table (Table B) when I click on the 'Save' button and have that data listed on a new web page. The ones that are unchecked should not be sent to the new table and therefore should be ignored. Also, the 'Save' button must initially be disabled until a checkbox is checked.
Now, there must be a relationship between the existing data in a table (Table A) to the new table (Table B), so for example when the main existing data is deleted from the table (Table A), it should also automatically delete the data in the new table (Table B).
I know some PHP and MySQL but not enough to figure out some of the above.
Can some smart PHP and MySQL guru please point me to the right direction as I'm pulling my hair out, especially with the checkbox issue. Thanks!
To send data to another page and to displaying a message you'll need AJAX.
And for that check this page:
Ajax passing data to php script
But without the message ( to send data to a page ) , use this ->
Let's say that you have:
<form action="insertInDatabase.php" method="post">
<input type="checkbox" name="cbs[]" value="firstValue">First value<br>
<input type="checkbox" name="cbs[]" value="secondValue">Second value
</form>
So here you send your data to "insertInDatabase.php".
There you have this:
//connection do mySql database
if(!empty($_POST['cbs'])) {
foreach($_POST['cbs'] as $cb) {
mysql_query("INSERT INTO table2(checkedCheckBoxValue) VALUES('$cb');");
}}
I'm using Generic HTML Form Processor in combination with an xampp lite installation to save data into a MYSQL database. However, I've encountered a problem while writing a multi-page survey. If users use the previous and forward buttons coded like:
<INPUT TYPE="button" VALUE="Previous Page" onClick="history.go(-1);">
<input type="submit" value="Go to last page">
The next button differs slightly per page. For example, on page 1 it's:
<input value="Next Page" type="submit">
Users can go back and forth in the survey. I would prefer them to use the backwards and forward button to let the browser take care of saving the data but sadly it's not an option. The next button is linked to a hidden input code like:
<input type="hidden" name="next_page" value="http://localhost/quislast.html">
It works like a dream except for one problem. Imagine there are three pages, A, B, and C. If a user is on page C, and they click the previous button twice so they return to page A. If they then click the next page button, the form data (radio buttons) that the users select on pages B and C are no longer remembered. The users then have to re-select their answers before submitting the form.
Any ideas? Thank you in advance. And I apologize if the answer is so simple a novice could understand it.
Use a Session to collect the data during the survey. Then, when the user goes back and forth through the pages, fill in the input value attributes from the collected values in the $_SESSION array. When the user is finished with the survey, save the data to the database.