How to convert from string to array with angularjs? - php

I'm trying to delete a row from my database table using php and angular. I'm using "Splice" but my data is a string and I need to convert to an array. can someone please help?
This is my code:
controller:
$scope.delete = function(deletingId, $index) {
var params = $.param({"customer_id":deletingId});
$http({
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
url: 'http://localhost:8081/hamatkin/api/delete-customer.php/',
method: "GET",
data: params
}).success(function(data){
console.log(data);
var arr=JSON.parse(JSON.stringify(data))
$scope.customerDetails = arr;
$scope.customerDetails.splice($index, 1);
The error I'm getting :
angular.js:13550 TypeError: $scope.customerDetails.splice is not a function
delete-customer.php
<?php header('Content-Type: text/html; charset=utf-8');
$connect=mysqli_connect("localhost", "root", "", "hamatkin");
include_once 'Customer.php';
mysqli_query($connect,"SET character_set_client = utf8");
mysqli_query($connect,"SET character_set_connection = utf8");
mysqli_query($connect,"SET character_set_results = utf8");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$customer = new Customer();
if(isset($_GET['customer_id'])){
$customer_id = $_GET['customer_id'];
$del = "DELETE FROM posts WHERE customer_id='".$customer_id."'";
mysql_query($connect, $del);
}
$newURL = "/hamatkin/#/customerCards";
header('Location: '.$newURL);
?>
html
<tbody>
<tr ng-repeat="x in customers | filter:search_query | orderBy: order_query:reverse_query">
<!-- <td>{{$index + 1}}</td> -->
<td>{{ x.customer_id}}</td>
<td>{{ x.kind_Of_Customer}}</td>
<td>{{ x.full_name}}</td>
<td>הצג פרטי לקוח </td>
<td><a ng-click="delete(x.customer_id, $index)" class="btn btn-primary btn- active">מחיקה</td>
</tr>
</tbody>
console.log(data)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Styles -->
<link rel="stylesheet" href="lib\bootstrap.css" />
<link rel="stylesheet" href="styles/layout.css" />
<!-- Liberaries -->
<script src="scripts/angular.min.js"></script>
<script src="lib/jquery-1.12.0.min.js"></script>
<!-- <script src="lib/angular.js"></script> -->
<script src="lib/angular-route.js"></script>
<script src="scripts/angular-ui/ui-bootstrap-tpls.min.js"></script>
<!-- <script src="scripts/angular-route.min.js"></script> -->
<script src="lib/bootstrap.js"></script>
<link href="scripts\bootstrap.min.js" />
<!-- Application Model, Direectives, Services & Controllers -->
<script src="scripts/App.js"></script>
<!-- <script src="scripts/angular.min.js"></script> -->
<!-- controllers-->
<script src="Controllers/loginCtrl.js"></script>
<script src="Controllers/customerFormCtrl.js"></script>
<script src="Controllers/customerCardsCtrl.js"></script>
<script src="Controllers/stockCtrl.js"></script>
<script src="Controllers/bodyCtrl.js"></script>
<script src="Controllers/ordersCtrl.js"></script>
<script src="Controllers/reportsCtrl.js"></script>
<script src="Controllers/recordExpensesCtrl.js"></script>
<script src="Controllers/supplierListCtrl.js"></script>
<script src="Controllers/supplierFormCtrl.js"></script>
<script src="Controllers/customerCardDetailsCtrl.js"></script>
<title>מערכת מידע רומן המתקין</title>
</head>
<body ng-app="dataSystem" ng-controller="bodyCtrl">
<!--Navigation Bar-->
<nav class="navbar navbar-inverse navbar-fixed-top" ng-hide="isNavTabsHidden()">
<div class="container-fluid">
<div class="navbar-header navbar-right">
<img class="img-rounded" src="images/black logo.jpg" style="width:155px" />
</div>
<ul class="nav navbar-nav navbar-right">
<li>דוחות</li>
<li>הכנסות והוצאות</li>
<li>ניהול מלאי וספקים</li>
<li>ניהול הזמנות</li>
<li>ניהול לקוחות</li>
</ul>
<ul class="nav navbar-nav navbar-left">
<li><span class="glyphicon glyphicon-log-out"></span> התנתק</li>
<li><span class="glyphicon glyphicon-wrench"></span> ניהול הרשאות</li>
</ul>
</div>
</nav>
<br /><br /><br />
<!--טאב ניהול לקוחות-->
<div class="containers-wrapper">
<div class="container" ng-hide="costumerHidden()">
<div class="list-group">
טופס רישום לקוח
כרטיסי לקוחות
רשימת פניות מלקוחות
</div>
</div>
<!--טאב ניהול מלאי וספקים-->
<div class="container" ng-hide="stockHidden()">
<div class="list-group">
טופס רישום מלאי
טופס עריכת/מחיקת מלאי
רשימת מלאים למכירה
רשימת ציוד עבודה
בדיקת זמינות מלאי
טופס רישום ספק
רשימת ספקים
</div>
</div>
<!--טאב ניהול הזמנות-->
<div class="container" ng-hide="ordersHidden()">
<div class="list-group">
טופס הזמנה חדשה
רשימת הזמנות
טופס הצעת מחיר
הצעות מחיר בהמתנה
</div>
</div>
<!--טאב דוחות-->
<div class="container" ng-hide="reportsHidden()">
<div class="list-group">
דו"ח מלאים לפי סוגים
דו"ח הצעות מחיר
דו"ח מכירות על פי סוגי מלאי
דו"ח הוצאות לספקים
דו"ח הוצאות לפי חודשים
דו"ח הכנסות לפי חודשים
דו"ח לקוחות חדשים חודשי
</div>
</div>
<!--טאב הכנסות והוצאות-->
<div class="container" ng-hide="isIncome_expensesHidden()">
<div class="list-group">
טופס תיעוד הוצאה
טופס תיעוד הכנסה
רשימת הוצאות
</div>
</div>
<!--left side screen-->
<div class="view-content left-side-screen">
<ng-view></ng-view>
</div>
</div>
<!--Footer-->
<div class="footer" ng-hide="isFooterHidden()">
<p>Copyright # 2016 Denis & Denis. All Rights Reserved</p>
</div>
</body>
</html>

Hi u have to first find the index which one u wants to splice then u have to splice , SPlice is for Array Items check whether the Item is array first for refrence https://plnkr.co/edit/Nzz4T4AmkLmcr7frxyH1?p=preview
JS
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.arrylist = [{
"id": 53,
"name": "abced"
}, {
"id": 53,
"name": "gayu"
}]
$scope.doc = {
"id": 53,
"name": "abced"
}
console.log($scope.arrylist)
var index = $scope.arrylist.findIndex(function(item) {
if (item.id == $scope.doc.id) {
return true;
}
});
if (index !== -1) {
//Removing the test from list;
$scope.arrylist.splice(index, 1);
}
console.log($scope.arrylist)
});

Using JSON.parse will turn JSON into JS object. In your scenario, you are invoking a splice function which exists on Array prototype, whereas your arr variable is in fact a plain string object which has no such function.
Assuming your string is formatted in some way, let's say - customer names are seperated by a comma, you can use split function. This will turn your string into an array of seperated elements devided by the required format.
Like this:
var clientsToDelete = arr.split(","); // comma splitting
clientsToDelete.splice($index, 1);

Related

Issu having to get a new transaction ID Keeps showing the first one

I am having an issue with getting a new transaction id when placing new order. It wants to keep only showing me the first order the user made. I have it so the user logs in and it keeps a session of the login. Then the user adds items to the cart and checkouts. After the data is inserted to the customer order table, the page moves on to a successful order page. The only issue is it keeps wanting to only show the first transaction id (tr_id) for that user in the db. When I sign in with new user I do get a different tr_id, but the same thing happens for the second user. Here is all the code I have for it. I know it may be hard question don't waste to much time on it if it cant be figured out. If I have to I will delete the question and try different method. This is the only thing holding up to complete my project. I also know that this is not the greatest code and can get sql injections. I am wondering what I am doing wrong with getting the new transaction id?
main.js
$('#checkout_btn').click(function(){
$.ajax({
url: 'action.php',
method: 'POST',
data: {payment_checkout:1},
success: function(){
window.location.href = "payment_success.php";
}
})
})
cart_checkout();
function cart_checkout()
{
$.ajax({
url: 'action.php',
method: 'POST',
data: {cart_checkout:1},
success: function(data){
$('#cartdetail').html(data);
}
})
}
$("#login").click(function(event){
event.preventDefault();
var email=$('#email').val();
var pwd=$('#password').val();
console.log(pwd);
$.ajax({
url: "login.php",
method: "POST",
data: {userLogin:1,email:email, pwd:pwd},
success: function(data){
if(data=="true"){
window.location.href="profile.php";
}
}
})
})
login.php
<?php
include('dbconnect.php');
session_start();
if(isset($_POST['userLogin'])){
$email=mysqli_real_escape_string($conn,$_POST['email']);
$pwd=md5($_POST['pwd']);
$sql="SELECT * FROM user_info WHERE email='$email' AND password='$pwd'";
$run_query=mysqli_query($conn,$sql);
$count=mysqli_num_rows($run_query);
if($count==1){
$row=mysqli_fetch_array($run_query);
$_SESSION['uid']=$row['user_id'];
$_SESSION['uname']=$row['first_name'];
echo "true";
}
}
?>
action.php
if(isset($_POST['cartmenu']) || isset($_POST['cart_checkout']))
{
$uid=$_SESSION['uid'];
$sql="SELECT * FROM cart WHERE user_id='$uid'";
$run_query=mysqli_query($conn,$sql);
$count=mysqli_num_rows($run_query);
if($count>0){
$i=1;
$total_amt=0;
while($row=mysqli_fetch_array($run_query))
{
$sl=$i++;
$pid=$row['p_id'];
$product_image=$row['product_image'];
$product_title=$row['product_title'];
$product_price=$row['price'];
$qty=$row['qty'];
$total=$row['total_amount'];
$price_array=array($total);
$total_sum=array_sum($price_array);
$total_amt+=$total_sum;
if(isset($_POST['cartmenu']))
{
echo "
<div class='row'>
<div class='col-md-3'>$sl</div>
<div class='col-md-3'><img src='assets/prod_images/$product_image' width='60px' height='60px'></div>
<div class='col-md-3'>$product_title</div>
<div class='col-md-3'>$$product_price</div>
</div>
";
}
else
{
echo "
<div class='row'>
<div class='col-md-2'><a href='#' remove_id='$pid' class='btn btn-danger remove'><span class='glyphicon glyphicon-trash'></span></a>
<a href='#' update_id='$pid' class='btn btn-success update'><span class='glyphicon glyphicon-ok-sign'></span></a>
</div>
<div class='col-md-2'><img src='assets/prod_images/$product_image' width='60px' height='60px'></div>
<div class='col-md-2'>$product_title</div>
<div class='col-md-2'><input class='form-control price' type='text' size='10px' pid='$pid' id='price-$pid' value='$product_price' disabled></div>
<div class='col-md-2'><input class='form-control qty' type='text' size='10px' pid='$pid' id='qty-$pid' value='$qty'></div>
<div class='col-md-2'><input class='total form-control price' type='text' size='10px' pid='$pid' id='amt-$pid' value='$total' disabled></div>
</div>
";
}
}
if(isset($_POST['cart_checkout'])){
echo "
<div class='row'>
<div class='col-md-8'></div>
<div class='col-md-4'>
<b>Total: $$total_amt</b>
</div>
</div>
";
}
}
}
if(isset($_POST['payment_checkout'])){
$uid=$_SESSION['uid'];
$sql="SELECT * FROM cart WHERE user_id='$uid'";
$run_query=mysqli_query($conn,$sql);
$i=rand();
while($cart_row=mysqli_fetch_array($run_query))
{
$cart_prod_id=$cart_row['p_id'];
$cart_prod_title=$cart_row['product_title'];
$cart_qty=$cart_row['qty'];
$cart_price_total=$cart_row['total_amount'];
$sql2="INSERT INTO customer_order (uid,pid,p_name, p_price,p_qty,p_status,tr_id) VALUES ('$uid','$cart_prod_id','$cart_prod_title','$cart_price_total','$cart_qty','CONFIRMED','$i')";
$run_query2=mysqli_query($conn,$sql2);
}
payment_success.php
<?php
include('dbconnect.php');
session_start();
if(!isset($_SESSION['uid'])){
header('Location:index.php');
}
$uid=$_SESSION['uid'];
$sql="SELECT * FROM customer_order WHERE uid='$uid'";
$run_query=mysqli_query($conn,$sql);
$row=mysqli_fetch_array($run_query);
$trid=$row['tr_id'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Supplies</title>
<link rel="stylesheet" type="text/css" href="assets/bootstrap-3.3.6-dist/css/bootstrap.css">
<style type="text/css">
.content{
display: none;
}
</style>
</head>
<body>
<div class='content'>
<div class="navbar navbar-default navbar-fixed-top" id="topnav">
<div class="container-fluid">
<div class="navbar-header">
Supplies
</div>
</div>
</div>
<br><br><br><br><br>
<div class='container-fluid'>
<div class='row'>
<div class='col-md-2'></div>
<div class='col-md-8'>
<div class="panel panel-default">
<div class="panel-heading"><h1>Thank you!</h1></div>
<div class="panel-body">
Hello <?php echo $_SESSION['uname']; ?>, your payment is successful.
<br>Your Transaction ID is <?php echo $trid; ?>
<br>You can continue with your shopping.
<p></p>
<a href="profile.php" class='btn btn-success btn-lg'>Back to store</a>
</div>
</div>
<div class='col-md-2'></div>
</div>
</div>
</div>
</div>
<!--Pre-loader -->
<div class="preload"><img src="assets/images/loading.gif" style="width:400px;
height: 400px;
position: relative;
top: 0px;
left: 469px;"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="assets/bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(".preload").fadeOut(5000, function(){
$(".content").fadeIn(500);
});
</script>
</body>
</html>
Your SQL select will fetch only the first tr-id (transaction id) because your select makes an array of unfetched tr-id's and fetches them in the order of their existence on the table.
you need to fetch the last element on the result. you could make it (there will be a better way) with a "for each" loop, it will write every result in the variable till the last one is saved on it.
there will most likely be a better way, but this should also work.
lg! ^^
Did not realize easy fix just need to add an order by id desc to grab last record entered.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Supplies</title>
<link rel="stylesheet" type="text/css" href="assets/bootstrap-3.3.6-dist/css/bootstrap.css">
<style type="text/css">
.content{
display: none;
}
</style>
</head>
<body>
<div class='content'>
<div class="navbar navbar-default navbar-fixed-top" id="topnav">
<div class="container-fluid">
<div class="navbar-header">
Supplies
</div>
</div>
</div>
<br><br><br><br><br>
<div class='container-fluid'>
<div class='row'>
<div class='col-md-2'></div>
<div class='col-md-8'>
<div class="panel panel-default">
<div class="panel-heading"><h1>Thank you!</h1></div>
<div class="panel-body">
Hello <?php echo $_SESSION['uname']; ?>, your payment is successful.
<br>Your Transaction ID is <?php echo $trid; ?>
<br>You can continue with your shopping.
<p></p>
<a href="profile.php" class='btn btn-success btn-lg'>Back to store</a>
</div>
</div>
<div class='col-md-2'></div>
</div>
</div>
</div>
</div>
<!--Pre-loader -->
<div class="preload"><img src="assets/images/loading.gif" style="width:400px;
height: 400px;
position: relative;
top: 0px;
left: 469px;"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="assets/bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(".preload").fadeOut(5000, function(){
$(".content").fadeIn(500);
});
</script>
</body>
</html>

Ajax does not display the result from mysql database

I have an issue with my ajax request and I can't figure out what is wrong, in console there is no error...
Here is my javascript file:
$(document).ready(function(){
done();
});
function done(){
setTimeout(function(){
updates();
done();
}, 50000);
}
function updates() {
$.getJSON("sedinte.php", function(data){
$("#results").empty();
$(".pagination").empty();
$.each(data.result, function() {$("#results").append("<tr class='"+this['aclass']+"'><td>"+this['object']+"</td><td>"+this['date']+"</td><td>"+this['amount']+"</td><td>"+this['paid']+"</td></tr>");
});
$.each(data.pagination, function() {
$("ul.pagination").append(this['controls']);
});
});
}
$("#btnAdd").click(function(){
$.post(
$("#addForm").attr("action"), $("#addForm :input").serializeArray(), function(info) {
$("#feedback").html(info);
});
clearInput();
});
$("#addForm").submit(function(){
return false;
});
function clearInput() {
$("#addForm :input").each( function() {
$(this).val(' ');
});
}
Here is my file I want to request:
<?php
#Get the total number of rows
$rows = $db->getTotalRows("sedinte");
#Set number of result to show on each page
$page_rows = 10;
#Get the last page
$last = ceil($rows/$page_rows);
#Make sure the last page is not below 1
if($last <1)
{
$last = 1;
}
$pagenum = 1; #Default page
#Get page number from URL vars if it is pressent, else it is = 1
if(isset($_GET['page']))
{
$pagenum = preg_replace('#[^0-9]#', '', $_GET['page']);
}
#Make sure the page number isn't below 1, or more than our last page
if($pagenum < 1)
{
$pagenum = 1;
}
else if($pagenum > $last)
{
$pagenum = $last;
}
#This sets the range of rows to query for the chosen page number
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows . ',' .$page_rows;
#This is for grabbing just one page worth of rows by applying limit
$sql = "SELECT * FROM sedinte ORDER BY id DESC $limit";
$query = mysqli_query($db->Conn(), $sql);
#Enstablish the pagination controls variable
$paginationCtrls = null;
#<li>2 <span class="sr-only">(current)</span></li>
#If there is more than 1 page worth of results
if($last != 1)
{
if($pagenum > 1)
{
$previous = $pagenum - 1;
$paginationCtrls .= '<li>«</li>';
#Render clickable number links that should appear on the left of the target page number
for($i = $pagenum - 4; $i < $pagenum; $i++)
{
if($i > 0)
{
$paginationCtrls .= '<li>'.$i.'</li>';
}
}
}
#Render the current page
$paginationCtrls .= '<li class="active">'.$pagenum.'<span class="sr-only">(current)</span></li>';
#Render clickable number lnks that should appear on the right of the target page number
for($i = $pagenum+1; $i <= $last; $i++)
{
$paginationCtrls .= '<li>'.$i.'</li>';
if($i >= $pagenum+4)
{
break;
}
}
if($pagenum != $last)
{
$next = $pagenum + 1;
$paginationCtrls .= '<li>»</li>';
}
}
$paginationArray = array();
array_push($paginationArray, array('controls' => $paginationCtrls));
$listTest = null;
$resultArray = array();
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC))
{
//$id = $row['id'];
$obiect = $row['obiect'];
$data = $row['data'];
$suma = $row['suma'];
$achitat = $row['achitat'];
if($achitat == 'Da')
{
$active_class= null;
}
else
{
$active_class= "danger";
}
array_push($resultArray, array('object' => $obiect,
'date' => $data,
'amount' => $suma,
'paid' => $achitat,
'aclass' => $active_class
));
/*
$listTest .=' <tr class="'.$active_class.'">
<td>'.$obiect.'</td>
<td>'.$data.'</td>
<td>'.$suma.'</td>
<td>'.$achitat.'</td>
</tr>';*/
}
echo json_encode(array("result" => $resultArray, "pagination" => $paginationArray));
mysqli_close($db->Conn());
?>
And here is my index file:
<?php
require 'includes/settings.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sedinte</title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-md-12">
<div role="tabpanel">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><span class="glyphicon glyphicon-eye-open"></span> Vezi Sedinte</li>
<li role="presentation"><span class="glyphicon glyphicon-plus-sign"></span> Adauga Sedinta</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="sedinte">
<div class="row">
<div class="col-xs-6 col-md-4">
<h4><span class="glyphicon glyphicon-usd"></span> Buget: 460 RON</h4>
</div>
<div class="col-xs-6 col-md-4 col-md-offset-4">
<h4><span class="glyphicon glyphicon-calendar"></span> Data: <?php echo date('D d M Y');?></h4>
</div>
</div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th><span class="glyphicon glyphicon-edit"></span> Obiect</th>
<th><span class="glyphicon glyphicon-calendar"></span> Data</th>
<th><span class="glyphicon glyphicon-usd"></span> Suma</th>
<th><span class="glyphicon glyphicon-ok"></span> Achitat</th>
</tr>
</thead>
<tbody id="results">
<?php //echo $listTest;?>
</tbody>
</table>
<ul class="pagination">
<?php //echo $paginationCtrls;?>
</ul>
</div>
<div role="tabpanel" class="tab-pane" id="adauga">
<div class="row">
<div class="col-md-6 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-body">
<form action="add.php" method="post" id="addForm">
<div class="form-group">
<label for="obiect">Obiect</label>
<input type="text" class="form-control" name="boxObiect" placeholder="M, L, R">
<!--
<select name="boxObiect" class="form-control">
<option>Matematica</option>
<option>Romana</option>
<option>Logica</option>
</select>
-->
</div>
<div class="form-group">
<label for="data">Data: </label>
<input type="text" class="form-control" name="boxData" placeholder="YYYY-MM-DD">
</div>
<div class="form-group">
<label for="radioAchitat">Achitat: </label>
<label class="radio-inline">
<input type="radio" name="radioAchitat" id="radioAchitat" value="Da"> Da
</label>
<label class="radio-inline">
<input type="radio" name="radioAchitat" id="radioAchitat" value="Nu" checked="checked"> Nu
</label>
</div>
<button type="submit" id="btnAdd" class="btn btn-primary">Adauga</button>
</form>
</div>
</div>
<div id="feedback"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script src="ajax/main.js"></script>
</body>
</html>
My data from the database is not showing... just the main template.
Please help me!
I Don't kow what's the problem because i did not read the full code, but that is a bug that i found so you can correct that and can try again :), i hope it will work, Thanks
header('Content-type: application/json');
echo json_encode(array("result" => $resultArray, "pagination" => $paginationArray));
mysqli_close($db->Conn());

