PHP prints out 1,458 MYSQL jquery 1072 - php

I am not sure why, but when I run the following MySQL query it returns 1458 results. It then puts those results in a JSON format, which my jQuery script then outputs, but for some reason it is only returning 1072 and also takes around 15 seconds for it to show. Included is the jQuery script I made.
SELECT
customer.customer_id,
customer.HQStatus,
date_format(customer.CreatedTime, '%d-%m-%Y') as CreatedTime,
date_format(customer.ModifiedDate, '%d-%m-%Y') as ModifiedDate,
customer.AMStatus,
customer.LeadOwnerId,
customer.Company,
customer.TradingName,
customer.FirstName,
customer.LastName,
customer.LeadStatus,
customer.Phone,
customer.Email,
user.firstname as stafffirstname,
user.lastname as stafflastname
FROM
customer_detail as customer,
admin_userlogin as user
WHERE user.id = customer.LeadOwnerId
ORDER BY customer.CreatedTime DESC
jQuery code is a little big:
function listallleads(){
$.getScript('js/quicksearch.js', function(data, textStatus){});
$.getScript('js/cornz.js', function(data, textStatus){});
numberofleads = null;
$.getJSON('system/classes/core.php?task=listmyleads&userid='+userid+'&usertype='+usertype+'&callback=?', function(dataleads) {
$.each(dataleads,function(i, myleads){
numberofleads = i;
var businessname = "";
if(myleads.Company == null || myleads.Company == "null" || myleads.Company == "")
{
businessname = myleads.TradingName;
}
else
{
businessname = myleads.Company;
}
if(myleads.ho > 1)
{
myleads.ho = "Complete";
}
else
{
myleads.ho = "Pending";
}
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "Confirmed";
}
else if(myleads.AMStatus == "3")
{
myleads.AMStatus = "Canceled";
}
else if(myleads.AMStatus == "4")
{
myleads.AMStatus = "Does Not Have Mobile";
}
else if(myleads.AMStatus == "5")
{
myleads.AMStatus = "Not Contactable";
}
else if(myleads.AMStatus == "6")
{
myleads.AMStatus = "Re-Send Welcome Pack";
}
else if(myleads.AMStatus == "7")
{
myleads.AMStatus = "Welcome Pack Sent";
}
else if(myleads.AMStatus == "8")
{
myleads.AMStatus = "Swipe Confirmed";
}
else if(myleads.AMStatus == "9")
{
myleads.AMStatus = "Refussed Banking Details";
}
else
{
myleads.AMStatus = "Not Confirmed";
}
leadstatus = leadstatusselect(myleads.LeadStatus);
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "one";
}
if(myleads.AMStatus == "3")
{
myleads.AMStatus = "red";
}
if(myleads.HQStatus == 0)
{
myleads.HQStatus = "Please Select";
}
else if(myleads.HQStatus == 2)
{
myleads.HQStatus = "iNcard Loaded $1";
}
else if(myleads.HQStatus == 3)
{
myleads.HQStatus = "iNcard Loaded $5";
}
else if(myleads.HQStatus == 4)
{
myleads.HQStatus = "Terminal Verified";
}
var s = myleads.Phone;
s = s.replace('(', '');
s = s.replace(')', '');
s = s.replace(/ /g, '');
myleads.Phone = s;
//alert(s);
cssstats = "lead"+myleads.AMStatus;
$("tbody").append('<tr id="'+myleads.customer_id+'" class="'+cssstats+'">'+
' <td id="row" class="small"><input id="'+myleads.customer_id+'" type="checkbox"></td>'+
' <td class="field">'+myleads.CreatedTime+'</td>'+
' <td class="field">'+myleads.stafffirstname+'</td>'+
' <td class="companysize">'+businessname+'</td>'+
' <td class="field">'+myleads.FirstName+' '+myleads.LastName+'</td>'+
' <td class="field">'+myleads.Phone+'</td>'+
' <td class="field" class="leadstatus">'+leadstatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.AMStatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.HQStatus+'</td>'+
' <td class="bigger temail">'+myleads.Email+'</td>'+
' <td class="last field">'+myleads.ModifiedDate+'</td>'+
' </tr>');
});
qs.cache();
});
if(usertype == 3)
{
leadtype = "A/M Status";
}
else
{
leadtype = "Lead Status";
}
$("#todo_bg").hide();
$("#menuarea").html('<a id="gotohome"><div id="backmain" class="backbg">Back</div></a><div id="nav" class="backbgright">Manage Business Lead</div>'+
'<div id="dowithleads"><button id="selectall" class="blackbutton export"><input type="checkbox" class="checkbox checkall" value="Yes" style="float:left;">Select All</button><button id="editlisting" class="blackbutton manage">Edit Listing</button><button id="sendemailout" class="blackbutton manage">Send Message</button> <button id="deletelead" class="blackbutton manage">Delete Lead</button>'+
'<div id="searchbox"><input type="text" name="search" value="" id="searchleads" placeholder="Search" autofocus /></div>'+
'</div>'+
'<div id="dowithleads" style="width:980px; overflow:scroll;"><table cellpadding="0" cellspacing="0" border="0" class="sortable paginated scrollTable" id="manageleads" style="text-align:left;">'+
' <thead class="fixedHeader">'+
' <tr>'+
' <th class="small" id="first"></th>'+
' <th class="field" class="ui-tableFilter-date">Created</th>'+
' <th class="field">Lead Owner</th>'+
' <th class="companysize">Trading Name</th>'+
' <th class="field">Customer Name</th>'+
' <th class="field">Phone No.</th>'+
' <th class="field" class="leadstatus">Lead Status</th>'+
' <th class="field" class="hostatus" style="display:hidden;">A/M Status</th>'+
' <th class="field" class="hostatus" style="display:hidden;">H/Q Status</th>'+
' <th id="emails" class="bigger">Email</th>'+
' <th class="field">Mod Date</th>'+
' </tr>'+
' </thead>'+
' <tbody class="scrollContent"></tbody>'+
'</table></div><div id="noloeads" style="float:right; margin:5px;"></div>');
if(usertype == 1 || usertype == 3 || usertype == 4)
{
$("#dowithleads").append('<button id="printlisting" class="blackbutton manage">Print W/P Letter</button>');
}
if(usertype == 1 || usertype == 3 || usertype == 4)
{
$("#dowithleads").append('<button id="exportlisting" class="blackbutton export">Export</button>');
}
if(usertype == 1)
{
$('.hostatus').show();
}
if(usertype ==3)
{
$('.hostatus').show();
$('.leadstatus').hide();
}
var script = document.createElement('link');
script.href = 'theme/style/manageleads.css';
script.rel = 'stylesheet';
script.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(script);
if ($.browser.msie && $.browser.version == 8) {
var script = document.createElement('link');
script.href = 'theme/style/ie-manageleads.css';
script.rel = 'stylesheet';
script.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(script);
}
setTimeout(function(){
setTimeout(function(){
$("table").tableFilter({ dialog: { modal: false } });
updatecounter(numberofleads);
},90);
var qs = $('input#searchleads').quicksearch('table#manageleads tbody tr');
},2000);
}

