Compare the input user quantity value with the quantity value from database - javascript

i have a problem that i don't know how to compare the quantity of user input with the quantity in the database so that if the user put the quantity over the quantity in the database it will come one alert that notice the user that the product have out of stock on that quantity.Below is my code:
<?php
$con = mysql_connect('localhost', 'root', '') or die (mysql_error());
mysql_select_db('warda',$con) or die(mysql_error());
$page_title= 'View Your Shooping Cart';
if(isset($_POST['submit']))
{
foreach( $_POST['qty'] as $key => $value)
{
if (is_numeric ($value))
{
if(($value == 0) AND (is_numeric($value)))
{
unset($_SESSION['cart'][$key]);
}
elseif(is_numeric($value)AND($value>0))
{
$_SESSION['cart'][$key]=$value;
}
}
else
{
print '<script type="text/javascript">';
print 'alert("Please insert the a number")';
print '</script>';
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=viewcart.php">';
exit();
}
}
}
$empty = TRUE;
if(isset($_SESSION['cart']))
{
foreach($_SESSION['cart'] as $key=>$value)
{
if(isset($key))
{
$empty=FALSE;
}
}
}
//echo $empty.'nilai';`
if(!$empty)
{
$query ='SELECT * FROM product WHERE code IN (';//coding dalam database
foreach($_SESSION['cart'] as $key => $value)
{
$query.="'".$key."'".',';
}
$query = substr($query,0,-1).')';
$result = mysql_query($query) or die("error");
echo "<form action=\"viewcart.php\" method=\"POST\">";
echo'<table width="800" align="center" cellpadding=4 cellspacing=0 border=0 align="center" class="style25">
<tr>
<td align="center" width="30%"><b>Code</b></td>
<td align="center" width="30%"><b>Name</b></td>
<td align="center" width="10%"><b>Price</b></td>
<td align="center" width="10%"><b>Quantity</b></td>
<td align="center" width="10%"><b>Total</b></td>
</tr>';
echo'<form action="viewcart.php" method="post">';
$total = 0 ;
while($row_Recordset1 = mysql_fetch_array($result, MYSQL_ASSOC))
{
$subtotal = $_SESSION['cart'] [$row_Recordset1['code']]*$row_Recordset1['price'];
$price = $row_Recordset1['price'];
$total+=$subtotal;
echo"<tr>
<td align=\"center\" width=\"30%\">{$row_Recordset1['code']}</td>
<td align=\"center\" width=\"30%\"><input type=\"hidden\"size=\"3\" `name=\"name\" value= \"{$row_Recordset1['name']}\">{$row_Recordset1['name']} </td>`
<td align=\"center\" width=\"10%\">";
echo "RM " . number_format($price,2);
echo"</td>
<td align=\"center\" width=\"10%\"><input type=\"text\"size=\"3\" name=\"qty[{$row_Recordset1['code']}]\" value=\"{$_SESSION['cart'] [$row_Recordset1['code']]}\"</td>";
echo'<td align="center">RM'.number_format($subtotal,2).'</td>
</tr>';
}
echo'<tr>
<td colspan="4" align="right"><b>Total Price:<b></td>
<td align="right">RM'.number_format($total,2).'</td>
</tr>
</table>';
$_SESSION['total'] = $total;
echo " <div align=\"center\"></p>
<input type=\"submit\"class=\"style1\" name=\"submit\"
value=\"Update My Cart\" /> </div>
</form>
<div align=\"center\">
<form name=\"form1\" method=\"post\" action=\"carts.php\">
<input type=\"submit\" class=\"style1\" name=\"checkout\"
value=\"Checkout\"></p>";
`?>`
</form>
Continue Shopping
</div>
<?php
$today = date("d-m-Y");
mysql_close();
}
else
{
echo 'YOUR CART IS EMPTY';
}
?>

Related

how can I put ajax in pagination(plain JavaScript not in jQuery)?