When form send adds \r\n to the code i put inside

Here is the full page code
<?php
if (!isset($_SESSION)) session_start();
if(!isset($_SESSION['admin_vmp']))
header('Location: ./login.php');
include "header.php";
include "../functions.php";
if(isset($_POST['leaderboard1']))
{
$leaderboard1 = $_POST["leaderboard1"];
$leaderboard1=mysql_real_escape_string($leaderboard1);
$leaderboard2 = $_POST["leaderboard2"];
$leaderboard2=mysql_real_escape_string($leaderboard2);
$medrec = $_POST["medrec"];
$medrec=mysql_real_escape_string($medrec);
update_ads($leaderboard1,$leaderboard2,$medrec);
}
?>
<title>Ads - <?php echo(get_title()) ?></title>
<script type='text/javascript'>
$(window).load(function(){
$(document).ready(function () {
$('#selectall').click(function () {
$('.selectedId').prop('checked', this.checked);
});
$('.selectedId').change(function () {
var check = ($('.selectedId').filter(":checked").length == $('.selectedId').length);
$('#selectall').prop("checked", check);
});
});
});
</script>
<?php
include "header_under.php";
?>
<div id="containerHolder">
<div id="container">
<div id="sidebar">
<ul class="sideNav">
<li>Website</li>
<li>Thumbnails</li>
<li>Watermark</li>
<li>Media</li>
<li>Social Media</li>
<li>Ad Management</li>
<li>Admin Settings</li>
<li>Analytics (Stats Tracking)</li>
<li>RSS Settings</li>
<li>Sitemap Settings</li>
<li>Comments Setting</li>
</ul>
<!-- // .sideNav -->
</div>
<!-- // #sidebar -->
<!-- h2 stays for breadcrumbs -->
<h2>Ad Management</h2>
<div id="main">
<br />
<form action="./ads.php" method="post">
<fieldset>
<p><a name="top_leaderboard"><label><b>Top : Large leaderboard (728 x 90)</b></label></a><textarea name="leaderboard1"><?php echo(show_leaderboard1_ad()) ?></textarea></p>
<p><a name="bottom_leaderboard"><label><b>Bottom : Large leaderboard (728 x 90)</b></label></a><textarea name="leaderboard2"><?php echo(show_leaderboard2_ad()) ?></textarea></p>
<p><label><a name="med_rec"><b>Sidebar : Medium Rectangle (300 x 250)</b></label></a><textarea name="medrec"><?php echo(show_rectangle_ad()) ?></textarea></p>
<input type="submit" class="myButton" value="Update Ads">
</fieldset>
</form>
<?php
if(isset($_POST['leaderboard1']))
echo('<div class="alert alert-success">Ads Updated Successfully</div>');
?>
</div>
<!-- // #main -->
<div class="clear"></div>
</div>
<!-- // #container -->
</div>
<!-- // #containerHolder -->
<?php
include "footer.php";
?>
Im using this for google ads, after adding the ad code its saves but automaticly ads \r\n in some places.. Is there posibble way to fix this.
Wat i want to fix.. I want to fix that \r\n not to be putted after saving the code so if i put ads will be clean and same as google gives them.
Thank you very much!
function update_ads($leaderboard1,$leaderboard2,$medrec)
{
$update_query = "UPDATE ads SET leaderboard1='".mysql_real_escape_string($leaderboard1)."',leaderboard2='".mysql_real_escape_string($leaderboard2)."',rectangle='".mysql_real_escape_string($medrec)."'";
mysql_query($update_query);
}
you are running mysql_real_escape_string twice (inside the function and before you parse the values to the function), that's the problem
change
$leaderboard1 = $_POST["leaderboard1"];
$leaderboard1=mysql_real_escape_string($leaderboard1);
$leaderboard2 = $_POST["leaderboard2"];
$leaderboard2=mysql_real_escape_string($leaderboard2);
$medrec = $_POST["medrec"];
$medrec=mysql_real_escape_string($medrec);
update_ads($leaderboard1,$leaderboard2,$medrec);
to
update_ads($_POST["leaderboard1"],$_POST["leaderboard2"],$_POST["medrec"]);