I fixed the issue by the following. I will say this is NOT the best way to do it.
function listallleads(){
$.getScript('js/quicksearch.js', function(data, textStatus){});
$.getScript('js/cornz.js', function(data, textStatus){});
var number;
$.getJSON('system/classes/core.php?task=listmyleads&userid='+userid+'&usertype='+usertype+'&callback=?', function(dataleads) {
number = dataleads.length;
$.each(dataleads,function(i, myleads){
numberofleads = i;
var businessname = "";
if(myleads.Company == null || myleads.Company == "null" || myleads.Company == "")
{
businessname = myleads.TradingName;
}
else
{
businessname = myleads.Company;
}
if(myleads.ho > 1)
{
myleads.ho = "Complete";
}
else
{
myleads.ho = "Pending";
}
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "Confirmed";
}
else if(myleads.AMStatus == "3")
{
myleads.AMStatus = "Canceled";
}
else if(myleads.AMStatus == "4")
{
myleads.AMStatus = "Does Not Have Mobile";
}
else if(myleads.AMStatus == "5")
{
myleads.AMStatus = "Not Contactable";
}
else if(myleads.AMStatus == "6")
{
myleads.AMStatus = "Re-Send Welcome Pack";
}
else if(myleads.AMStatus == "7")
{
myleads.AMStatus = "Welcome Pack Sent";
}
else if(myleads.AMStatus == "8")
{
myleads.AMStatus = "Swipe Confirmed";
}
else if(myleads.AMStatus == "9")
{
myleads.AMStatus = "Refussed Banking Details";
}
else
{
myleads.AMStatus = "Not Confirmed";
}
leadstatus = leadstatusselect(myleads.LeadStatus);
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "one";
}
if(myleads.AMStatus == "3")
{
myleads.AMStatus = "red";
}
if(myleads.HQStatus == 0)
{
myleads.HQStatus = "Please Select";
}
else if(myleads.HQStatus == 2)
{
myleads.HQStatus = "iNcard Loaded $1";
}
else if(myleads.HQStatus == 3)
{
myleads.HQStatus = "iNcard Loaded $5";
}
else if(myleads.HQStatus == 4)
{
myleads.HQStatus = "Terminal Verified";
}
var s = myleads.Phone;
s = s.replace('(', '');
s = s.replace(')', '');
s = s.replace(/ /g, '');
myleads.Phone = s;
//alert(s);
cssstats = "lead"+myleads.AMStatus;
$("tbody").append('<tr id="'+myleads.customer_id+'" class="'+cssstats+'">'+
' <td id="row" class="small"><input id="'+myleads.customer_id+'" type="checkbox"></td>'+
' <td class="field">'+myleads.CreatedTime+'</td>'+
' <td class="field">'+myleads.stafffirstname+'</td>'+
' <td class="companysize">'+businessname+'</td>'+
' <td class="field">'+myleads.FirstName+' '+myleads.LastName+'</td>'+
' <td class="field">'+myleads.Phone+'</td>'+
' <td class="field" class="leadstatus">'+leadstatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.AMStatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.HQStatus+'</td>'+
' <td class="bigger temail">'+myleads.Email+'</td>'+
' <td class="last field">'+myleads.ModifiedDate+'</td>'+
' </tr>');
});
qs.cache();
});
setTimeout(function(){
var n = $('tbody tr:not(.ui-tableFilter-hidden)').size();
checknewleads(n,number);
},7000);
if(usertype == 3)
{
leadtype = "A/M Status";
}
else
{
leadtype = "Lead Status";
}
$("#todo_bg").hide();
$("#menuarea").html('<a id="gotohome"><div id="backmain" class="backbg">Back</div></a><div id="nav" class="backbgright">Manage Business Lead</div>'+
'<div id="dowithleads"><div style="width:100px;float:left;"><input type="checkbox" class="checkbox checkall" value="Yes" style="float:left;">Select All</div><button id="editlisting" class="blackbutton manage">Edit Listing</button><button id="sendemailout" class="blackbutton manage">Send Message</button> <button id="deletelead" class="blackbutton manage">Delete Lead</button>'+
'<div id="searchbox"><input type="text" name="search" value="" id="searchleads" placeholder="Search" autofocus /></div>'+
'</div>'+
'<div id="dowithleads" style="width:980px; overflow:scroll;"><table cellpadding="0" cellspacing="0" border="0" class="sortable paginated scrollTable" id="manageleads" style="text-align:left;">'+
' <thead class="fixedHeader">'+
' <tr>'+
' <th class="small" id="first"></th>'+
' <th class="field" class="ui-tableFilter-date">Created</th>'+
' <th class="field">Lead Owner</th>'+
' <th class="companysize">Trading Name</th>'+
' <th class="field">Customer Name</th>'+
' <th class="field">Phone No.</th>'+
' <th class="field" class="leadstatus">Lead Status</th>'+
' <th class="field" class="hostatus" style="display:hidden;">A/M Status</th>'+
' <th class="field" class="hostatus" style="display:hidden;">H/Q Status</th>'+
' <th id="emails" class="bigger">Email</th>'+
' <th class="field">Mod Date</th>'+
' </tr>'+
' </thead>'+
' <tbody class="scrollContent"></tbody>'+
'</table></div><div id="noloeads" style="float:right; margin:5px;"></div>');
if(usertype == 1 || usertype == 3 || usertype == 4)
{
$("#dowithleads").append('<button id="printlisting" class="blackbutton manage">Print W/P Letter</button>');
}
if(usertype == 1 || usertype == 3 || usertype == 4)
{
$("#dowithleads").append('<button id="exportlisting" class="blackbutton export">Export</button>');
}
if(usertype == 1)
{
$('.hostatus').show();
}
if(usertype ==3)
{
$('.hostatus').show();
$('.leadstatus').hide();
}
var script = document.createElement('link');
script.href = 'theme/style/manageleads.css';
script.rel = 'stylesheet';
script.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(script);
if ($.browser.msie && $.browser.version == 8) {
var script = document.createElement('link');
script.href = 'theme/style/ie-manageleads.css';
script.rel = 'stylesheet';
script.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(script);
}
setTimeout(function(){
setTimeout(function(){
$("table").tableFilter({ dialog: { modal: false } });
//updatecounter(numberofleads);
},90);
var qs = $('input#searchleads').quicksearch('table#manageleads tbody tr');
},2000);
}
function checknewleads(a,e)
{
a = a+1;
$.getJSON('system/classes/core.php?task=checkmyleads&fromid='+a+'&toid='+e+'&userid='+userid+'&usertype='+usertype+'&callback=?', function(dataleadstwo) {
$.each(dataleadstwo,function(i, myleads){
numberofleads = i;
var businessname = "";
if(myleads.Company == null || myleads.Company == "null" || myleads.Company == "")
{
businessname = myleads.TradingName;
}
else
{
businessname = myleads.Company;
}
if(myleads.ho > 1)
{
myleads.ho = "Complete";
}
else
{
myleads.ho = "Pending";
}
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "Confirmed";
}
else if(myleads.AMStatus == "3")
{
myleads.AMStatus = "Canceled";
}
else if(myleads.AMStatus == "4")
{
myleads.AMStatus = "Does Not Have Mobile";
}
else if(myleads.AMStatus == "5")
{
myleads.AMStatus = "Not Contactable";
}
else if(myleads.AMStatus == "6")
{
myleads.AMStatus = "Re-Send Welcome Pack";
}
else if(myleads.AMStatus == "7")
{
myleads.AMStatus = "Welcome Pack Sent";
}
else if(myleads.AMStatus == "8")
{
myleads.AMStatus = "Swipe Confirmed";
}
else if(myleads.AMStatus == "9")
{
myleads.AMStatus = "Refussed Banking Details";
}
else
{
myleads.AMStatus = "Not Confirmed";
}
leadstatus = leadstatusselect(myleads.LeadStatus);
if(myleads.AMStatus == "1")
{
myleads.AMStatus = "one";
}
if(myleads.AMStatus == "3")
{
myleads.AMStatus = "red";
}
if(myleads.HQStatus == 0)
{
myleads.HQStatus = "Please Select";
}
else if(myleads.HQStatus == 2)
{
myleads.HQStatus = "iNcard Loaded $1";
}
else if(myleads.HQStatus == 3)
{
myleads.HQStatus = "iNcard Loaded $5";
}
else if(myleads.HQStatus == 4)
{
myleads.HQStatus = "Terminal Verified";
}
var s = myleads.Phone;
s = s.replace('(', '');
s = s.replace(')', '');
s = s.replace(/ /g, '');
myleads.Phone = s;
//alert(s);
cssstats = "lead"+myleads.AMStatus;
$("tbody").append('<tr id="'+myleads.customer_id+'" class="'+cssstats+'">'+
' <td id="row" class="small"><input id="'+myleads.customer_id+'" type="checkbox"></td>'+
' <td class="field">'+myleads.CreatedTime+'</td>'+
' <td class="field">'+myleads.stafffirstname+'</td>'+
' <td class="companysize">'+businessname+'</td>'+
' <td class="field">'+myleads.FirstName+' '+myleads.LastName+'</td>'+
' <td class="field">'+myleads.Phone+'</td>'+
' <td class="field" class="leadstatus">'+leadstatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.AMStatus+'</td>'+
' <td class="field" class="hostatus" style="display:hidden;">'+myleads.HQStatus+'</td>'+
' <td class="bigger temail">'+myleads.Email+'</td>'+
' <td class="last field">'+myleads.ModifiedDate+'</td>'+
' </tr>');
});
qs.cache();
});
setTimeout(function(){
setTimeout(function(){
$("table").tableFilter({ dialog: { modal: false } });
updatecounter(numberofleads);
},90);
var qs = $('input#searchleads').quicksearch('table#manageleads tbody tr');
},2000);
}