I am new in JavaScript i don't know how to do ajax in pagination. is there anyone who can help me out on ajax in pagination. I write normal code of PHP and Ajax .
Thank you for your good support(:
i know that in ajax pagination is work on ClassName is active or not and replace the Inner HTML at the end but I don't know how can i do in my Code
this is my pagination.php file
<script type="text/javascript" src='../project/assets/js/ajax_pegination.js'></script>
<?php
include('../project/header.php');
include('../project/sidebar.php');
?>
<div class="body-contant">
<div class="main">
<table align="center">
<h2>Persnol information</h2>
<tr>
<div class="column">
<th>Id</th>
<th>firstName</th>
<th>lastName</th>
<th>email</th>
<th>mobileNo</th>
<th>gender</th>
<th>hobbies</th>
<th>Prewview</th>
<th>function</th>
</div>
</tr>
<?php
if (check_is_admin($_SESSION['id'])) {
$select = "SELECT * FROM form";
}
else{
$select = "SELECT * FROM form WHERE ID=".$_SESSION['id'];
}
$result= mysqli_query($conn, $select);
$total_rows= mysqli_num_rows($result);
$limit= 3;
$totalPages= ceil ($total_rows/$limit);
if (!isset ($_GET['page']) ) {
$pageNumber= 1;
} else {
$pageNumber= $_GET['page'];
}
$offset= ($pageNumber-1) * $limit;
if (check_is_admin($_SESSION['id'])) {
$select= "SELECT *FROM form LIMIT " . $offset . ',' . $limit;
}
$result= mysqli_query($conn, $select);
while($data = mysqli_fetch_assoc($result)) {
$extract=explode(',',$data['hobbies']);
$hobbies=[];
?>
<tr>
<td><?php echo $data['ID']; ?> </td>
<td><?php echo $data['first_name']; ?> </td>
<td><?php echo $data['last_name']; ?> </td>
<td><?php echo $data['email']; ?> </td>
<td><?php echo $data['mobile_no']; ?> </td>
<td><?php echo $data['gender']; ?> </td>
<?php
foreach($extract as $hobbiesId){
$select1 = "SELECT * from hobbies WHERE `ID` IN ($hobbiesId)";
$result1=mysqli_query($conn,$select1);
while($data1=mysqli_fetch_assoc($result1)){
$hobbies[] = $data1['name'];
}
}
?>
<td><?php echo implode(",", $hobbies); ?> </td>
<td><img src="..\project\assets\uploads\<?php echo $data['file_path'] ?>" id="preview" alt="img"></td>
<div class="btn">
<td>
<a class="button1" type="button" name="edit" href="..\project\edit_user.php?id=<?php echo $data['ID']; ?>">Edit</a>
<a class="button2" type="button" name="delete" href="../project/delete_user.php?id=<?php echo $data['ID']; ?>" onclick="return confirm('are you sure you want to delete??');">Delete</a>
</td>
</div>
</tr>
<?php
}
?>
</table>
<!-- --------------------------------------------------------- -->
<div class="pagination">
<?php
if (check_is_admin($_SESSION['id'])) {
$pageURL = "";
if($pageNumber>=2){
echo "<a class='prev' href='pagination.php?page=".($pageNumber-1)."' onchange='load()'> Prev </a>";
}
for ($i=1; $i<=$totalPages; $i++) {
if ($i == $pageNumber) {
$pageURL .= "<a class = 'active' href='pagination.php?page=" .$i."'>".$i." </a>";
}
else {
$pageURL .= "<a href='pagination.php?page=".$i."'>".$i." </a>";
}
};
echo $pageURL;
if($pageNumber<$totalPages){
echo "<a class='next' href='pagination.php?page=".($pageNumber+1)."'> Next </a>";
}
}
?>
</div>
<!-- ------------------------------------------------------- -->
</div>
</div>
<?php
include('../project/footer.php');
?>
and this my AJAX_pagination.js file
// document.getElementsByClassName("prev").addEventListener("change", (event) => {
// event.preventDefault();
// load();
// });
function load(){
var httpx = new XMLHttpRequest();
httpx.onreadystatechange = function(){
if(this.readyState==4 && this.status==200){
console.log(this);
document.getElementsByClassName("prev").innerHTML=this.responseText;
}
}
httpx.open("POST", "http://localhost/project/pagination.php", true);
httpx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpx.send();
}

PHP & MySQL & JS editable table won't update records

So I'm trying to use a table to update some records in my database but each time I click on update it won't work and it won't do anything. A part of the code below was found in an another topic but it was incomplete so I added some other things.
Js script
$(function(){
$("#loading").hide();
var message_status = $("#status");
$("td[contenteditable=true]").blur(function(){
var field_userid = $(this).attr("id") ;
var value = $(this).text() ;
$.post('update.php' , field_userid + "=" + value, function(data){
if(data != '')
{
message_status.show();
message_status.text(data);
//hide the message
setTimeout(function(){message_status.hide()},1000);
}
});
});
});
This is the table fetching the rows from the database, however everything works besides updating.
HTML & PHP
<form method="post" action="update.php">
<div class="col-sm-12">
<div class="table-responsive">
<table class="table table-striped table-dark">
<tr bgcolor="#df4662" style="color:#FFFFFF;">
<td>ID</td>
<td>Nickname</td>
<td>Name</td>
<td>Rank</td>
</tr>
<?php
while($row = mysqli_fetch_array($result)) {
?>
<tr>
<td contenteditable="true" id="id:<?php echo $row["id"]; ?>"><?php echo $row["id"]; ?></td>
<td contenteditable="true" id="username:<?php echo $row["username"]; ?>"><?php echo $row["username"]; ?></td>
<td contenteditable="true" id="name:<?php echo $row["steamid"]; ?>"><?php echo $row["steamid"]; ?></td>
<td contenteditable="true" id="ranks:<?php echo $row["ranks"]; ?>"><?php echo $row["ranks"]; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</form>
After a few errors I've been able to have a clean error_logs, but now I don't get any error even after pressing the update button.
update.php
<?php
include '../database.php'
?>
<?php
if(!empty($_POST))
{
foreach($_POST as $field_name => $val)
{
$field_id = strip_tags(trim($field_name));
$split_data = explode(':', $field_id);
$id = $split_data[1];
$field_name = $split_data[0];
if(!empty($id) && !empty($field_name) && !empty($val))
{
$affected_rows = mysqli_query($mysqli,"UPDATE users SET $field_name = '$val' WHERE id = $id");
echo $affected_rows;
echo "Updated";
} else {
echo "Invalid Request";
}
}
}
else {
echo "Invalid Requests";
}
?>
EDIT: Thanking Sam now the problem is just that the record won't update at all

Call API only for Selected items

I am calling Api : $url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order=' . $orderrecords[$k]["order_id"] . '&username=admin&password=admin123'; and fetching Status results of all Order IDS & displaying in php page when we refresh php page.
Now i want to select Order IDs through checkbox, than when i click on button "Show Status" , than only i want to Call Api & update the Selected Order IDs status in web page.
<p><button type= "button" class="call">Show Status</button></p>
<table class="tbl-qa" border="1">
<thead>
<tr>
<th class="table-header"></th>
<th class="table-header">ORDERID</th>
<th class="table-header">Status</th>
</tr>
</thead>
<tbody id="table-body">
<?php
$tabindex = 1;
if (!empty($orderrecords))
{
foreach($orderrecords as $k => $v)
{ ?>
<?php
$hide = '';
$data['username'] = 'admin';
$data['password'] = 'admin123';
$url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order=' . $orderrecords[$k]["order_id"] . '&username=admin&password=admin123';
$ch = curl_init();
// some curl code
$res = explode("\n", $output);
if (!isset($res[13]))
{
$res[13] = null;
}
$status = $res[13];
?>
<tr class="table-row" id="table-row-<?php echo $orderrecords[$k]["id"]; ?>" tabindex="<?php echo $tabindex; ?>">
<td><input onclick="assignorderids('<?php echo $orderrecords[$k]["order_id"]; ?>')" type="checkbox" name="assigneeid" id="assigneeid-<?php echo $orderrecords[$k]["order_id"]; ?>" value="<?php echo $orderrecords[$k]["order_id"]; ?>"></td>
<td><?php echo $orderrecords[$k]["order_id"]; ?></td>
<td><?php echo $status; ?></td>
</tr>
<?php
$tabindex++;
}
} ?>
</tbody>
</table>
Please help me how i can achieve this ?
Update : assignorderids function
function assignorderids(oid)
{
var checkstatus=$("#assigneeid-"+oid).is(":checked");
var morderId =document.getElementById("orderids").value;
if(checkstatus==false)
{
var arrayorder = JSON.parse("[" + morderId + "]");
document.getElementById("orderids").value='';
for (var i = 0; i < arrayorder.length; i++) {
var orderstatusValue=arrayorder[i];
if(orderstatusValue!=oid){
if (document.getElementById("orderids").value=='')
{
document.getElementById("orderids").value=orderstatusValue;
}
else
{
var newvalue=document.getElementById("orderids").value;
document.getElementById("orderids").value=newvalue+","+orderstatusValue;
}
}
}
}
else
{
if(morderId=='')
{
document.getElementById("orderids").value=oid;
}
else
{
document.getElementById("orderids").value=morderId+","+oid;
}
}
}
Url Output

Leave Plan plugin for orangehrm

I am using Orangehrm 3.2.1(latest build). Below is the php code I am using to display a leave plan calendar for the employees employed with me since its too costly to buy from Orangehrm. When I run this script, I get screen on my browser which shows a part of the code....
".$seeDate.""; ?>
Month: Year:
".$i."
"; } ?> "; $even = 1; while ($row = mysql_fetch_array( $result ) ) { $employee_id = $row['employee_id']; $employee_num = $row['emp_number']; $employee_firstname = $row['emp_firstname']; $employee_lastname = $row['emp_lastname']; echo ""; if ( $even % 2) echo " "; else echo " "; $even++; // echo "$even $numDays
"; for ($i = 1; $i <= $numDays; $i++) { $day = checkDay($employee_num, $i, $month, $year); // echo "$employee_num, $i, $month, $year $day
"; switch ($day) { case 'holiday': echo " "; break; case 'weekend': echo " "; break; case 'absence_full': echo " "; break; case 'absence_partial_m': echo " "; break; case 'absence_partial_a': echo " "; break; default: echo " "; break; }//switch }//for echo ""; }//while ?>
The code which is seen on the screen is a part of my php script. Is there any modification that i need to carry out? I have played a lot around with it but don't seem to get it correct. The code as compared to orangehrm version 2.5 has been changed and they have been marked with // in the script below.
<?php
/*****************/
/* Configuration */
/*****************/
//Database information
$db_host = "localhost";
$db_user = "root";
$db_pwd = "";
$db_name = "main";
$db_port = 3306;
$logoLink = "orangehrm/symfony/web/webres_513fd0981da216.38969927/themes/default/images/login/logo.png";
/******************************/
/* DONT EDIT BELLOW THIS LINE */
/******************************/
//Year
if (isset($_GET['year']))
$year = $_GET['year'];
else
$year = date("Y");
//Month
if (isset($_GET['month']))
$month = $_GET['month'];
else
$month = date("m");
$date_aux = $year . "-" . $month;
$seeDate = date("Y-m", strtotime($date_aux));
/* Number of days in a month/Year */
function monthDays($month, $year) {
return date("t", strtotime($year . "-" . $month . "-01"));
}//
//admin get Years
function getYears($year) {
global $db_host, $db_user, $db_pwd, $db_name, $db_port;
if(!isset($year))
$year = date("Y");
// $sql = "SELECT DISTINCT(EXTRACT(Year FROM leave_date)) FROM hs_hr_leave WHERE 1 ORDER BY leave_date;";
$sql = "SELECT DISTINCT(EXTRACT(Year FROM date)) FROM ohrm_leave WHERE 1 ORDER BY date;";
// Make a MySQL Connection
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
//Query
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result )) {
if ($row['(EXTRACT(Year FROM Date))'] == $year) {/*
echo "<option value=\"".$row['(EXTRACT(Year FROM leave_date))']."\" selected>".$row['(EXTRACT(Year FROM leave_date))']."</option><br>";*/
echo "<option value=\"".$row['(EXTRACT(Year FROM date))']."\" selected>".$row['(EXTRACT(Year FROM date))']."</option><br>";
} else {
// echo "<option value=\"".$row['(EXTRACT(Year FROM leave_date))']."\">".$row['(EXTRACT(Year FROM leave_date))']."</option><br>";
echo "<option value=\"".$row['(EXTRACT(Year FROM date))']."\">".$row['(EXTRACT(Year FROM date))']."</option><br>";
}
}
}//
function weekDay($date) {
$thisDay = date("D", strtotime($date));
return $thisDay;
}//
function checkDay($employee_id, $i, $month, $year) {
global $db_host, $db_user, $db_pwd, $db_name, $db_port;
$date = $year . "-" . $month . "-" . $i;
// $sql = "SELECT * FROM hs_hr_holidays WHERE date = '$date';";
$sql = "SELECT * FROM ohrm_holiday WHERE date = '$date';";
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result = mysql_query($sql)or die(msysql_error());
$result_count = mysql_num_rows($result);
if ($result_count > 0)
return "holiday";
if( ( weekDay($date) == "Sat") || ( weekDay($date) == "Sun") ) {
return "weekend";
}
//Get Absences
// $sql = "SELECT leaves.*
// FROM `hs_hr_leave` AS leaves
// WHERE (leaves.employee_id = '$employee_id') AND (leaves.leave_date = '$date') AND (leaves.leave_status > 1)
// ORDER BY leaves.leave_date ASC;";
$sql = "SELECT leaves.*
FROM `ohrm_leave` AS leaves
WHERE (leaves.emp_number = '$employee_id') AND (leaves.date = '$date') AND (leaves.status > 1)
ORDER BY leaves.date ASC;";
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result = mysql_query($sql)or die(mysql_error());
$result_count = mysql_num_rows($result);
if ( $result_count == 0 ) {
// echo "default<br>";
return "default";
} else {
while ($row = mysql_fetch_array( $result ) ) {
if ($row['leave_length_days'] < 1.0 ) {
if ( ($row['start_time'] >= "08:00:00") && ($row['start_time'] <= "09:00:00") )
return "absence_partial_m";
else if ( ($row['start_time'] >= "13:00:00") && ($row['start_time'] <= "18:00:00") )
return "absence_partial_a";
} else
// echo "full abs<br>";
return "absence_full";
}//
}
}
$numDays = monthDays($month, $year);
?>
<HTML>
<HEAD><TITLE>Vacation Plan</TITLE>
<script type="text/javascript">
function sort(form) {
var Page = "?";
var month = form.listMonth.selectedIndex+1;
var iyear = form.listYear.selectedIndex;
var year = form.listYear.options[iyear].value;
var URL = Page + "month=" + month + "&year=" + year;
window.location = URL;
return false;
}
</script>
<style type="text/css">
<!--
.style2 {font-size: 12px; }
td{ border:solid 1px red;}
-->
</style>
</HEAD>
<BODY>
<?
?>
<?php if (!empty($logoLink))
echo "<img src='$logoLink'/>";
?>
<center>
<div id="sort" style="padding-right: 10%">
<form id="frmSort" name="frmSort" onsubmit="return sort(this); return false;">
<?
$seeDate = date("F Y", strtotime($seeDate));
echo "<h2>".$seeDate."</h2>";
?>
<div align="right">
<strong>Month</strong>:
<?php
$curr_month = $month;
$auxmonth = array (1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$select = "<select name=\"listMonth\">\n";
foreach ($auxmonth as $key => $val) {
$select .= "\t<option val=\"".$key."\"";
if ($key == $curr_month) {
$select .= " selected>".$val."\n";
} else {
$select .= ">".$val."\n";
}
}
echo $select;
?>
</select>
<img src="img/pixel.gif" width="1" height="1" /><img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" /><img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" /><strong>Year</strong>:
<select name="listYear" id="listYear">
<?php getYears($year); ?>
</select>
<img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" />
<input type="submit" name="Submit" value="Select" />
</form>
</div>
<div id="table">
<table width="90%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td > </td>
<?
for($i = 1; $i <= $numDays; $i++) {
echo "<td bgcolor=\"#FFFFFF\" width=\"15\"><div align=\"center\"><strong>".$i."</strong></div></td>";
}
?>
</tr>
<?
global $db_host, $db_user, $db_pwd, $db_name, $db_port;
// $sql = "SELECT emp.*
// FROM hs_hr_employee AS emp
// INNER JOIN hs_hr_users AS users ON emp.emp_number = users.emp_number
// WHERE (users.status = 'Enabled')
// ORDER BY emp.emp_firstname ASC";
$sql = "SELECT emp.*
FROM hs_hr_employee AS emp
INNER JOIN ohrm_user AS users ON emp.emp_number = users.emp_number
WHERE (users.status = 1)
ORDER BY emp.emp_firstname ASC";
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result = mysql_query($sql)or die(mysql_error());
$result_count = mysql_num_rows($result);
// echo "toto:$result_count<br>";
$even = 1;
while ($row = mysql_fetch_array( $result ) ) {
$employee_id = $row['employee_id'];
$employee_num = $row['emp_number'];
$employee_firstname = $row['emp_firstname'];
$employee_lastname = $row['emp_lastname'];
echo "<tr>";
if ( $even % 2)
echo " <td bgcolor=\"#FFFFFF\" width=\"10%\"><div align=\"right\">".$employee_firstname . " " . $employee_lastname . "</div></td>";
else
echo " <td bgcolor=\"#FFFFFF\" width=\"10%\"><div align=\"right\">".$employee_firstname . " " . $employee_lastname . "</div></td>";
$even++;
// echo "$even $numDays<br>";
for ($i = 1; $i <= $numDays; $i++) {
$day = checkDay($employee_num, $i, $month, $year);
// echo "$employee_num, $i, $month, $year $day<br>";
switch ($day) {
case 'holiday':
echo " <td bgcolor=\"#0000FF\"></td>";
break;
case 'weekend':
echo " <td bgcolor=\"#999999\"></td>";
break;
case 'absence_full':
echo " <td bgcolor=\"#FF0000\"></td>";
break;
case 'absence_partial_m':
echo " <td bgcolor=\"#FFFF00\"><center>M</center></td>";
break;
case 'absence_partial_a':
echo " <td bgcolor=\"#FFFF00\"><center>A</center></td>";
break;
default:
echo " <td bgcolor=\"##00FF00\"></td>";
break;
}//switch
}//for
echo "</tr>";
}//while
?>
</table>
</div>
</center>
<br/>
<div style="padding-left: 5%">
<table width="25%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td bgcolor="#00FF00"> </td>
<td><div align="left" class="style2">Available</div></td>
</tr>
<tr>
<td width="11%" bgcolor="#FF0000"> </td>
<td width="89%"><div align="left" class="style2">Absence</div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"> </td>
<td><div align="left" class="style2">WeekEnd</div></td>
</tr>
<tr>
<td bgcolor="#0000FF"> </td>
<td><div align="left" class="style2">Public Holiday </div></td>
</tr>
<tr>
<td bgcolor="#FFFF00"><div align="center">M</div></td>
<td><div align="left" class="style2">Partial Absence (Morning) </div></td>
</tr>
<tr>
<td bgcolor="#FFFF00"><div align="center">A</div></td>
<td><span class="style2"> Partial Absence (Afternoon) </span></td>
</tr>
</table>
</div>
<br/>
<div align="center"> </div>
</BODY>
</HTML>
Thanks for sharing the code.
I seem to have got it working with 3.3! :)
I don't get the error you get.
Try adding debug code at the beginning: after
ini_set('display_errors', 'On');
I found that full day absence wasn't showing so I edited the code by removing
the comment at line 137:
} else
// echo "full abs";
return "absence_full";
not sure why I had to leave in semicolon though - thus:
} else
;
return "absence_full";
you need to turn short_tags on in PHP ini if you are going to use <? ?>