Trying to show jqmobile grid(trirand) in a jquery mobile windows

Using JQuery Mobile I want to pop a dialog box where the user can enter in search filters and then when they submit the query show the jqmobile grid(trirand) inside a modal window. Is this possible. Here is my code below:
qr.php
<?php require_once '../auth.php'; require_once '../jqSuitePHP/jq-config.php'; // include the PDO driver class require_once '../../jqSuitePHP/php/jqGridPdo.php'; // Connection to the server $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Tell the db that we use utf-8 $conn->query("SET NAMES utf8"); if(isset($_REQUEST['a'])) { //get asset information $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); $sql = "SELECT asset_no, dept_id as dept, short_desc, `LOTO #` as loto FROM mfg_eng_common.machine WHERE asset_no ='".$_REQUEST['a']."'"; $result = $conn->query($sql); $row = $result->fetch(PDO::FETCH_ASSOC); //check to see if active work order exists in MWO system for current asset //status_id of 50 mean Approved/Closed $sql = "SELECT count(*) woCnt FROM mfg_eng_mwo.mwo WHERE asset_id ='".$_REQUEST['a']."' AND status_id != 50"; $result = $conn->query($sql); $woCnt = $result->fetch(PDO::FETCH_ASSOC); } else { header("Location: http://rworley-laptop.dayton-phoenix.com/dpg/mwo/forms/MWO.php"); } ?> <!DOCTYPE HTML> <html lang="en-US"> <head> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" /> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script> <script type="text/javascript"> function getWOCnt() { var cntval = <?php echo $woCnt['woCnt'];?>; if(cntval > 0) { if (confirm(" There are already active work order(s) for asset <?php echo $_REQUEST['a']?>. \n To see active work orders:\n Click Cancel and then click 'Update Work Orders'. \n\n To enter a new work order for asset <?php echo $_REQUEST['a']?> \n Click OK .")) { window.open("../forms/MWO.php?a=<?php echo $_REQUEST['a']?>", "new"); /* $(function () { $("#newMWO").on('click', (function (event) { event.preventDefault(); var loadVars=(encodeURI("../forms/MWO.php?a=<?php echo $_REQUEST['a']?>")); var dialogName= $("#mwoForm").load(loadVars); $(dialogName).dialog({ autoOpen: false, resizable: true, modal: true, bigframe: true, height: 600, width: 1000, overflow: scroll, resizable: true, title: "MWO New Work Order" }); dialogName.dialog('open'); return false; })); }); */ } } else { window.open("../forms/MWO.php?a=<?php echo $_REQUEST['a']?>", "new"); /* $(function () { $("#newMWO").on('click', (function (event) { event.preventDefault(); var loadVars=(encodeURI("../forms/MWO.php?a=<?php echo $_REQUEST['a']?>")); var dialogName= $("#mwoForm").load(loadVars); $(dialogName).dialog({ autoOpen: false, resizable: true, modal: true, bigframe: true, height: 600, width: 1000, overflow: scroll, resizable: true, title: "MWO New Work Order" }); dialogName.dialog('open'); return false; })); }); */ } }; </script> </head> <body> <div data-role="page" data-theme="b" align="center"> <div data-theme="a" data-role="header"> <h1>Maintenance Work Orders</h1> <img alt="<?php echo $_REQUEST['a']?>" src="../../Machine Pictures/<?php echo $row['dept']?>/<?php echo $row['asset_no']?>.jpg" height="240" width="300"/> <b><br><?php echo $row['short_desc']?></b> </div><!-- /header --> <br> <div data-theme="c" data-content-theme="d" > <hr> <?php echo "PM Procedure" ?> <b>|</b> <?php echo "Loto Procedure" ?> </div> <div data-role="collapsible-set" data-theme="b" data-content-theme="d" > <ul data-role="listview" data-inset="true" align="center" data-filter="false" data-theme="b"> <li> <a id="newMWO" name="newMWO" data-role="button" data-inline="true" target="_blank" onclick=getWOCnt() > New Work Order </a> </li> </ul> <ul data-role="listview" data-inset="true" align="center" data-filter="false" data-theme="b"> <li> Update Work Order </li> </ul> <ul data-role="listview" data-inset="true" align="center" data-filter="false" data-theme="b"> <li> <a href="../../mwo/MWO_mobile.php?a=<?php echo $_REQUEST['a']?>" data-role="button" data-inline="true" data-rel="dialog" target="mwoSearch" data-transition="slidedown" > Search Work Orders </a> </li> </ul> </div> <?php if(!($_POST)) { echo " <a href='#popupBasic' data-rel='popup' data-role='button' data-inline='true'>Quick Search</a> <div data-role='popup' id='popupBasic' data-transition='flip' > <a href='#' data-rel='back' data-role='button' data-theme='a' data-icon='delete' data-iconpos='notext' class='ui-btn-right'>Close</a> <form action='#' method='POST'> <div data-theme='a' data-role='header'> <h2>Look Up MWO</h2> </div> <p> Problem<textarea name='search_prob' data-theme = 'a' data-content-theme = 'd' rows = '3' cols = '50' id = 'search_prob' /></textarea> </p> <p> Solution<textarea name='search_sol' data-theme = 'a' data-content-theme = 'd' rows = '3' cols = '50' id = 'search_sol' /></textarea> </p> <p id = 'submit-area'> <input type='submit' data-theme='b' value='Search' id = 'sub1'/> </p> </form> </div> "; } else { echo " <ul data-role='listview' data-inset='true' align='center' data-filter='false' data-theme='b'> <li> <a href=\"QS.php?a=".$_REQUEST['a']."\" data-role='button' data-inline='true' data-rel='dialog' data-transition='slidedown'> Qucick Search Results </a> </li> </ul>"; } ?> <div data-role="footer" data-theme="a"> <h4>Dayton-Phoenix Group, Inc.</h4> </div><!-- footer --> </div><!-- page --> </body> </html>
QS.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MWO Quick Search</title>
<link rel="stylesheet" href="../../jquerymobile.jqGrid/css/themes/default/jquery.mobile.css" />
<link rel="stylesheet" href="../../jquerymobile.jqGrid/css/themes/ui.jqgridmobile.css" />
<link rel="stylesheet" href="../../jquerymobile.jqGrid/css/themes/shCoreEclipse.css" />
<link rel="stylesheet" href="../../jquerymobile.jqGrid/css/themes/shThemeEclipse.css" />
<script src="../../jquerymobile.jqGrid/js/jquery.js" type="text/javascript"></script>
<script src="../../jquerymobile.jqGrid/js/jquerymobile.jqGrid.min.js" type="text/javascript"></script>
<script src="../../jquerymobile.jqGrid/js/jquery.mobile.js" type="text/javascript"></script>
<script src="../../jquerymobile.jqGrid/js/grid.locale-en.js" type="text/javascript"></script>
</head>
<body>
Paging, sorting and searching
</body>
</html>
quickSearch2.php
<!DOCTYPE html>
<html>
<body>
<div id="page" data-role="page" data-theme="b">
<div data-role="header" data-theme="b" style="margin-bottom: 10px">
<h1> MWO Quick Search Results</h1>
Home
</div>
<!-- HTML table Definition -->
<table id='grid'></table>
<div id='pager'></div>
<!-- Java Scruipt Code -->
<script type='text/javascript'>
var a = <?php echo json_encode($_REQUEST['a']); ?>;
var prob = <?php echo json_encode($_REQUEST['search_prob']); ?>;
jQuery('#grid').jqGrid({
"hoverrows":false,
"viewrecords":true,
//"jsonReader":{"repeatitems":false,"subgrid":{"repeatitems":false}},
"gridview":true,
"url":"../../mwo/mobile/quicksearch.php?a=" + a + "&search_prob=" + prob,
"loadonce": true,
"rowNum":10,
"height":200,
"autowidth":true,
"sortname":"mwo_id",
"rowList":[10,30,40],
"datatype":"json",
"colModel":[
{"name":"e", "index":"empty", "sorttype":"int", "hidden":true,"width":50,"editable":true},
{"name":"MWO #", "index":"mwo_id", "sorttype":"int", "key":true,"width":80,"editable":true},
{"name":"DPG #", "index":"asset_id", "sorttype":"string", "width":80, "editable":true},
{"name":"Assigned to", "index":"assigned_id", "sorttype":"string", "width":80, "editable":true},
{"name":"Entered", "index":"entered_time", "sorttype":"datetime", "width":80, "editable":true,"datefmt":"m/d/Y", "searchoptions":{sopt:['eq']}, "formatter":"date","formatoptions":{"srcformat":"Y-m-d H:i:s","newformat":"m/d/Y"}},
{"name":"Problem", "index":"long_desc", "sorttype":"string", "width":80, "editable":true},
{"name":"Solution", "index":"solution", "sorttype":"string", "width":80, "editable":true}
],
"pager":"#pager"
});
</script>
</div>
</body>
</html>
json data being used:
{"page":1,"total":2,"records":13,"rows":[{"mwo_id":"1302271211","cell":["","1302271211","38315","-1","2013-07-08 11:13:19","approved test",""]},{"mwo_id":"1302271213","cell":["","1302271213","38315","-1","2013-07-11 09:26:26","yo momma is so fattest","how fat is she? she's so fat she left the house in heels and came back in flip-flops"]},{"mwo_id":"1302271214","cell":["","1302271214","38315","-1","2013-07-12 12:13:55","july test",""]},{"mwo_id":"1302271215","cell":["","1302271215","38315","-1","2013-07-08 08:59:56","test","update2"]},{"mwo_id":"1302271216","cell":["","1302271216","38315","-1","2013-07-09 06:14:02","test",""]},{"mwo_id":"1302271217","cell":["","1302271217","38315","-1","2013-07-08 09:01:30","yep testing","no answer yet"]},{"mwo_id":"1302271218","cell":["","1302271218","38315","-1","2013-07-09 09:59:46","new test of email system",""]},{"mwo_id":"1302271219","cell":["","1302271219","38315","","2013-07-08 12:33:09","email new test",""]},{"mwo_id":"1302271221","cell":["","1302271221","38315","12","2013-07-11 13:20:55","ANOTHER TEST OF NEW ...WITH EMAIL","AND THE ANSWER IS ....."]},{"mwo_id":"1302271222","cell":["","1302271222","38315","","2013-07-11 09:29:58","test...add issue",""]},{"mwo_id":"1302271223","cell":["","1302271223","38315","","2013-07-11 13:11:15","testing",""]},{"mwo_id":"1302271224","cell":["","1302271224","38315","7","2013-07-11 13:27:32","test with auto assign","no solution its all good"]},{"mwo_id":"1302271226","cell":["","1302271226","38315","7","2013-07-12 12:05:02","Meeting test",""]}]}

