How do I insert all employee attendance(Monthly once) in mysql database
Here is my db tables
att_employee_id | att_year | att_month | att_present_days | att_absent_days | att_workingdays
Date.prototype.daysInThisMonthOfThisYear=function() {
return new Date(this.getFullYear(),this.getMonth()+1,0).getDate();
}
var days_inmonth = new Date().daysInThisMonthOfThisYear();
$(document).ready(function() {
$( ".absent_days" ).keyup(function() {
var days = $(this).val();
$(this).closest("tr").find(".present_days" ).val( days_inmonth - days );
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<form name="emp_att" action="" method="post">
<table>
<thead>
<tr>
<th class="head0" style="width:5%">S.No</th>
<th class="head1" style="width:15%">Employee ID</th>
<th class="head0 no-sort" style="width:15%">No.of days present</th>
<th class="head1 no-sort" style="width:15%">No.of days absent</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>ETO0001</td>
<td><input type="text" class="present_days" name="present_days" value=""></td>
<td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>2</td>
<td>ETO0002</td>
<td><input type="text" class="present_days" name="present_days" value=""></td>
<td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>3</td>
<td>ETO0003</td>
<td><input type="text" class="present_days" name="present_days" value=""></td>
<td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>4</td>
<td>ETO0004</td>
<td><input type="text" class="present_days" name="present_days" value="" readonly></td>
<td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" value="Submit">
</form>
Here is my query to get all the employees
<form name="emp_att" action="" method="post">
<table>
<thead>
<tr>
<th class="head0" style="width:5%">S.No</th>
<th class="head1" style="width:15%">Employee ID</th>
<th class="head0 no-sort" style="width:15%">No.of days present</th>
<th class="head1 no-sort" style="width:15%">No.of days absent</th>
</tr>
</thead>
<tbody>
<?php
$allemp= mysqli_query($con,"select * from t_emp e");
$all_emp = mysqli_num_rows($allemp);
if ($all_emp > 0)
{
$i=1;
while($all_emp = mysqli_fetch_assoc($allemp))
{
echo "<tr>";
echo "<td>".$i."<input type='hidden' name='serialno' value='".$i++."'></td>
<td> ".$all_emp["emp_id"]."</td>
<td><input type='text' class='present_days' name='present_days' value=''></td>";
echo "<td><input type='number' name='absent_days' class='absent_days' min='0' max= date('t') onChange='absentdays()' style='width:100%'></a></td>";
echo "</tr>";
}
}
else
{
echo "0 Results";
}
?>
</tbody>
</table>
<input type="submit" name="submit" value="Submit">
</form>
Here I am getting all the n number of employees in the above form. when entered all employees "No.of days absent" and then hit on submit I am able to send only last record to the database.
Can any one help me to send all the employees attendance to database
Here is my form submission query
<?php
if(isset($_POST['submit']))
{
$serialno=$_post['serialno'];
$employee_id=$_post['emp_id'];
$att_year = date('Y');
$att_month = date('m');
for($i=1; $i<= $serialno;$i++)
{
$present_days=$_POST['present_days'];
$absent_days=$_POST['absent_days'];
}
$query=mysqli_query($con,"INSERT INTO t_emp_attendance(att_employee_id,att_year,att_month,att_present_days,att_absent_days)values('$employee_id','$att_year','$att_month','$present_days','$absent_days')");
}
?>
any suggestions will be appreciated, I need to store all the employees attendance to database
Check that name of input fields are created. It might be overwritten with the latest values. Send it as an array format like "absent_days[]" it will solve your problem
Check you spelling for INSERT. And also you have missed to pass the connection object for inserting
First parameter should be the connection object in mysqli_*
mysqli_query(connectionObject,your Query);
$query=mysqli_query("INSERT INTO t_emp_attendance(att_employee_id,att_year,att_month,att_present_days,att_absent_days)values('$employee_id','$att_year','$att_month','$present_days','$absent_days')");
for($i=1; $i<= $serialno;$i++)
{
$present_days=$_POST['present_days'][$i];
$absent_days=$_POST['absent_days'][$i];
$query=mysqli_query($con,"INSERT INTO t_emp_attendance(att_employee_id,att_year,att_month,att_present_days,att_absent_days)values('$employee_id','$att_year','$att_month','$present_days','$absent_days')");
}
Your query should be inside the loop. And as suggested by parag, make text field names as arrays []
Soomething like this,
<input type="text" class="present_days" name="present_days[]" value="">
^ ^
You shud do for all the text boxes.
Related
I've got two tables: Subjects and Careers :
"Subjects" includes (id, careers_id (is the foreign key to the column "id" of the table Careers) subject, description, hours)
"Careers" includes (id,name,description)
I put a button which allows me to add a new subject. So when I click on it another page open. I need to add a slider/select which shows me the careers available in the table career. Take a look,I need something like this :
Here is my code to add a new subject (it works,but i dont know how to make the slider/select which fetch data from the table careers :/)
<?php include('connect.php');
$error="";
if(isset($_POST['btnsave']))
{
$carreras_id=$_POST['txtcarreras_id'];
$subject=$_POST['txtsubject'];
$descripcion=$_POST['txtdescripcion'];
$carga_horaria=$_POST['txtcarga_horaria'];
if($_POST['txtid']=="0")
{
$a_sql=mysql_query("INSERT INTO subjects VALUES('','$carreras_id','$subject','$descripcion','$carga_horaria')");
if($a_sql)
{
header("location:index.php");
}
}else{
echo "Actualizar";
}
}
?>
<h2 align="center">ADD NEW SUBJECT</h2>
<form method="Post">
<table align="center">
<tr>
<td>Career:</td>
<td>
<input type='text' name='txtcarreras_id' />
<input type="hidden" name="txtid" value="0" />
</td>
</tr>
<tr>
<td>Subject:</td>
<td>
<input type='text' name='txtsubject' />
</td>
</tr>
<tr>
<td>Description:</td>
<td>
<input type='text' name='txtdescripcion' />
</td>
</tr>
<tr>
<td>Hours:</td>
<td>
<input type='text' name='txtcarga_horaria' />
</td>
</tr>
<tr>
<td></td>
<td>
<input type='submit' value=save name='btnsave' />
</td>
</tr>
</table>
</form>
I don't know what to do?
Hope you can help me!
Thanks!
To build your <option>s you would do something like this ->
$sql = mysql_query("SELECT * FROM Careers");
$options = "";
while($result = mysql_fetch_array($sql)){
$options .= "<option value='".$result['id']."'>".$result['name']."</option>";
}
(Note - you should update from mysql_ to MySQLi or PDO - MySQL: choosing an API )
Then you would change your <input> to a <select> with your $options ->
<tr>
<td>Career:</td>
<td><select name='txtcarreras_id'><?php echo $options; ?></select><input type="hidden" name="txtid" value="0" /></td>
</tr>
I have a form where I ask the user to enter some values. Then, using PHP, I'm trying to process the values the user entered.
The issue I'm facing is that, after the user submitted the form, all my values are set to 1 instead of the value the user entered.
Here is the form:
<form method="post" action="checkOutResult.php">
<p> Transaction #:
<input type="text" name="transactionNum" placeholder="Input #">
</p>
<table>
<tr>
<td>Student ID</td>
<td>Employee ID</td>
<td>Professor ID</td>
</tr>
<tr>
<td>
<input type="text" name="studentID" placeholder="7 Digit Student ID">
</td>
<td>
<input type="text" name="empID" placeholder="7 Digit Employee ID">
</td>
<td>
<input type="text" name="profID" placeholder="7 Digit Professor ID">
</td>
</tr>
</table>
<table>
<tr>
<td>Product ID</td>
</tr>
<tr>
<td>
<input type="text" name="productID" placeholder="Scan Barcode">
</td>
</tr>
</table>
<center>
<table>
<tr>
<iframe src="http://free.timeanddate.com/clock/i4nrjjak/n179/fn10/fs24/fcb40431/ftb/bas2/bat1/bacfff/pa8/tt0/tw1/td2/th2/tb4" frameborder="0" width="334" height="74"></iframe>
<td>CheckOut Date</td>
<td>CheckOut Time</td>
</tr>
<tr>
<td>
<input type="text" name="checkoutDate" placeholder="YYYY-MM-DD">
</td>
<td>
<input type="text" name="checkoutTime" placeholder="HH:MM:SS">
</td>
</tr>
</table>
</center>
<center>
<table>
<tr>
<td>Due Date</td>
<td>Due Time</td>
</tr>
<tr>
<td>
<input type="text" name="dueDate" placeholder="YYYY-MM-DD">
</td>
<td>
<input type="text" name="dueTime" placeholder="HH:MM:SS">
</td>
</tr>
</table>
</center>
<input type="submit" name="Submit" value="submit">
</form>
This is the PHP code that is executed upon form submission.
<?php
include ("thesis.php");
$transactionNum = isset($_POST['transactionNum']);
$studentID = isset($_POST['studentID']);
$empID = isset($_POST['empID']);
$profID = isset($_POST['profID']);
$productID = isset($_POST['productID']);
$checkoutDate = isset($_POST['checkoutDate']);
$checkoutTime = isset($_POST['checkoutTime']);
$dueDate = isset($_POST['dueDate']);
$dueTime = isset($_POST['dueTime']);
$query = "INSERT INTO Transactions(transactionNum, studentID, empID, profID, productID, checkoutDate, checkoutTime, dueDate, dueTime)
VALUES ('$transactionNum', '$studentID', '$empID', '$profID', '$productID', '$checkoutDate', '$checkoutTime', '$dueDate', '$dueTime')";
if($link->query($query) === TRUE){
echo "New Record Created Successfully. ";
echo"<br>";
}
else{
echo" Error: " .$query ."<br>" .$link->error;
}
echo"<br>";
echo "Transacton #: ".$transactionNum;
echo"<br>";
echo "Student ID: ".$profID;
echo"<br>";
echo "Employee ID: ".$empID;
echo"<br>";
echo "Professor ID: ".$profID;
echo"<br>";
echo "Product ID: ".$productID;
echo"<br>";
echo "Out Date: ".$checkoutDate;
echo"<br>";
echo "Out Time: ".$checkoutTime;
echo"<br>";
echo "Due Date: ".$dueDate;
echo"<br>";
echo "Due Time: ".$dueTime;
echo"<br>";
?>
Why do I keep getting 1s instead of the values I submit with the form?
The following command retuns true (1 as a string) if the field empID isset in your $_POST data.
$empID =isset($_POST['empID']);
it should be
$empID = isset($_POST['empID']) ? $_POST['empID'] : "";
and so on.
Which means: catch the empID of $_POST if there is one, else catch an empty string. It is a short version of the following:
if(isset($_POST['empID'])) {
$empID = $_POST['empID'];
} else {
$empID = "";
}
You are getting boolean for isset here
$empID = isset($_POST['empID']);
Which is why it is giving you a value of 1 as that is the value for true in this case.
Resolve with if isset($_POST['empID']) {$empID = $_POST['empID'];}
I have a little question about something. I have some forms, where I send the input to a MySQL database. I get the return from the database, out in some div tags. Here I have 2 buttons. Button number 1 can delete the row, and button number 2 should have a function, where I can update a specific row, if I want to change the content of the row. But can I update a div tag? I can see on the net, that a lot of people use tables to do that.
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/arrangeTables.css">
</head>
<body>
<?php
include 'connection.php';
if(isset($_POST['addto'])){
// Insert to database
$date = $_POST['date'];
$day = $_POST['day'];
$fromtime = $_POST['fromtime'];
$totime = $_POST['totime'];
$sql = "INSERT INTO addWorkTime(date, day, fromtime, totime) VALUES('$date', '$day', '$fromtime', '$totime')";
$result = mysql_query($sql, $dbhandle) or die(mysql_error($dbhandle));
// Update of the row
if(isset($_POST['update'])){
$hidden = mysql_real_escape_string($_POST['hidden']);
$UpdateQuery = "UPDATE addWorkTime
SET date='$_POST[date]',
day='$_POST[day]',
fromtime='$_POST[fromtime]',
totime='$_POST[totime]'
WHERE p_id='$_POST[hidden]'";
$update = mysql_query($UpdateQuery, $dbhandle) or die(mysql_error($dbhandle));
if($update) {
echo "Succes";
} else {
echo "Der er en fejl";
}
}; // brace for if(isset($_POST['update']))
if($result){
echo "Insert successful.";
}
}; // brace for if(isset($_POST['addto']))
if(isset($_POST['delete'])){
$hidden = mysql_real_escape_string($_POST['hidden']);
$DeleteQuery = "DELETE FROM addWorkTime WHERE p_id=$hidden";
$delete = mysql_query($DeleteQuery, $dbhandle) or die(mysql_error($dbhandle));
if($delete){
echo "Delete successful";
}
}
//Return records from database
$result = mysql_query("SELECT p_id, date, day, fromtime, totime FROM addWorkTime");
?>
<form method="post">
<h3>Add your worktime to database</h3><br>
Date:
<input type="date" name="date"><br><br>
Day
<select name="day">
<option value="Mandag">Mandag</option>
<option value="Tirsdag">Tirsdag</option>
<option value="Onsdag">Onsdag</option>
<option value="Torsdag">Torsdag</option>
<option value="Fredag">Fredag</option>
<option value="Lørdag">Lørdag</option>
<option value="Søndag">Søndag</option>
</select>
From time:
<input type="time" name="fromtime">
To time:
<input type="time" name="totime">
<input type="submit" name="addto" value="submit"><br><br>
<!-- Return from the database -->
<h3>Return from database:</h3><br>
<!-- headers -->
<table>
<tr>
<th class="column0">Primary Key</th>
<th class="column1">Date</th>
<th class="column2">Day</th>
<th class="column3">From</th>
<th class="column4">To</th>
</tr>
</table>
</form>
<!--loop through through the database -->
<?php while($row = mysql_fetch_array($result)): ?>
<form method="post">
<table>
<tr>
<td class="resultcolumn0"><?php echo $row{'p_id'};?></td>
<td class="resultcolumn1"><?php echo $row{'date'};?><br></td>
<td class="resultcolumn2"><?php echo $row{'day'};?></td>
<td class="resultcolumn3"><?php echo $row{'fromtime'};?></td>
<td class="resultcolumn4"><?php echo $row{'totime'};?></td>
<td><input type="hidden" name="hidden" value="<?php echo $row{'p_id'}?>"><?php echo $row{'p_id'}?></td>
<td><input type="submit" name="update" value="Update"></td>
<td><input type="submit" name="delete" value="Delete"></td>
</tr>
</table>
</form>
<?php endwhile; ?>
</body>
</html>
If you want to update your cell table like your recording, you can do a tricky way like this code snippet:
function change1() {
var inp1 = document.getElementById('myTable').rows[1].cells[0];
inp1.innerHTML = "<input type='text' name='inp1'>";
var inp2 = document.getElementById('myTable').rows[1].cells[1];
inp2.innerHTML = "<input type='text' name='inp2'>";
}
function change2() {
var inp1 = document.getElementById('myTable').rows[2].cells[0];
inp1.innerHTML = "<input type='text' name='inp1'>";
var inp2 = document.getElementById('myTable').rows[2].cells[1];
inp2.innerHTML = "<input type='text' name='inp2'>";
}
table, td {
border: 1px solid black;
}
<table id="myTable">
<tr>
<td>column 1</td>
<td>column 2</td>
<td>action</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
<td>
<button onclick="change1()">Update</button>
</td>
</tr>
<tr>
<td>Row3 cell1</td>
<td>Row3 cell2</td>
<td>
<button onclick="change2()">Update</button>
</td>
</tr>
</table>
<button onclick="alert('whatever function to save the edit')">Save</button>
you can improve that to give <form> tag to your <table> tag and save that using another Save button. Or you can use if conditional to your update button for change to textfield and post it to your database.
<form method="post" action='function_to_update_or_delete.php'>
<table>
<tr>
<td class="resultcolumn0"><?php echo $row{'p_id'};?></td>
<td class="resultcolumn1"><?php echo $row{'date'};?><br></td>
<td class="resultcolumn2"><?php echo $row{'day'};?></td>
<td class="resultcolumn3"><?php echo $row{'fromtime'};?></td>
<td class="resultcolumn4"><?php echo $row{'totime'};?></td>
<td><input type="hidden" name="hidden" value="<?php echo $row{'p_id'}?>"><?php echo $row{'p_id'}?></td>
<td><button onclick="<?php echo change($some_information_to_your_cell)?>">Update</button></td>
<td><input type="submit" name="delete" value="Delete"></td>
</tr>
</table>
</form>
And, please try to make a function dynamically each row, don't hardcode it like function change1(), function change2(), function change3(), etc
Hope this will help you out. :)
my problem goes like this:
my home page has tables with rows pulled from the database (while loops)
each row has a - cell in which he can add an event to that specific row
in order to do that i send the row id as a $_GET variable from the home page table
and in the "add event" page i store it as a variable
but when i submit my addevent form without filling it properly (as i coded) it simply refreshes the form only without the row id in the url therefor also the query i do in the beginning of the page for pulling the row data can no longer execute and that pops a PHP error
for the id variable which i sign it the $_GET and the query (mysql fetch array).
also of course all the data which i display in the form from that query is gone.
any suggestions on how to approach this ? thanks in advance, Regards.
EDIT:** kill the new guy! -Sorry i guess
home page where i send the id :
$sql = "SELECT * FROM alarms WHERE alarmstatus = 'OFF' and starttime='::' ORDER BY clientid ASC";
$query = mysql_query($sql);
echo "<table cellpadding='1px' border='1px' bordercolor='#0066FF' cellspacing='0'>
<form action='hpage.php' method='get'>";
while($fetch = mysql_fetch_array($query)) {
echo "<tr>
<td>
".$fetch['clientid']."</td>
<td>".$fetch['controller']."</td>
<td>".$fetch['typeid']."</td>
<td style='color: red'>".$fetch['alarmstatus']."</td>
<td>".$fetch['starttime']."</td>
<td>".$fetch['endtime']."</td>
<td><a href='includes/editalarm.php?id=".$fetch['id']."'>Edit</a></td>
<td><a href='includes/addevent.php?id=".$fetch['id']."'>Add event</a></td>
<td><a href='includes/deletealarm.php?id=".$fetch['id']."'>Delete</a></td>
</tr>";
}
the add event where i get the variable and make the query:
$alarmid = $_GET['id'];
$sql = "SELECT * FROM alarms WHERE id=".$alarmid;
$query = mysql_query($sql);
$fetch = mysql_fetch_array($query);
?>
the form:
<table cellpadding="2px" cellspacing="0" >
<form action="addevent.php" method="post">
<tr>
<td>סניף:</td>
<td><input style="width:200px; background-color: #d6d6d6;" readonly name="client" value="<?php echo $fetch['clientid']; ?>" /></td>
</tr>
<tr>
<td>בקר:</td>
<td><input style="width:200px; background-color: #d6d6d6;" readonly name="controller" value="<?php echo $fetch['controller']; ?>" /></td>
</tr>
<tr>
<td>אזעקה:</td>
<td><input style="width:200px; background-color: #d6d6d6;" readonly name="controller" value="<?php echo $fetch['typeid']; ?>" /></td>
</tr>
<tr>
<td>מוקדן:</td>
<td>
<?php
$sql = "SELECT * FROM users WHERE privilege = '2'";
$query = mysql_query($sql);
echo "<select name='user' style='width:207px;'>";
echo "<option>..</option>";
while ($fetch2 = mysql_fetch_array($query)){
echo "<option>".$fetch2['username']."</option>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td>איש קשר:</td>
<td><input type="text" name="contact" /></td>
</tr>
<tr>
<td>הודעה:</td>
<td><input type="text" style="width:200px; height:100px" name="message" /></td>
</tr>
<tr>
<td>תשובה:</td>
<td><input type="text" style="width:200px; height:100px" name="answer" /></td>
</tr>
<tr>
<td>שעה:</td>
<td>
<select name="eventhour">
<option value ="default"></option>
<?php
for($i = 0; $i<60; $i++){
$value = $i;
if($i<=9){
$value= "0".$i;
}
echo "<option>".$value."</option>";
}
?>
</select>
<select name="eventminute">
<option value ="default"></option>
<?php
for($i = 0; $i<24; $i++){
$value = $i;
if($i<=9){
$value= "0".$i;
}
echo "<option>".$value."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" name="save" value="שמור" />
<input type="submit" name="cancell" value="בטל" />
</td>
<td></td>
</tr>
</form>
Your form action is POST. If you change that to GET then you will have the form as $_GET.
I need to pass back a large string of results to a form, so that the form can read those results from the URL and then populate the form with them. Problem is, the link ends up being:
&key=value&key=value ... until it can't process anymore (I assume a URL has a length limit?) resulting in my form not being able to fully populate. I need another way to pass values back to my form file.
VIEW.php file (basically just a table of values right as they are from the database, with the first column "id" being a link. When I click on "id", it goes back to my add.php(form page) and populates the form with the data matching that id)
<table border="0" cellpadding="0" cellspacing="0" id="table">
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
<th>MANUFACTURER</th>
<th>MODEL</th>
<th>DESCRIPTION</th>
<th>ON HAND</th>
<th>REORDER</th>
<th>COST</th>
<th>PRICE</th>
<th>SALE</th>
<th>DISCOUNT</th>
<th>DELETED</th>
<th></th>
</tr>
</thead>
<tbody>
<?php } ?>
<?php
// loop to fetch data
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>
<a href='molszewski1_a2_add.php'>$row[id]</a></td>";
echo "<td>$row[name]</td>";
echo "<td>$row[manufac]</td>";
echo "<td>$row[model]</td>";
echo "<td>$row[descrip]</td>";
echo "<td>$row[onhand]</td>";
echo "<td>$row[reorder]</td>";
echo "<td>$row[cost]</td>";
echo "<td>$row[price]</td>";
echo "<td>$row[sale]</td>";
echo "<td>$row[discont]</td>";
echo "<td>$row[deleted]</td>";
$status = "$row[deleted]";
echo "<td><a href='molszewski1_a2_delete.php?id=$row[id]&flag=$status&sort=$sort'>";
$status = "$row[deleted]";
if ($status == 'n') {
$flag = "restore";
echo "delete";
} else if ( $status == 'y') {
$flag = "delete";
echo "restore";
}
echo "</a></td>";
echo "</tr>";
} ?>
<?php { ?>
</tbody>
</table>
ADD.php (form page where the form is supposed to fetch the data and populate it)
<?php
// If no form has been submitted, present form
if (empty($_GET))
{
add_form();
}
// if a form has been submitted
else
{
// if form_validity() == 1, proceed to connect
if (form_validity() == 1)
{
// connect to mysql + database
connect();
$saleItem = "n";
$discountItem = "n";
if( array_key_exists( 'saleItem', $_GET ) && $_GET['saleItem'] == 'y' )
{ $saleItem = "y"; }
if( array_key_exists( 'discountItem', $_GET ) && $_GET['discountItem'] == 'y' )
{ $discountItem = "y"; }
// get values from form, insert into database
$sql=("INSERT INTO inventory (name,
manufac,
model,
descrip,
onhand,
reorder,
cost,
price,
sale,
discont,
deleted)
VALUES ('$_GET[itemName]',
'$_GET[manufacturer]',
'$_GET[model]',
'$_GET[description]',
'$_GET[numberOnHand]',
'$_GET[reorderLevel]',
'$_GET[cost]',
'$_GET[sellingPrice]',
'$saleItem',
'$discountItem', 'n')");
// if the query doesn't work, display error message
if (!(mysql_query($sql))) { die ("could not query: " . mysql_error()); }
add_form();
// redirect to view.php after form submission
// use php instead
echo "<meta http-equiv='REFRESH' content='0;url=molszewski1_a2_view.php'>";
}
else
{
// if form is not valid (form_validity returns 0), display error messages
add_form();
}
}
?>
FUNCTIONS.php (all my functions for stuff like the form)
<?php function page_navigation(){ ?>
<div class="center">
<input type="button" value="ADD" />
<input type="button" value="VIEW" />
<input type="button" value="VIEW DELETED" />
<input type="button" value="VIEW ACTIVE" />
<br />
<br />
</div>
<?php } ?>
<?php function add_form() { ?>
<form action="molszewski1_a2_add.php" method="get" id="form">
<table width="529px">
<tr>
<td>ITEM NAME</td>
<td><input name="itemName" size="30" type="text" value="<?php echo $_GET["itemName"] ?>"/></td>
</tr>
<tr>
<td>MANUFACTURER</td>
<td><input name="manufacturer" size="30" type="text" value="<?php echo $_GET["manufacturer"] ?>"/></td>
</tr>
<tr>
<td>MODEL</td>
<td><input name="model" size="30" type="text" value="<?php echo $_GET["model"] ?>"/></td>
</tr>
<tr>
<td>DESCRIPTION</td>
<td><textarea name="description" rows="3" cols="20"><?php echo $_GET["description"] ?></textarea></td>
</tr>
<tr>
<td>ON HAND</td>
<td><input name="numberOnHand" size="30" type="text" value="<?php echo $_GET["numberOnHand"] ?>"/></td>
</tr>
<tr>
<td>REORDER LEVEL</td>
<td><input name="reorderLevel" size="30" type="text" value="<?php echo $_GET["reorderLevel"] ?>"/></td>
</tr>
<tr>
<td>COST</td>
<td><input name="cost" size="30" type="text" value="<?php echo $_GET["cost"] ?>"/></td>
</tr>
<tr>
<td>SELLING PRICE</td>
<td><input name="sellingPrice" size="30" type="text" value="<?php echo $_GET["sellingPrice"] ?>"/></td>
</tr>
<tr>
<td>SALE ITEM</td>
<td>
<input type="checkbox" name="saleItem" value="y" <?php if( isset( $_GET['saleItem'] ) ){ ?> checked="checked" <?php } ?> />
</td>
</tr>
<tr>
<td>DISCOUNTED ITEM</td>
<td>
<input type="checkbox" name="discountItem" value="y" <?php if( isset( $_GET['discountItem'] ) ){ ?> checked="checked" <?php } ?> />
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="save" name="submit" id="submit" /></td>
</tr>
</table>
</form>
<?php } ?>
Use method="post" and $_POST (instead of $_GET).
POST requests can be much larger than GET requests as GET requests are limited by the maximum length of a URL. POST requests are limited by the size of the max_post_size ini-value which is usually a few megabytes.