Related

This code is supposed to output a temperature converting table for the user once they input a start end and increment temp

My error because the user inputted a non numerical value, the if else statement to change the value of the incrementing value to a positive number if the user inputs a negative value and the change if the start value is greater that the stop value is not working either.
<?php
$banner = "Self-referring Forms w/Data Validation";
include ("./header.php");
$start = "";
$stop = "";
$incr = "";
$error = "";
$output = "";
$checkResult = false;
$MAX_ITERATIONS = 100;
?>
<h2><?php echo $output; ?></h2>
<h3><?php echo $error; ?></h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
<p id="para6">Starting Temperature: <input
type="text" name="starting_number" size="12"<?php ?>/><br/>
<p id="para6">Stop Temperature :
<input type="text" name="stop_number" size="12" /><br/>
<p id="para6">Temperature Increment: <input type="text"
name="increment_number" size="12" /><br/></p>
<input id="para6" type="submit" value="Create Temperature Conversion Table" name="calculate"/>
<?php
error_reporting(E_ERROR | E_PARSE);
try
{
if($_SERVER["REQUEST_METHOD"] == "GET"){
$start = "";
$stop = "";
$incr = "";
}
else if($_SERVER["REQUEST_METHOD"] == "POST")
{
$start=(double)trim($_POST["starting_number"]);
$stop=(double)trim($_POST["stop_number"]);
$incr=(double)trim($_POST["increment_number"]);
$num = (double)($stop-$start)/$incr;
if($start == "" || $stop == "" || $incr == "" || $num == "")
{
//means the user did not enter anything
$error .= "The text boxes cannot be blank.";
echo $error;
}
else if($num>$MAX_ITERATIONS)
{
$error .= "The conditions will cause too many iterations (max. 100), therefore (for the
sake of server resources) your request is denied.";
echo $error;
}
This is where I need help
else if($start >= $stop)
{
$start == $stop;
$stop == $start;
}
else if($incr == "0")
{
$error .= "You must enter a non-zero increment.";
echo $error;
}
else if($incr < "0")
{
$incr == $incr * (-1);
}
else if($start == input type="text" || $stop == input type="text" ||$incr == input
type="text" || $num == input type="text")
{
$error .= "You must enter a numerical value";
echo $error;
}
The rest is just for you to see what the rest of my code looks like
else
{
echo "<table border='1'>";
echo "<tr>";
echo "<th>Celcius</th>";
echo "<th>Fahrenheit</th>";
echo "</tr>";
for($i=$start; $i<=$stop; $i += $incr)
{
echo "<tr>";
echo "<td>". $i . "°</td>";
echo "<td>". (($i * 9/5) + 32 ). "°</td>";
echo "</tr>";
}
echo "</table>";
}
if($error == "")
{
$output = "";
}
else
{
$error .= "<br/>Please try again.";
}
}
}
catch(DivisionByZeroError $e)
{
echo "The text boxes cannot be blank.";
}
catch(Exception $e)
{
echo 'Please Enter correctly';
}
?>
</form>
<?php
include ("./footer.php");
?>

