Here is my question 'if(!empty($_POST['btn_editinventory]))' is working but if i click on btndeleteinventory it will also execute the codes in my btneditinventory. Anyone knows how will i correct my condition in my controller if you have two buttons in the view like this:
<input type="button" value="Edit" name="btn_editinventory" id="btn_editinventory" onclick="validate_editinventory();"/>
<input type="button" value="Delete" name="btn_deleteinventory" id="btn_deleteinventory" onclick="validate_deleteinventory();"/>
Thank you in advance for your help! :)
Here is my view
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/mystyle.css') ?>">
<div id="content">
<form action="edit_delete_others2" method="POST" id='frm_otherequips2' name="frm_otherequips2">
<fieldset id="edit_other">
<legend>Inventory Details</legend>
<table>
<tr>
<?php $otherequips = $other2->Equipment;
$otherdesc = $other2->ItemDescription;
$otherID = $other2->ID;
$otherserialnum = $other2->SerialNumber;
?>
<td>Equipment</td>
<?php // if(isset($other)) { ?>
<td><input type="text" id="txt_editotherequip" name="txt_editotherequip" value="<?php echo $otherequips // echo (isset($other->Equipment) AND $other->Equipment) ? $other->Equipment:''; ?>"/></td>
<td>Item Description</td>
<td><input type="text" id="txt_editotherdesc" name="txt_editotherdesc" value="<?php echo $otherdesc // echo (isset($other->ItemDescription) AND $other->ItemDescription) ? $other->ItemDescription:''; ?>"/></td>
<td style="visibility: hidden;"><input type="text" id="txt_editotherID" name="txt_editotherID" value="<?php echo $otherID //echo (isset($other->ID) AND $other->ID) ? $other->ID:''; ?>"/></td>
</tr>
<tr>
<td>Serial Number</td>
<td><input type="text" id="txt_editotherserialnum" name="txt_editotherserialnum" value="<?php echo $otherserialnum // echo (isset($other->SerialNumber) AND $other->SerialNumber) ? $other->SerialNumber:''; ?>"/></td>
<?php // } ?>
</tr>
<tr>
<td><input type="button" id="btn_editother" name="btn_editother" value="Edit" onclick="validate_edit_otherequip();"/></td>
<td><input type="button" id="btn_deleteother" name="btn_deleteother" class="btn_deleteother" value="Delete" onclick="validate_delete_otherequip();"/></td>
</tr>
</table>
</fieldset>
</form>
</div>
here is my javascript:
<script>
function validate_edit_otherequip(){
if(document.getElementById('txt_editotherequip').value === ""){
alert('Please Input Equipment!');
return false;
}
else if(document.getElementById('txt_editotherdesc').value === ""){
alert('Please Input Item Description');
return false;
}
else if(document.getElementById('txt_editotherserialnum').value === ""){
alert('Please Input Serial Number');
return false;
}
else{
var y;
if(confirm("Are you sure you want to save updated data?") === true){
var y = document.forms['frm_otherequips2'].submit();
}
else if(confirm("Are you sure you want to save updated data?") === false){
return false;
}
}
}
function validate_delete_otherequip(){
var x;
if(confirm("Are you sure you want to delete this data?") === true){
var x = document.forms['frm_otherequips2'].submit();
}
else if(confirm("Are you sure you want to delete this data?") === false){
return false;
}
}
and here is my controller:
public function edit_delete_others2($id){
$data_other['other2'] = $this->inventory_model->other_search($id);
$this->load->view('homeview');
$this->load->view('frm_otherequips2', $data_other);
$this->load->view('footer_view');
}
I don't know how to have a condition in buttons.
As far as your two buttons have a name attribute, it's pretty easy to handle in your Controller
public function edit_delete_others2($id){
if($this->input->post('btn_editinventory')) {
// Do your edit stuff
} elseif($this->input->post('btn_deleteinventory')) {
// Do your delete stuff
}
}
The button is never send in the post when you don't click on it, this is why it works
Related
So I am trying to get the title from the URL by using $_GET['title'] in the first PHP file, but I can't get the file on the 2nd file.
URL:
https://easy2book.000webhostapp.com/neworder.php?bookid=101&title=SENIOR%20secondary%20geography%20fieldwork%20and%20assessment%20practice%202021.%20For%20HKDSE%202021%20/%20Ip%20Kim%20Wai%20...%20[et%20al.].
1st File:
<?php
include_once 'header.php';
$id2 = mysqli_real_escape_string($conn, $_GET['bookid']);
$title2 = mysqli_real_escape_string($conn, $_GET['title']);
?>
<section class="neworder-form">
<h2>Order</h2>
<div class="neworder-form-form">
<form action="neworder.inc.php" method="post">
<table>
<tr>
<td>Book ID:</td>
<td>
<input type="text" disabled="disabled" name="bookid2" value="<?= $id2 ?>">
</td>
</tr>
<tr>
<td>Book Title: </td>
<td>
<input type="text" disabled="disabled" name="title2" value="<?= $title2 ?>">
</td>
</tr>
<tr>
<td>Username: </td>
<td>
<input type="text" name="uid2" placeholder="Username...">
</td>
</tr>
<tr>
<td>Comfirmed Book ID: </td>
<td>
<input type="text" name="id2" placeholder="Please enter the Book ID....">
</td>
</tr>
</table>
<button type="submit" name="submit2">Order</button>
</form>
</div>
<?php
// Error messages
if (isset($_GET["error"])) {
if ($_GET["error"] == "emptyinput2") {
echo "<p>Fill in all fields!</p>";
}
else if ($_GET["error"] == "usernametaken2") {
echo "<p>Username already taken!</p>";
}
}
?>
</section>
2nd File:
<?php
if (isset($_POST["submit2"])) {
// First we get the form data from the URL
$uid2 = $_POST["uid2"];
$id2 = $_POST["id2"];
$title2 = $_POST["title2"];
// Then we run a bunch of error handlers to catch any user mistakes we can (you can add more than I did)
// These functions can be found in functions.inc.php
require_once "dbh.inc.php";
require_once 'functions2.inc.php';
// Left inputs empty
// We set the functions "!== false" since "=== true" has a risk of giving us the wrong outcome
if (emptyInputOrder2($uid2,$id2) !== false) {
header("location: ../neworder.php?error=emptyinput&bookid=$id2&title=$title2");
exit();
}
// Is the username exists
if (uidExists2($conn, $uid2) !== true) {
header("location: ../neworder.php?error=undefineuser");
exit();
}
// If we get to here, it means there are no user errors
// Now we insert the user into the database
createUser($conn, $uid2, $id2);
} else {
header("location: ../neworder.php");
exit();
}
The input fields are disbled, disabled inputs are not posted.
Replace $title2 = $_POST[""]; with $title2 = $_POST["title2"];
Example of what I want:
Hi i want on each row to update instant the checkbox with value 1 when checked and 0 when not checked.
I've make some steps and already taken in a URL via post the values, but I see that updates only on the first row of my table. I think it must have some foreach or loop on ajax to take value to other rows?
This value will export as a URL querystring (ischeck) to an extrnal URL to take import on my function to make the sql query to update the value.
Here is the javascript that for sure want changes about loop that I haven't put on charges.php.
<script>
$(function($) {
var arr = [];
$('input.checkbox').on('change', function() {
var id = "<?php echo $charge['id'] ?>";
var check_active = $(this).is(':checked') ? 1 : 0;
var check_id = $('[id^="checked-]');
arr.push(check_active);
var url = "ajax_ischeck.php?id=" + id + "&ischeked=" + check_active;
console.log("url", url);
if (this.checked) {
$.ajax({
url: url,
type: "GET",
dataType: 'html',
success: function(response) {
},
});
}
});
});
</script>
Here is the table with the input checkbox sry its little big the checkbox is down to last lines on Charges.php:
<tbody>
<?php foreach ($showcharge as $charge) { ?>
<tr>
<td><?php echo htmlspecialchars($charge['created_at']); ?></td>
<td><?php echo htmlspecialchars($charge['tasks']); ?> </td>
<th width="5%"><?php if (empty($charge['taskcharges'])) {
echo "Free";
} else {
echo htmlspecialchars($charge['taskcharges'] . "\xE2\x82\xAc");
} ?></th>
<th width="5%"><?php
if (empty($charge['payment'])) {
echo htmlspecialchars($charge['payment']);
} else {
echo htmlspecialchars($charge['payment'] . "\xE2\x82\xAc");
}
?>
</th>
<th width="5%" id="balance"><?= htmlspecialchars($charge['balance'] . "\xE2\x82\xAc") ?></th>
<th width="10%"><?php if (($charge['payment_date'] == 0000 - 00 - 00)) {
echo "";
} else {
echo htmlspecialchars($charge['payment_date']);
} ?></th>
<th width="10%"><?php echo htmlspecialchars($charge['admin']); ?></th>
<th width="15%"><?php echo htmlspecialchars($charge['comments']); ?></th>
<td class="mytd">
<form action="" method="POST">
<a href="editcharge.php?id=<?php echo $charge['id'];
echo '&custid=' . $customer['id'] ?>" class="btn btn-info " role=" button " aria-disabled=" true">Edit</a>
</form>
<form id="delete-<?php echo $charge['id'] ?>" onSubmit="return confirm('Are you sure you want to delete?')" method="post">
<input type="hidden" name="id_to_delete" value="<?php echo $charge['id'] ?>" />
<input type="submit" class="btn btn-danger" name=" delete" value="delete" />
</form>
<script>
$("#delete").submit(function() {
return confirm("Are you sure you want to delete?");
});
</script>
</td>
<th width="7%"> <input class="checkbox" type="checkbox" checked value="1" id="checked-1" name="checbox"> <label> Success </label> </input> </th>
</tr>
<?php } ?>
</tbody>
The ajax_ischeck.php that gets data from charges.php post :
<?php include('dataprocess.php'); ?>
<?php include('config/pdo_connect.php'); ?>
<?php
$id = $_GET['id'];
$ischeck = $_GET['ischeck'];
if(isset($_GET["ischeck"])){
Data::ischecked($id, $ischeck);
}
and the sql query:
public static function ischecked ($id, $ischeck)
{
$sql = "UPDATE charges SET
ischecked='$ischeck'
WHERE id=$id";
$statement = conn()->prepare($sql);
$statement->execute();
/* echo $sql;
die(); */
if (!$statement) {
echo "\nPDO::errorInfo():\n";
}
}
Basically I have a page that displays a seating plan using check boxes. These check boxes can be ticked to represent the seat being booked. I also have a text input where names are entered for the bookings, these forms are then posted to the next page to work out what check boxes are selected and save them in the database. This is some of the code:
title>School Hall</title>
<script>
function confirmReservation() {
var selectedList = getSelectedList('Confirm Reservation');
if (selectedList) {
if (confirm('Do you want to CONFIRM this Reservation : ' + selectedList + '?')) {
document.forms[0].statusA.value=0;
document.forms[0].statusB.value=1;
document.forms[0].previousPage.value='schoolHall';
document.forms[0].action='bookingQueries.php';
document.forms[0].submit();
} else {
clearSelection();
}
}
}
function cancelReservation() {
var selectedList = getSelectedList('cancel Reservation');
if (selectedList) {
if (confirm('Do you want to CANCEL this Reservation : ' + selectedList + '?')) {
document.forms[0].statusA.value=1;
document.forms[0].statusB.value=0;
document.forms[0].previousPage.value='schoolHall';
document.forms[0].action='bookingQueries.php';
document.forms[0].submit();
} else {
clearSelection();
}
}
}
function getSelectedList(actionSelected) {
// get selected list
var obj = document.forms[0].elements;
var selectedList = '';
for (var i = 0; i < obj.length; i++) {
if (obj[i].checked && obj[i].name == 'seats[]') {
selectedList += obj[i].value + ', ';
}
}
// no selection error
if (selectedList == '') {
alert('Please select a seat ');
return false;
} else {
return selectedList;
}
}
function validateForm()
{
var x=document.forms["0"]["fname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
}
</script>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" >
<table>
<tr><td width="100%" align="left" id='table-2'>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="previousPage" value=""/>
<input type="hidden" name="statusA" value=""/>
<input type="hidden" name="statusB" value=""/>
</tr>
<table>
<tr><td width="100%" align=left" id='table-2'>
<INPUT Type="BUTTON" VALUE="Home Page" ONCLICK="window.location.href='/final/homePage.php'" align='lef'>
<INPUT Type="BUTTON" VALUE="Bookings" ONCLICK="window.location.href='/final/schoolHallBookings.php'">
<?php
// Connection
$con = mysql_connect("localhost","root","");
if(!con)
{
die('Could not connect:' . mysql_error());
}
mysql_select_db("systemDatabase",$con); // Connection to DB
echo '<br>';
echo '<font face="Trebuchet MS" color="Black" size="9" >School Hall </font>';
$query = "SELECT * from schoolHall order by rowId, columnId"; // Create Select Query
$result = mysql_query($query); // Retrieve all data from query and hold in $result
$prevRowId = null;
$seatColor = null;
$tableRow = false;
echo "<table align='center' id='table-2'"; // Create table
while (list($rowId, $columnId, $status, $updatedby, $firstName, $lastName) = mysql_fetch_row($result)) // Itterates through fetched data
{
if ($prevRowId != $rowId)
{
if ($rowId != 'A')
{
echo "</tr></table></td>";
echo "\n</tr>";
}
$prevRowId = $rowId;
echo "\n<tr><td align='center'><table class='center' border='1' cellpadding='15' cellspacing='8' align='center' id='table-2' ><tr>";
}
else
{
$tableRow = false;
}
if ($status == 0)
{
$seatColor = "lightgreen"; // Available
}
else
{
$seatColor = "red"; // Booked
}
echo "\n<td bgcolor='$seatColor' align='center'>";
echo "$rowId$columnId";
if ($status == 0 || ($status == 1)) {
echo "<input type='checkbox' name='seats[]' value='$rowId$columnId' align='center'></checkbox>"; // Create Checkboxes giving value RowId, ColumnId
}
}
echo "</tr></table></td>";
echo "</tr>";
echo "</table>";
// Con close
mysql_close();
?>
<table width='100%' border='0'>
<tr><td align='right'>
First Name: <input type="text" name="fname">
Last Name: <input type="text" name="lname">
</td>
<td><td align='left'>
</td>
<td><td align ='right'>
<input type='button' value='Confirm Reservation' onclick='confirmReservation()'/>
</td></tr>
<tr>
<td><td align='left'>
</td>
<td><td align='left'>
</td>
<td align='right'>
<input type='button' value=' Cancel Reservation' onclick='cancelReservation()'>
</td>
</table>
</td></tr>
<tr><td width="100%" align="center">
</td></tr>
<tr><td> </td></tr>
<tr><td width="100%" align="center">
<table border="1" cellspacing="6" cellpadding="4" align="center">
<tr>
<td bgcolor='lightgreen'>Available</td>
<td bgcolor='red'>Unavailable</td>
</tr>
</table>
</td></tr>
<tr><td> </td></tr>
<tr><td width="100%" align="center">
</td></tr>
</table>
</body>
Is there any way i can incorporate validation with my current code? I need the names text checked to make sure there is actually a name entered. This needs to happen before the next page is accessed. Any ideas?
Try first add ids to your text input:
<table width='100%' border='0'>
<tr>
<td align='right'>
First Name: <input type="text" id="fname" name="fname"/>
Last Name: <input type="text" id="lname" name="lname"/>
</td>
<td>
<td align='left'>
function getSelectedList(actionSelected) {
// get selected list
var obj = document.forms[0].elements;
var selectedList = '';
for (var i = 0; i < obj.length; i++) {
if (obj[i].checked && obj[i].name == 'seats[]') {
selectedList += obj[i].value + ', ';
}
}
var fname = document.getElementById('fname');
var lname = document.getElementById('lname');
// no selection error
if (selectedList == '') {
alert('Please select a seat ');
return false;
} else if (actionSelected.beginsWith('Confirm') && (fname .value.replace(/^\s+|\s+$/g, '').length == 0 || /[0-9]/.test(fname))) {
alert('Please Enter valid first name.');
return false;
} else if (actionSelected.beginsWith('Confirm') && (lname.value.replace(/^\s+|\s+$/g, '').length == 0 || /[0-9]/.test(lname))) {
alert('Please Enter valid last name.');
return false;
} else {
return selectedList;
}
}
Working example
http://jsfiddle.net/
The below example demonstrates how you can pass a value to the function checkInput and it will determine whether or not it is a valid input - the function uses jQuery but you can do it whthout jQuery too.
Demo HTML:
<form>
<input id="first-name" value="some value" />
<input id="last-name" value="" />
</form>
JS Function (goes with HTML demo):
function checkInput(fieldID){
var isValid = true;
if($("#" + fieldID).val() == ''){
isValid = false;
}
return isValid;
}
$(document).ready(function(){
if(!checkInput("first-name")){
alert("error found with first name");
}
if(!checkInput("last-name")){
alert("error found with last name");
}
});
when i press on edit link on detail.php it will show me data.php page with data filled in form... now if i want to edit something then press edit button it would be update.. code of data.php is given as below
<?php if(isset($_GET['name']) && !empty($_GET['name'])):?>
<script>
window.onload=function()
{
document.getElementById("sbmt").style.visibility="hidden";
};
function editform()
{
i need code at this place _what should it be?? i guess i need ajax. when i press edit button it would be edit record i tried below something like below bt for that i need value name=??? how can i get that value _
<?php
$con=mysqli_connect("localhost","root","","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// mysqli_query($con,"UPDATE user_detail SET name=,address=,gender=,hoby=,country=,place=,
//WHERE name='$_GET['name']'");
mysqli_close($con);
?>
};
</script>
<?php
$con=mysqli_connect("localhost","root","","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$p= $_GET['name'];
//echo "$p";
$result = mysqli_query($con,"SELECT * FROM user_detail where name ='$p' ");
$data =mysqli_fetch_array($result);
mysqli_close($con);
?>
<?php else:?>
<script>
window.onload=function()
{
document.getElementById("edit").style.visibility="hidden";
};
</script>
<?php $data =array();?>
<?php endif;?>
<!DOCTYPE html>
<?php
session_start();
if (!isset($_SESSION['txt_user'])) {
header('Location: Login.php');
}
?>
<html>
<head>
<title> Form with Validation </title>
<script language="JavaScript">
var flag=0;
var file_selected = false;
var file_selected1 = false;
function validform()
{
var x=document.forms["form1"]["tname"].value;//Name
var y=document.forms["form1"]["address"].value;//Address
if (x==null || x=="")
{
flag = 1;
document.getElementById('tn').value="Please! Enter name ";
//alert("Please Enter Name:");
//return false;
}
else
{
flag=0;
}
if (y==null || y==" ")
{
flag=flag+1;
document.getElementById('ta').innerHTML="Please! Enter address ";
//alert("Please Enter Address");
//return false;
}
else
{
flag=0;
}
if ((form1.gender[0].checked == false) && (form1.gender[1].checked == false))
{
flag +=1;
document.getElementById('gne').innerHTML="Please! Select gender ";
//alert("Pleae Select Gender");
//return false;
}
else
{
flag =0;
document.getElementById('gne').innerHTML="";
}
if (form1.hobby.checked == false && form1.hobby.checked == false && form1.hobby.checked == false)
{
flag +=1;
document.getElementById('hbe').innerHTML="Please! Select hobby ";
//alert ('Please!!!, Select any hobby!');
//return false;
}
else
{
flag =0;
document.getElementById('hbe').innerHTML="";
}
var psel=document.getElementById('fp'); //Favourite place
var valid = false;
for(var i = 0; i < psel.options.length; i++) {
if(psel.options[i].selected) {
valid = true;
break;
}
}
if(valid==false)
{
flag +=1;
document.getElementById('fp_error').innerHTML="Please! Select Any Favourite Place ";
//return false;
// alert("Please! Select Any Favourite Place ");
}
else
{
flag =0;
document.getElementById('fp_error').innerHTML="";
}
if(!file_selected)
{
flag +=1;
document.getElementById('f_pic').innerHTML="Please! Select Any Picture ";
//alert('Please Select any Picture');
//return false;
}
else
{
flag =0;
document.getElementById('f_pic').innerHTML="";
}
if(!file_selected1)
{
flag +=1;
document.getElementById('f_doc').innerHTML="Please! Select Document";
//alert('Please Select any Document');
//return false;
}
else
{
flag =0;
}
if(flag ==0)
{
document.getElementById('data_form').action = "Data_con.php";
document.getElementById('data_form').submit();
}
else
{
return true;
}
return false;
}
function Logout()
{
document.getElementById('data_form').action = "Logout.php";
}
</script>
</head>
<body>
<!--onsubmit="return validform()"-->
<form id="data_form" name="form1" method="post" enctype="multipart/form-data" action="">
<table align="center" border="2">
<tr>
<td>Name:</td>
<td><input id="tn" type="text" name="tname" <?php if($data['name']):?>value="<?php echo $data['name'];?>" <?php endif;?>></td>
<!--<td id="tne"></td>-->
</tr>
<tr>
<td>Address:</td>
<td><textarea id= "ta" rows="3" cols="16" name="address" >
<?php echo $data['address'];?>
</textarea> </td>
<!--<td id="tae"></td>-->
</tr>
<tr>
<td>Gender:</td>
<?php
$x=$data['gender'];
?>
<td> <input type="radio" id="gn" name="gender" value="male" <?php if($x=='male'):?> checked<?php endif;?> > Male
<input type="radio" id="gn" name="gender" value="female" <?php if($x=='female'):?> checked<?php endif;?> > Female
</td>
<td id="gne"></td>
</tr>
<tr>
<td>Hobby:</td>
<?php
$y=$data['hoby'];
?>
<td>
<input type="checkbox" name="hobby" value="hockey" <?php if($y=='hockey'):?> checked='checked';<?php endif;?>> Hockey
<input type="checkbox" name="hobby" value="reading" <?php if($y=='reading'):?> checked='checked';<?php endif;?>> Reading<br>
<input type="checkbox" name="hobby" value="traveling" <?php if($y=='traveling'):?> checked='checked';<?php endif;?>> Traveling
<br>
</td>
<td id="hbe"></td>
</tr>
<tr>
<td>Country: </td>
<?php
$z=$data['country'];
?>
<td>
<select name="helo" id="hl">
<option value="germany"<?php if($z=='germany'):?> selected<?php endif;?> >Germany </option>
<option value="india" <?php if($z=='india'):?> selected <?php endif;?> >India </option>
<option value="japan" <?php if($z=='japan'):?> selected<?php endif;?> >Japan </option>
</select>
</td>
<td id="hle"></td>
</tr>
<tr>
<td>Favourite Place:</td>
<?php
$w =$data['place'];
?>
<td>
<select id="fp" name="place" multiple="multiple">
<option value="ahmedabad" <?php if($w=='ahmedabad'):?> selected<?php endif;?> >Ahmedabad</option>
<option value="nadiad" <?php if($w=='nadiad'):?> selected<?php endif;?> >Nadiad</option>
<option value="anand" <?php if($w=='anand'):?> selected<?php endif;?> >Anand</option>
<option value="vadodara" <?php if($w=='vadodara'):?> selected<?php endif;?> >Vadodara</option>
<option value="surat" <?php if($w=='surat'):?> selected<?php endif;?> >Surat</option>
</select>
</td>
<td id="fp_error"></td>
</tr>
<tr>
<td>Photo:</td>
<td><input type="file" onchange="file_selected=true;" name="pic" ></td>
<td id="f_pic"></td>
</tr>
<tr>
<td>Resume:</td>
<td><input type="file" onchange="file_selected1=true;" name="doc" ></td>
<td id="f_doc"></td>
</tr>
<tr>
<td colspan="2"><center>
<input type="Submit" id="edit" value="edit" Name="Edit" onclick="editform();">
<input type="button" id="sbmt" value="Submit" Name="Submit" onclick="validform();">
<input type="submit" value="Logout" Name="Submit" onclick="Logout();">
<center></td>
</tr>
</table>
</form>
</body>
</html>
Thanks friend...
I am trying to create a form in which a logged in user can enter a sale (ltd_entry_amount), but only sales that are $200.00 or more, but with no luck. If I get rid of the '> 199.99' the form works ok but for now the 'Please check all manatory fields are complete and try again.' message shows. Can anyone help?
<?php
require_once ('./includes/config.inc.php');
$page_title = 'Log a Sale';
include ('./includes/header.html');
if (!isset($_SESSION['ltd_user_id'])) {
$url = 'http://' . $_SERVER['HTTP_HOST']
. dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1); // Chop off the slash.
}
$url .= '/login.php';
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.
}
$users = $_SESSION['ltd_user_id'];
if (isset($_POST['submitted'])) {// Handle the form.
require_once ('database.php');
// Connect to the database.
$errors = array(); // Initialize error array.
// Check for a Invoice Number.
if (empty($_POST['ltd_invoice_no'])) {
$errors[] = '<p>• You forgot to enter your Invoice Number.</p>';
} else {
$inv = escape_data($_POST['ltd_invoice_no']);
}
// Check for invoice amount.
if (empty($_POST['ltd_entry_amount']) < 199.99) {
$errors[] = '<p>• You forgot to enter your Total Amount. Please ensure it is at least $200.00</p>';
} else {
$amount = escape_data($_POST['ltd_entry_amount']);
}
// Check for business name.
if (empty($_POST['ltd_business_name'])) {
$errors[] = '• You forgot to enter your Dealership Name.';
} else {
$dealer = escape_data($_POST['ltd_business_name']);
}
if (empty($errors) && $amount) { // If everything's OK. // If everything's OK.
// Make sure the invoice number is available.
$uid = #mysql_insert_id(); //Get the url ID.
// Add the user.
$query = "INSERT INTO ltd_sales_list (ltd_item_id , ltd_user_id, ltd_invoice_no, ltd_entry_amount, ltd_entry_userdate, ltd_business_name, ltd_entry_date) VALUES
('$uid', '$users', '$inv', '$amount', '$_POST[ltd_entry_userdate]', '$dealer' , NOW())";
$result = #mysql_query ($query); // Run the query.
if (mysql_affected_rows() == 1) {
// If it ran OK.
echo 'Your sale is registered into the system.';
include ('./includes/footer.html'); // Include the HTML footer.
exit();
} else { // If it did not run OK.
echo 'You could not be registered due to a system error. We apologize for any inconvenience.';
}
} else { // If one of the data tests failed.
echo 'Please check all manatory fields are complete and try again.';
}
mysql_close(); // Close the database connection.
} // End of the main Submit conditional.
?>
<form action="logsale.php" method="post">
<table width="550" border="0" cellspacing="1" cellpadding="5">
<tr>
<td width="250"><div align="right">Invoice Number <span class="red_light">*</span></div></td>
<td width="267">
<input type="text" name="ltd_invoice_no" size="30" maxlength="30" value="<?php if (isset($_POST['ltd_invoice_no'])) echo $_POST['ltd_invoice_no']; ?>" /></td>
</tr>
<tr>
<td><div align="right">Total Amount of sale
<em><strong>(exc. GST)</strong></em> <span class="red_light">*</span></div></td>
<td>
<input type="text" name="ltd_entry_amount" size="30" maxlength="30"
value="<?php if (isset($_POST['ltd_entry_amount'])) echo $_POST['ltd_entry_amount']; ?>" /></td>
</tr>
<tr>
<td></td>
<td>Please enter number only</td>
</tr>
<tr>
<td><div align="right">Date of Invoice</div></td>
<td>
<script type="text/javascript">
$(function() {
$("#datepicker").datepicker({ dateFormat: "dd/mm/yy" }).val()
});
</script>
<input size="30" maxlength="10" id="datepicker" name="ltd_entry_userdate" type="text" value="<?php if (isset($_POST['ltd_entry_userdate'])) echo $_POST['ltd_entry_userdate']; ?>" /></td>
</tr>
<tr>
<td></td>
<td><span class="sml_italics"><strong>Please enter as <strong>DD-MM-YYYY</strong></td>
</tr>
<tr>
<td><div align="right">Dealership <span class="red_light">*</span></div></td>
<td><input type="text" name="ltd_business_name" size="50" maxlength="60" value="<?php if (isset($_POST['ltd_business_name'])) echo $_POST['ltd_business_name']; ?>" /></td>
</tr>
<tr>
<td></td>
<td><p><input type="submit" name="submit" value="Submit" /></p><input type="hidden" name="submitted" value="TRUE" />
</td>
</tr>
</table>
</form>
<?php
include ('./includes/footer.html');
?>
if (empty($_POST['ltd_entry_amount']) < 199.99) {
You are comparing a boolean value with a float number
You must separate both conditions:
if(empty($_POST['ltd_entry_amount']) or $_POST['ldt_entry_amount'] < 199.99){
It looks like there is a problem with your if statement:
if (empty($_POST['ltd_entry_amount']) < 199.99)
should be
if (empty($_POST['ltd_entry_amount']) || $_POST['ltd_entry_amount'] < 199.99)