Updating inline doesn't work with symbols such as +

I've got the following table on a webpage:
<table class="table table-striped table-condensed">
<thead>
<tr>
<center><th>Name</th><th>Rank</th><th>MOS</th><th>Tag</th><th>MOSTs</th><th>Prom. Date</th><th>DI</th><th>CMO</th><th>MCRC</th><th>Medals</th><th>Leave</th></center>
</tr>
</thead>
<tbody>
<?php
$rank = 'O-10';
$result->execute();
while($row = $result->fetch()) {
?>
<tr>
<td id="habbo_name:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['habbo_name']);?></td>
<td id="rank:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['rank']);?></td>
<td id="rating:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['rating']);?></td>
<td id="tag:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['tag']);?></td>
<td id="asts:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['asts']);?></td>
<td id="promotion_date:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['promotion_date']);?></td>
<td id="rdc_grade:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['rdc_grade']);?></td>
<td id="cnl_trainings:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['cnl_trainings']);?></td>
<td id="mcrc:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['mcrc']);?></td>
<td id="medals:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['medals']);?></td>
<td id="leave:<?php echo htmlspecialchars($row['user_id']); ?>" contenteditable="true"><?php echo htmlspecialchars($row['leave']);?></td>
</tr>
<?php
}
?>
</tbody>
</table>
I have this code which sends a request to ajax.php whenever a td is clicked:
<script type="text/javascript">
$(function(){
$("td[contenteditable=true]").blur(function(){
var field_userid = $(this).attr("id") ;
var value = '$(this).text()' ;
$.post('ajax.php' , field_userid + "=" + value, function(data){
});
});
});
</script>
ajax.php:
<?php
include 'functions/user.php';
if(!empty($_POST))
{
foreach($_POST as $field_name => $val)
{
$field_userid = strip_tags(trim($field_name));
$split_data = explode(':', $field_userid);
$user_id = $split_data[1];
$field_name = $split_data[0];
if(!empty($user_id) && !empty($field_name))
{
$query = "UPDATE `personnel` SET $field_name = '$val' WHERE user_id = $user_id";
$result = $con->prepare($query);
$result->execute();
} else {
echo "Invalid Requests";
}
}
} else {
echo "Invalid Requests";
}
?>
The problem I have is with 3 of the fields - MCRC, Medals and Leave - the others all update fine.
The MCRC field will either be empty or contain the + symbol. Using firebug, this is the POST request when trying to send a +:
As you can see, the + is removed in the parameters. The same goes for medals.
Leave seems to have a different issue. The parameters are fine but the database is not updated with the [TEST]
If anyone could explain a way for me to send symbols/see what's going wrong with leave that would be great. Thanks.
Got it working by changing
var value = $(this).text();
to
var value = encodeURIComponent($(this).text());

Categories

Resources