Validation using jquery&CSS not working

I'm trying (without success :/ ) to do a form validation to the "name" & "description" fields in a table before clicking the button (a live validation).
I mean, the button "submit" wont do anything before everything it's correct.
Name allows 50 characters only, and cannot be empty (if empty or higher than 50 a red alert should appear)
Description does not allow numbers and only 255 characters (if you insert a number or higher than 255 an alert should appear)
Here is my code, i tried so hard and i don´t know what to do.
<?php include('connect.php');
$error="";
if(isset($_GET['editar']))
{
$ident=$_GET['iden'];
$row=mysql_query("SELECT * FROM subjects WHERE id=$ident");
$st_row=mysql_fetch_array($row);
}
$sqlm = mysql_query("SELECT * FROM careers");
$options = "";
while($resultado = mysql_fetch_array($sqlm)){
$options .= "<option value='".$resultado['id']."'>".$resultado['nombre']."</option>";
}
?>
<h2 align="center">UPDATE SUBJECTS</h2>
<form method="Post" action=''>
<table align="center">
<tr>
<td>Career:</td>
<td><select name='txtcarreras_id'><?php echo $options; ?></td>
</tr>
<tr>
<td>Name:</td>
<td><input type='text' class="form-text" id="form-name" name='txtnombre' value="<?PHP echo $st_row['nombre'] ?>"/><span class="error-form" id="error-name"></td>
</tr>
<tr>
<td>Description:</td>
<td><input type='text' class="form-text" id="form-description" name='txtdescripcion' value="<?PHP echo $st_row['descripcion'] ?>"/><span class="error-form" id="error-description"></td>
</tr>
<tr>
<td>Hours:</td>
<td>
<select name='txtcarga_horaria'/>
<option <?php if($carga_horaria=='1') echo 'selected' ; ?> value="2">2 (dos)</option>
<option <?php if($carga_horaria=='1') echo 'selected' ; ?> value="4">4 (cuatro)</option>
<option <?php if($carga_horaria=='1') echo 'selected' ; ?> value="6">6 (seis)</option>
<option <?php if($carga_horaria=='1') echo 'selected' ; ?> value="8">8 (ocho)</option>
<option <?php if($carga_horaria=='1') echo 'selected' ; ?> value="10">10 (diez)</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type='submit' value="save" name='btnsave'/></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['btnsave']))
{
$carreras_id=$_POST['txtcarreras_id'];
$nombre=$_POST['txtnombre'];
$descripcion=$_POST['txtdescripcion'];
$carga_horaria=$_POST['txtcarga_horaria'];
$a_sql=mysql_query("UPDATE subjects SET carrera_id='$career_id', name='$nombre', description='$descripcion', hours='$carga_horaria' WHERE id='$ident'");
if($a_sql)
{
header("location:index.php");//
}
}
?>
<script>
function lettersonly(input){
var regex = /[^a-z]/gi;
input.value = input.value.replace(regex, "");
}
</script>
<script>
$(function()){
$("#error-name").hide();
// $("#error-description").hide();
var error_name = false;
// var error_description= false;
$("#form-name").focusout(function() {
check_name();
});
function check_name(){
var nombre_length = $("#form_name").val().length;
if(nombre_length > 50)
{
$("#error-name").html("NO DEBE SUPERAR LOS 50 CARACTERES");
$("#error-name").show();
error_name = true;
}else {
$("#error-name").hide();
}
}
</script>
<script>
$(document).ready(function(){
$("#inputtext").keypress(function(event){
var inputValue = event.which;
// allow letters and whitespaces only.
if(!(inputValue >= 65 && inputValue <= 123) && (inputValue != 32 && inputValue != 0)) {
event.preventDefault();
}
});
$("#lastname").keypress(function(event){
var inputValue = event.which;
// allow letters and whitespaces only.
if(!(inputValue >= 65 && inputValue <= 123) && (inputValue != 32 && inputValue != 0)) {
event.preventDefault();
}
});
$("#middlename").keypress(function(event){
var inputValue = event.which;
// allow letters and whitespaces only.
if(!(inputValue >= 65 && inputValue <= 123) && (inputValue != 32 && inputValue != 0)) {
event.preventDefault();
}
});
$("#age").keypress(function(event){
var inputValue = event.which;
// allow letters and whitespaces only.
if( (inputValue >=65 && inputValue <=123 ) && (inputValue >=32 && inputValue <=47 )) {
event.preventDefault();
}
else if((inputValue >=32 && inputValue <=47 ))
{
event.preventDefault();
}
else if((inputValue >=91 && inputValue <=96 ))
{
event.preventDefault();
}
else if((inputValue >=123 && inputValue <=127 ))
{
event.preventDefault();
}
else if(inputValue < 1 && inputValue >100)
{
alert("the age must be a number between 1 and 100");
return false;
}
else if(inputValue >=92 && inputValue <=123 )
{
event.preventDefault();
}
});
$("#txtct").keydown(function (e) {
// Allow: backspace, delete, tab, escape, enter and .
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
// Allow: Ctrl+A, Command+A
(e.keyCode === 65 && (e.ctrlKey === true || e.metaKey === true)) ||
// Allow: home, end, left, right, down, up
(e.keyCode >= 35 && e.keyCode <= 40)) {
// let it happen, don't do anything
return;
}
// Ensure that it is a number and stop the keypress
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
});
});
</script>
Just set div id and add masg in this code like
var masg='only number';
$('#divid').html(masg);