Undefined constant php error message in laravel

I am new in MVC framework. I created an application in Laravel Framework & it was working fine. Now after some modification when I want to view the index page the following error is shown to me-
Message:
Use of undefined constant php - assumed 'php'
Location:
C:\wamp\www\alpha.team.com\laravel\view.php(354) : eval()'d code on
line 32
Here is my view code of index.blade.php
#layout('/layouts/layout')
<link href='http://fonts.googleapis.com/css?family=Neucha' rel='stylesheet' type='text/css'>
<div id="top">
#section('navigation')
<!-- <li class="active"><i class="icon-user"></i> My Profile</li> -->
<li><i class="icon-book"></i> Dashboard</li>
#parent
#endsection
</div>
#section('content')
<!-- For showing error message if any error occours-->
<?php if(Session::get('error')): ?>
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Warning!</strong> <?php echo Session::get('error'); ?>
</div>
<?php endif; ?>
<!-- For showing success message.-->
<?php if(Session::get('success')): ?>
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Well done!</strong> <?php echo Session::get('success'); ?>
</div>
<?php endif; ?>
<div class="field-section">
<div class="hero-unit">
<!-- <a id="logo" href="#"><img alt="TechIndyeah" src="/uploads/logo.png" style="vertical-align: top;"></a> -->
<h1 style="display:inline;">Team TechIndyeah</h1>
<ul class="teams" style="text-align:center;">
#foreach($departments as $dept)
<?php// print_r($dept); ?>
<li>
<?php echo $dept->name; ?>
</li>
#endforeach
</ul>
</div>
</div> <!-- field-section div ends here-->
<!-- <div class="container"> -->
<div class="wrapper">
<div class="hero-unit" id="bg-pattern">
<h1 class="home-tag"> Tech-ing India<span><p>The team of enthusiastic tech fanatics</p></span></h1>
<p class="home-ptag">We are a team of enthusiastic tech fanatics and yes we are Apple fanboys too. We have sailed out together on a small boat and we do live in what Seth Godin says, “Small is the next big”. We love technology and we love you. Our team is free, creative and always brimming with ideas.</p>
<div class="row" style="background:none;">
<div class="span8">
<h1 class="home-tag" >About Us</h1>
<p class="home-ptag">TechIndyeah has a team which is highly process oriented and has a sharp client-centric approach. Our mission is to help you to build your footprints in business. We are a team inspired by a vision and driven by technology. We are driven by an offbeat approach when it comes to client servicing and support. We have been serving our clients for a long time and have won accolades galore. We are a team and we believe in making our time resourceful so that our clients get the most out of us. We are a band of developers, designers and marketers who can take your business online and also combat the stiff competition from similar players in your domain. </p>
</div>
<div class="span3">
<object type="image/svg+xml" data="/img/logo.svg">
<img alt="TechIndyeah" src="/img/logo.png" style="vertical-align:top;">
</object>
</div>
</div>
<div class="row">
<div class="span4">
<!-- <a id="logo" href="#"><img alt="TechIndyeah" src="/uploads/logo.png"></a> -->
</div>
<!-- <div class="span6" id="caption">
<h3>Here We Are</h3>
</div> -->
</div>
<div class="row">
<?php $something = $errors->all();
if(!empty($something)): ?>
<div class = "alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
#foreach ($errors->all('<p>:message</p>') as $input_error)
{{ $input_error }}
#endforeach
</div>
<?php endif; ?>
</div>
<!-- For showing all employee name in the front page.. Showcasing them..-->
<div id="hero-unit">
<script type="text/javascript">
//The departments are randomly comming in the page when it is first loaded..
(function($) {
// Get the list items and hide them
var items = $(".teams > li").css({opacity:0});
// Shuffle them
shuffle(items);
// Start the fade-in queue
nextItemFade(items);
// Animation callback to start next fade-in
function nextItemFade(items) {
// Fade in the first element in the collection
items.eq(0).animate({opacity:1}, 400, function() {
// Recurse, but without the first element
nextItemFade(items.slice(1));
});
}
// Shuffles an array
// Based on http://jsfromhell.com/array/shuffle
function shuffle(a) {
var j, // Random position
x, // Last item
i = a.length; // Iterator
// Loop through the array
while(i) {
// Select a random position
j = (Math.random() * i) | 0;
// Get the last item in the array
x = a[--i];
// Swap the last item with the item at the selected position
a[i] = a[j];
a[j] = x;
}
return a;
}
/* Minified version
function shuffle(a) {
for(var j, x, i = a.length; i; j = (Math.random() * i) | 0, x = a[--i], a[i] = a[j], a[j] = x);
return a;
} */
})(jQuery);
$(".nav1 li").each(
function(intIndex) {
var l = Math.floor(Math.random() * $(".nav1").width());
var t = Math.floor(Math.random() * $(".nav1").height());
$(this).css("left", l);
$(this).css("top", t);
$(this).on(
"click",
function() {
alert("l=" + l + " t=" + t);
}
);
}
);
$(".nav1 li").each(
function(intIndex) {
var l = Math.floor(Math.random() * 940);
var t = Math.floor(Math.random() * 500);
$(this).css("left", l);
$(this).css("top", t);
$(this).on(
"click",
function() {
alert("l=" + l + " t=" + t);
}
);
}
);
</script>
<style type="text/css">
.nav1
{
position:relative;
}
.nav1 li
{
padding: 10px;
position:absolute;
}
</style>
</div> <!-- #hero-unit ends here-->
<!-- </div> mucarousel div ends here -->
<div class="member-list">
<!-- <object type="image/svg+xml" data="/img/vector-tree2.svg"> -->
<!-- <img alt="TechIndyeah" src="/img/vector-tree2.png" style="vertical-align:top;"> -->
<!-- </object> -->
#foreach($departments as $dept)
<div id="<?php echo implode('_',explode(' ',$dept->name));?>" class="demo">
<ul class="member">
<?php $users = User::where('department_id','=',$dept->id)->get();
// $users = User::where('department_code','=',$dept->code)->get();
?>
#foreach($users as $user)
<li class="new-element" style="display:inline-block;" rel="tooltip" data-placement="right" data-original-title="<?php echo $user->first_name." ".$user->last_name;?>">
<a href="/home/view/<?php echo $user->username;?>" rel="tooltip" data-placement="right" href="#" data-original-title="<?php echo $user->first_name." ".$user->last_name."</br> ".$user->designation;?>">
<img class="hover-img" src="http://graph.facebook.com/<?php echo $user->facebook_id;?>/picture?type=large">
</a>
</li>
#endforeach
</ul>
Back To Top
</div>
#endforeach
<script type="text/javascript">
$(window).scroll(function(){
if ($(this).scrollTop() > 50) {
$('.scrollup').fadeIn();
} else {
$('.scrollup').fadeOut();
}
});
</script>
<script type="text/javascript">
//all links which start with a # will have an animated scroll to the target.
$('a[href^="#"]').on('click.smoothscroll',function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
// console.log($target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top - 10
}, 900, 'swing', function () {
window.location.hash = target;
});
});
$('.new-element').children('a').tooltip();
</script>
</div>
<h1 style="text-align:center;font-family: 'Lato light', sans-serif;text-shadow: 2px 1px #848686;">TechIndyeah Software Pvt. Ltd.</h1>
</div>
</div>
#endsection
</div>
I cannot understand. Please help.
I'm not familiar with Laravel, but it seems that an eval() in a file named view.php is rendering a template. So my guess is that someplace in your template (whatever template is being rendered) you have php where you really mean 'php'.
For example:
echo $data[php]; //you have this
echo $data['php']; //but it should be this
//or
if(php == $var){} //you have this
if('php' == $var){} //but it should be this
Can you share some of the code that is in your view.php file?
You're doing something wrong on line 32 of that file, so it would be very helpful if we can see what the code actually is :)

Categories