Echo not displaying my result/answer

I'am using php 7.0, apache2, mysql ver 14.14 distribution 5.6.17, and phpmyadmin 5.7
My php file for some reason will not display the value for variable $result. Whenever I try to use "echo" it wont display it. Not even another variable (sum).
My html file has following code:
<!doctype html>
<html lang="en-us">
<head>
<title>calculation form</title>
<meta charset="utf-8">
</head>
<body>
<form method="post" action="calculate.php">
<p>Value 1: <input type="text" name="val1" size="10"></p>
<p>Value 2: <input type="text" name="val2" size="10"></p>
<p>Calculation:<br>
<input type="radio" name="calc" value="add"> add<br>
<input type="radio" name="calc" value="subtract"> subtract<br>
<input type="radio" name="calc" value="multiply"> multiply<br>
<input type="radio" name="calc" value="divide"> divide
</p>
<p><input type="submit" name="submit" value="Calculate"></p>
</form>
</body>
</html>
My php code has the following:
<?php
$sum = 0;
if(($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] == ""))
{
header("Location: calculate_form.html");
exit;
}
if($_POST[calc] == "add")
{
$result = $_POST[val1] + $_POST[val2];
}
if($_POST[calc] == "subtract")
{
$result = $_POST[val1] - $_POST[val2];
}
if($_POST[calc] == "multiply")
{
$result = $_POST[val1] - $_POST[val2];
}
if ($_POST[calc] == "divide") {
$result = $_POST[val1] / $_POST[val2];
}
?>
<?php
echo $result;
echo $sum;
?>
you have to echo inside if condition or you have to set variable globally
<?php
$sum = 0;
if(($_POST['val1'] == "") || ($_POST['val2'] == "") || ($_POST['calc'] == ""))
{
header("Location: calculate_form.html");
exit;
}
if($_POST['calc'] == "add")
{
$result = $_POST['val1'] + $_POST['val2'];
echo $result;
}
if($_POST['calc'] == "subtract")
{
$result = $_POST['val1'] - $_POST['val2'];
echo $result;
}
if($_POST['calc'] == "multiply")
{
$result = $_POST['val1'] - $_POST['val2'];
echo $result;
}
if ($_POST['calc'] == "divide") {
$result = $_POST['val1'] / $_POST['val2'];
echo $result;
}
?>
or else set like this
if($_POST[calc] == "add")
{
$result = $_POST[val1] + $_POST[val2];
$sum= $result;
}
also yuo have error in $_POST[val1]
it should be $_POST['val1']
Updated with example
<?php
$sum = 0;
$_POST['val1']=5;
$_POST['val2']=10;
$_POST['calc']='add';
if(($_POST['val1'] == "") || ($_POST['val2'] == "") || ($_POST['calc'] == ""))
{
header("Location: calculate_form.html");
exit;
}
if($_POST['calc'] == "add")
{
$sum = $_POST['val1'] + $_POST['val2'];
}
if($_POST['calc'] == "subtract")
{
$sum = $_POST['val1'] - $_POST['val2'];
}
if($_POST['calc'] == "multiply")
{
$sum = $_POST['val1'] - $_POST['val2'];
}
if ($_POST['calc'] == "divide") {
$sum = $_POST['val1'] / $_POST['val2'];
}
echo $sum;
?>

Seats booking system

So, i made a seat booking system where there are checkboxes in every seat and the user select this boxes and the seats are considered reserved.
But now i want make the user be able to give each marked seat a name. How can i do that?
seats.php
<?php include("login.php"); ?>
<html>
<head>
<title>Tickets</title>
<style>
* {
font-size: 11px;
font-family: arial;
}
</style>
<script>
function reserveSeats() {
var selectedList = getSelectedList('Reserve Seats');
if (selectedList) {
if (confirm('Do you want to reserve
selected seat/s '
+ selectedList + '?')) {
document.forms[0].oldStatusCode.value=0;
document.forms[0].newStatusCode.value=1;
document.forms[0].action='bookseats.php';
document.forms[0].submit();
} else {
clearSelection();
}
}
}
function cancelSeats() {
var selectedList = getSelectedList('Cancel Reservation');
if (selectedList) {
if (confirm('Do you want to cancel reserved seat/s ' + selectedList + '?')) {
document.forms[0].oldStatusCode.value=1;
document.forms[0].newStatusCode.value=0;
document.forms[0].action='bookseats.php';
document.forms[0].submit();
} else {
clearSelection();
}
}
}
function confirmSeats() {
var selectedList = getSelectedList('Confirm Reservation');
if (selectedList) {
if (confirm('Do you want to confirm reserved seat/s ' + selectedList + '?')) {
document.forms[0].oldStatusCode.value=1;
document.forms[0].newStatusCode.value=2;
document.forms[0].action='bookseats.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 before clicking ' + actionSelected);
return false;
} else {
return selectedList;
}
}
function clearSelection() {
var obj = document.forms[0].elements;
for (var i = 0; i < obj.length; i++) {
if (obj[i].checked) {
obj[i].checked = false;
}
}
}
function refreshView() {
clearSelection();
document.forms[0].action='<?php echo $_SERVER['PHP_SELF']; ?>';
document.forms[0].submit();
}
</script>
</head>
<body>
<table>
<tr><td width="100%" align="center">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="oldStatusCode" value=""/>
<input type="hidden" name="newStatusCode" value=""/>
<table width='100%' border='0'>
<tr><td align='center'>
<input type='button' value='Refresh View' onclick='refreshView();'/>
</td></tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<table width='100%' border='0'>
<tr><td align='center'>
<input type='button' value='Reserve Seats' onclick='reserveSeats()'/>
<input type='button' value='Confirm Reservation' onclick='confirmSeats()'/>
<input type='button' value='Cancel Reservation' onclick='cancelSeats()'/>
</td></tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<table width='100%' border='0'>
<tr><td align='center'>
<input type='button' value='Clear Selection' onclick='clearSelection()'/></td>
</tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<?php
/*
* Created on Mar 17, 2007
* Author: dayg
*/
$linkID = # mysql_connect("localhost", "tickets", "tickets") or die("Could not connect to MySQL server");
# mysql_select_db("tickets") or die("Could not select database");
/* Create and execute query. */
$query = "SELECT * from seats order by rowId, columnId desc";
$result = mysql_query($query);
$prevRowId = null;
$seatColor = null;
$tableRow = false;
//echo $result;
echo "<table width='100%' border='0' cellpadding='3' cellspacing='3'>";
while (list($rowId, $columnId, $status, $updatedby) = mysql_fetch_row($result))
{
if ($prevRowId != $rowId) {
if ($rowId != 'A') {
echo "</tr></table></td>";
echo "\n</tr>";
}
$prevRowId = $rowId;
echo "\n<tr><td align='center'><table border='1' cellpadding='8' cellspacing='8'><tr>";
} else {
$tableRow = false;
}
if ($status == 0) {
$seatColor = "lightgreen";
} else if ($status == 1 && $updatedby == 'user1') {
$seatColor = "FFCC99";
} else if ($status == 1 && $updatedby == 'user2') {
$seatColor = "FFCCFF";
} else if ($status == 2 && $updatedby == 'user1') {
$seatColor = "FF9999";
} else if ($status == 2 && $updatedby == 'user2') {
$seatColor = "CC66FF";
} else {
$seatColor = "red";
}
echo "\n<td bgcolor='$seatColor' align='center'>";
echo "$rowId$columnId";
if ($status == 0 || ($status == 1 && $updatedby == $_SERVER['PHP_AUTH_USER'])) {
echo "<input type='checkbox' name='seats[]' value='$rowId$columnId'></checkbox>";
}
echo "</td>";
if (($rowId == 'A' && $columnId == 7)
|| ($rowId == 'B' && $columnId == 9)
|| ($rowId == 'C' && $columnId == 9)
|| ($rowId == 'D' && $columnId == 10)
|| ($rowId == 'E' && $columnId == 8)
|| ($rowId == 'F' && $columnId == 5)
|| ($rowId == 'G' && $columnId == 13)
|| ($rowId == 'H' && $columnId == 14)
|| ($rowId == 'I' && $columnId == 14)
|| ($rowId == 'J' && $columnId == 12)
|| ($rowId == 'K' && $columnId == 14)
|| ($rowId == 'L' && $columnId == 13)
|| ($rowId == 'M' && $columnId == 9)) {
// This fragment is for adding a blank cell which represent the "center aisle"
echo "<td> </td>";
}
}
echo "</tr></table></td>";
echo "</tr>";
echo "</table>";
/* Close connection to database server. */
mysql_close();
?>
</td></tr>
<tr><td> </td></tr>
<tr><td width="100%" align="center">
<table border="1" cellspacing="8" cellpadding="8">
<tr>
<td bgcolor='lightgreen'>Available</td>
<td bgcolor='FFCC99'>Reserved user1</td>
<td bgcolor='FF9999'>Confirmed user1</td>
<td bgcolor='FFCCFF'>Reserved user2</td>
<td bgcolor='CC66FF'>Confirmed user2</td>
</tr>
</table>
</td></tr>
<tr><td> </td></tr>
<tr><td width="100%" align="center">
View Layout
</td></tr>
</table>
</form>
</body>
</html>
bookseats.php
<html>
<head>
<title>Book Seats</title>
<style>
* {
font-size: 14px;
font-family: arial;
}
</style>
</head>
<body>
<?php include("login.php"); ?>
<center>
<br/>
<br/>
<br/>
<?php
if (isset($_POST['seats']))
{
$user = $_SERVER['PHP_AUTH_USER'];
$newStatusCode = $_POST['newStatusCode'];
$oldStatusCode = $_POST['oldStatusCode'];
// open database connection
$linkID = # mysql_connect("localhost", "tickets", "tickets") or die("Could not connect to MySQL server");
# mysql_select_db("tickets") or die("Could not select database");
// prepare select statement
$selectQuery = "SELECT rowId, columnId from seats where (";
$count = 0;
foreach($_POST['seats'] AS $seat) {
if ($count > 0) {
$selectQuery .= " || ";
}
$selectQuery .= " ( rowId = '" . substr($seat, 0, 1) . "'";
$selectQuery .= " and columnId = " . substr($seat, 1) . " ) ";
$count++;
}
$selectQuery .= " ) and status = $oldStatusCode";
if ($oldStatusCode == 1) {
$selectQuery .= " and updatedby = '$user'";
}
//echo $selectQuery;
// execute select statement
$result = mysql_query($selectQuery);
//echo $result;
$selectedSeats = mysql_num_rows($result);
//echo "<br/>" . $selectedSeats;
if ($selectedSeats != $count) {
$problem = "<h3>There was a problem executing your request. No seat/s were updated.</h3>";
$problem .= "Possible problems are:";
$problem .= "<ul>";
$problem .= "<li>Another process was able to book the same seat while you were still browsing.</li>";
$problem .= "<li>You were trying to Confirm an unreserved Seat.</li>";
$problem .= "<li>You were trying to Cancel an unreserved Seat.</li>";
$problem .= "<li>You were trying to Reserve a reserved Seat.</li>";
$problem .= "<li>There was a problem connecting to the database.</li>";
$problem .= "</ul>";
$problem .= "<a href='seats.php'>View Seat Plan</a>";
die ($problem);
}
// prepare update statement
$newStatusCode = $_POST['newStatusCode'];
$oldStatusCode = $_POST['oldStatusCode'];
$updateQuery = "UPDATE seats set status=$newStatusCode, updatedby='$user' where ( ";
$count = 0;
foreach($_POST['seats'] AS $seat) {
if ($count > 0) {
$updateQuery .= " || ";
}
$updateQuery .= " ( rowId = '" . substr($seat, 0, 1) . "'";
$updateQuery .= " and columnId = " . substr($seat, 1) . " ) ";
$count++;
}
$updateQuery .= " ) and status = $oldStatusCode";
if ($oldStatusCode == 1) {
$updateQuery .= " and updatedby = '$user'";
}
// perform update
$result = mysql_query($updateQuery);
$updatedSeats = mysql_affected_rows();
if ($result && $updatedSeats == $count) {
//$mysql->commit();
echo "<h3>";
echo "You have successfully updated $updatedSeats seat/s: ";
echo "[";
foreach($_POST['seats'] AS $seat) {
$rowId = substr($seat, 0, 1);
$columnId = substr($seat, 1);
echo $rowId . $columnId . ", ";
}
echo "]";
echo "...</h3>";
} else {
//$mysql->rollback();
echo "<h3>There was a problem executing your request. No seat/s were updated.</h3>";
echo "Possible problems are:";
echo "<ul>";
echo "<li>Another process was able to book the same seat while you were still browsing.</li>";
echo "<li>You were trying to Confirm an unreserved Seat.</li>";
echo "<li>You were trying to Cancel an unreserved Seat.</li>";
echo "<li>You were trying to Reserve a reserved Seat.</li>";
echo "<li>There was a problem connecting to the database.</li>";
echo "</ul>";
}
echo "<a href='seats.php'>View Seat Plan</a>";
// Enable the autocommit feature
//$mysqldb->autocommit(TRUE);
// Recuperate the query resources
//$result->free();
mysql_close();
}
?>
</center>
</body>
</html>
EDIT:
I tried the following:
When the user submit the checkboxes, this is included:
name.php
<?php
//$mysql->commit();
session_start();
$_SESSION['rowId'] = $_POST['rowId'];
$_SESSION['columnId'] = $_POST['columnId'];
echo "<h3>";
echo "Please enter the name for each seat:<br><p>&nbsp</p>";
echo "";
foreach($_POST['seats'] AS $seat) {
$rowId = substr($seat, 0, 1);
$columnId = substr($seat, 1);
echo $rowId . $columnId . '</br><form method="post" name="input" action="pt2.php" >
<input name="name" type="text"/></br>';
}
?>
<input type="submit" name="Submit" value="insert" />
</form>
pt2.php:
<?php
// Connect to MySQL
mysql_connect("localhost", "root", "root") or die("Connection Failed");
mysql_select_db("tickets")or die("Connection Failed");
$name = $_POST['name'];
session_start();
$rowId = $_SESSION['rowId'];
$columnId = $_SESSION['columnId'];
$result = mysql_query("UPDATE seats SET updatedby='".$name."' WHERE rowId='".$rowId."' AND columnId='".$columnId."'")
or die(mysql_error());
?>
If the user selects only one seat, this code works like a charm. But when there's two or more, the $columnId and the $rowId doesn't change as it should, and only the name of the last checked seat is changed.
i think you shouldn't use jquery for this part. try using php with an html form ( show an input next to the seat it has the checkbox ) then save the data into mysql seatid, seat_userId, seat_name etc... then just pull the data and do whatever you want with it.

PHP file not being called from javascript function

I am trying to call a form and php filefrom a javascript function but it does not work. It might have to do with the cookies, it does not call the "frmSubdeptChainDailyHL" form and it does not call the "subdeptclass_reportHL.php" file, here is the code:
function submitClassChainDaily()
{
var store = readCookie('storeAccess');
var clss = readCookie('classAccess');
var subdept = readCookie('subDeptAccess');
var period = readCookie('period');
if (period == null || period == '') {
period = 'CUR';
}
document.frmClassChainDaily.period.value = period;
var storePref = readCookie('storePref');
if (storePref == null || storePref == '') {
if (store == null || store == '') {
storePref = 'ALL';
} else {
storePref = store;
}
}
if ((storePref.length) > 3 && storePref != 'ALL100') {
document.setStore.submit();
} else {
document.frmClassChainDaily.store.value = storePref;
if (clss == null || clss == '') {
clss = 'ALL';
}
document.frmClassChainDaily.clss.value = clss;
if (subdept == null || subdept == '') {
subdept = 'ALL';
}
document.frmClassChainDaily.subdept.value = subdept;
";
if ($_REQUEST['storePref']=='099')
{
echo "document.frmSubdeptChainDailyHL.submit();";
} else {
echo "document.frmSubdeptChainDaily.submit();";
}
echo "
}
}
Here is the form code:
if ($_REQUEST['storeCode'] == '099') {
echo"
<li>
<!-- SubDept Daily Sales - Chain -->
<form name=\"frmSubdeptChainDailyHL\" action=\"subdeptclass_reportHL.php\">
<input type=hidden value=\"\" name=\"store\">
<input type=hidden value=\"\" name=\"subdept\">
<input type=hidden value=\"\" name=\"clss\">
<input type=hidden value=\"\" name=\"period\">
</form>
<a style=\"display: block; text-decoration: none; color: #000\" href=\"javascript: submitSubDeptChainDaily();\">
<h3 class=\"longfield\">
<img src=\"content/images/icons/US_dollar_icon.png\" alt=\"icon\" class=\"icon\"/>
<span>Sales</span>
</h3>
</a>
</li>
You cant directly call to a php function from javascript. Make use of some ajax calls

Categories