jQuery does not delete user info - php

I have a php page that uses a jQuery to confirm before deleting data, Infact when I click delete it doesnt do anything the link doesnt do anything, I tried my efforts still nothing happens, please assist me
my code
teacher.php
<?php
require_once('../auth.php');
?>
<html>
<head>
<title>Silay Institute</title>
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
<!--sa poip up-->
<link href="src/facebox.css" media="screen" rel="stylesheet" type="text/css" />
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="src/facebox.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('a[rel*=facebox]').facebox({
loadingImage : 'src/loading.gif',
closeImage : 'src/closelabel.png'
})
})
</script>
<link rel="stylesheet" href="febe/style.css" type="text/css" media="screen" charset="utf-8">
<script src="argiepolicarpio.js" type="text/javascript" charset="utf-8"></script>
<script src="js/application.js" type="text/javascript" charset="utf-8"></script>
<style>
#mainhhh {
background: none repeat scroll 0 0 #FFFFFF;
border: 8px solid #EEEEEE;
border-radius: 5px 5px 5px 5px;
box-shadow: 0 0 10px #4E707C;
font: 11px "Trebuchet MS",Verdana,Arial,Helvetica,sans-serif;
margin: 5em auto;
position: relative;
text-align: left;
width: 1000px;
}
#mainhhh h1 {
background: none repeat scroll 0 0 #0092C8;
border-bottom: 1px solid #007DAB;
color: #FFFFFF;
font-size: 14px;
margin: 0;
padding: 5px 10px;
text-shadow: 0 1px 0 #007DAB;
}
</style>
</head>
<body>
<div id="mainhhh">
<h1>
<a id="addq" href="index.php" title="click to enter homepage" style="background-image:url('../images/out.png'); background-repeat:no-repeat; padding: 3px 12px 12px; margin-right: 10px;"></a>
<label for="filter">Filter</label> <input type="text" name="filter" value="" id="filter" />
<a rel="facebox" href="addteacher.php" id="addq">Add Teacher</a>
</h1>
<table cellpadding="1" cellspacing="1" id="resultTable">
<thead>
<tr>
<th style="border-left: 1px solid #C1DAD7"> Name </th>
<th>ID Number</th>
<th>Work</th>
<th>Gender</th>
<th>Status</th>
<th>Birthday</th>
<th>Advisory</th>
<th> Action </th>
</tr>
</thead>
<tbody>
<?php
include('../connect.php');
$result = mysql_query("SELECT * FROM teacher");
while($row = mysql_fetch_array($result))
{
echo '<tr class="record">';
echo '<td style="border-left: 1px solid #C1DAD7">'.$row['fname'].' '.$row['mname'].' '.$row['lname'].'</td>';
echo '<td><div align="left">'.$row['idnumber'].'</div></td>';
echo '<td><div align="left">'.$row['work'].'</div></td>';
echo '<td><div align="left">'.$row['gender'].'</div></td>';
echo '<td><div align="left">'.$row['status'].'</div></td>';
echo '<td><div align="left">'.$row['bday'].'</div></td>';
echo '<td><div align="left">';
$sdsd=$row['idnumber'];
$results = mysql_query("SELECT * FROM `teacher` JOIN `advisory` ON `advisory`.`tid`=`teacher`.`idnumber`");
while($rows = mysql_fetch_array($results))
{
echo $rows['level'].' section '.$rows['section'];
}
echo '</div></td>';
echo '<td><div align="center"><a rel="facebox" href="editprofile.php?id='.$row['id'].'" title="Click To Edit">Edit Profile</a> | delete</div></td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
<script src="js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$(".delbutton").click(function(){
//Save the link in a variable called element
var element = $(this);
//Find the id of the link that was clicked
var del_id = element.attr("id");
//Built a url to send
var info = {'id': del_id};
if(confirm("Sure you want to delete this update? There is NO undo!"))
{
$.ajax({
type: "GET",
url: "deleteteacher.php",
data: info,
success: function(){
}
});
$(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow");
}
return false;
});
});
</script>
</body>
</html>
deleteteacher.php
<?php
// This is a sample code in case you wish to check the username from a mysql db table
include('../connect.php');
if($_GET['id'])
{
$id = intval($_GET['id']);
$sql = "delete from teacher where id='$id'";
mysql_query( $sql);
}
?>

As I remember, you should send a JSON object as data; its means you should make a dictionary, not just an assignment. When you write $_GET['id'] compiler searches for an element in the data dictionary with key "id" to returns its value; but since you don't send a dictionary structured data, it returns NULL and of course nothing will happen.
You should write something like this in your delete function:
var info = {'id': del_id};

Related

Date range from reports , not working properly because of query

What to add in my query to restrict users from choosing wrong dates ,
E.G. From March 7 To March 2 , the transaction within march 2-7 does not show up ,but when you change it to march 7 to april 7 it shows all transaction , is
there anything that I can add to restrict users from doing that.
Please help me.
Thank you very much.
This is my sales.php file where the user will choose what date to show.
<form action="total_sales.php" method="post">
From: <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required pattern="[0-9]{4}+[0-9]+[0-9]"> To: <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required pattern="[0-9]{4}+[0-9]+[0-9]">
<input type="submit" value="Show Sales" name="salesbtn" ></form></center>
This is my total_sales.php file.
<head>
<script>
$(function() {
$( "#tabs" ).tabs();
$('a[rel*=facebox]').facebox();
$( ".datepicker" ).datepicker();
});
$(document).ready(function(){
// Write on keyup event of keyword input element
$("#searchme").keyup(function(){
// When value of the input is not blank
if( $(this).val() != "")
{
// Show only matching TR, hide rest of them
$("#searchTbl tbody>tr").hide();
$("#searchTbl td:contains-ci('" + $(this).val() + "')").parent("tr").show();
}
else
{
// When there is no input or clean again, show everything back
$("#searchTbl tbody>tr").show();
}
});
});
// jQuery expression for case-insensitive filter
$.extend($.expr[":"],
{
"contains-ci": function(elem, i, match, array)
{
return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
</script>
<script>
function goBack() {
window.history.back();
}
</script>
<?php include('session.php'); ?>
<?php include('header.php'); ?>
<?php include('navbar.php'); ?>
<style>
.footer1 {
position: absolute;
right: 45%;
font-family: ""Lucida Console", Monaco, monospace";
top: 0%;
width: 80%;
background-color:#F8F8FF;
color: black;
text-align: left;
}
h3{
font-size:20px;
font-family: "Arial";
}
table {
width:60%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: center;
}
#media print {
#page { margin: 0; }
body { margin: 1cm; }
#printPageButton {
display: none;
}
#e{
display:none;
}
.footer {
position: fixed;
left: 0;
font-family: ""Lucida Console", Monaco, monospace";
bottom: 0;
width: 100%;
background-color:#F8F8FF;
color: black;
text-align: center;
}
}
</style>
<div style="height:30px;"></div>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-0">
<br><img src="../upload/logo.jpg" align="center" class="footer1" style="height:50px; width:50px;"><br>
<br>
<?php
if(isset($_POST['salesbtn'])) {
$from = date('Y-m-d', strtotime($_POST['dayfrom']))." 00:00:01";
$to = date('Y-m-d', strtotime($_POST['dayto']))." 23:59:59";
?>
<center><h1> Product Sales Report </h1><h3>From (<?php echo $from; ?>) To (<?php echo $to; ?>)</h3>
<button id="printPageButton" onClick="window.print();" class="btn btn-primary" button type="submit">Print</button>
<button id="e" class="btn btn-primary" onclick="goBack()">Back</button>
<br><br>
<table width="100%" cellspacing="0" cellpadding="0" style="font-family:Arial Narrow, Arial,sans-serif; font-size:15px;" border="1">
<tr>
<td width="30%"><div align="center"><strong>Purchase Date</strong></div></td>
<td width="30%"><div align="center"><strong>Customer</strong></div></td>
<td width="40%"><div align="center"><strong> Purchase Name</strong></div></td>
<td width="40%"><div align="center"><strong>Quantity</strong></div></td>
</tr>
<?php
try {
require ("conn.php");
$stmt1 = $conn->prepare("select * from sales_detail left join product on product.productid=sales_detail.productid left join sales on sales.salesid=sales_detail.salesid left join customer on sales.userid=customer.userid where product.supplierid='".$_SESSION['id'] ."' AND sales_date BETWEEN '$from' AND '$to' order by sales.sales_date desc");
$stmt1->execute();
while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
$sales_date = $row['sales_date'];
$customer_name = $row['customer_name'];
$product_name = $row['product_name'];
$sales_qty = $row['sales_qty'];
?>
<tr align="center">
<td><?php echo $sales_date; ?></td>
<td><?php echo $customer_name; ?></td>
<td><?php echo $product_name; ?></td>
<td><?php echo $sales_qty; ?></td>
</tr>
</center>
<?php
}
}
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
}
?>
<tr>
</tr>
</table> </br> </br>
</div>
</div>
</div>
<?php include('script.php'); ?>
<?php include('modal.php'); ?>
<?php include('add_modal.php'); ?>
<script src="custom.js"></script>
So, I tried this and it worked:
the scripts HAVE TO BE in that order (if not it will break)
There is some problem with your pattern, but with Datepicker, you don't need it anyway
After the FROM Date selection I would set the minDate of the TO Date to +1d
Code Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<title>Document</title>
</head>
<body>
<form action="total_sales.php" method="post">
From:
<input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required > To:
<input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required >
<input type="submit" value="Show Sales" name="salesbtn">
</form>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.21/jquery-ui.min.js"></script>
<script>
$(function () {
$(".datepicker").datepicker({
dateFormat: "yy-mm-dd",
minDate: "-1d",
maxDate: "+1w"
});
});
</script>
</body>
</html>

pass data to two fields

Hi I am trying to make a autocomplete function where I use a search field and write the first letters of the name of a company. the code vill search an online database for the company and there will be a list of suggestions. for example
company1 street1 zipcode etc.
company2 astreet2 zipcode etc.
company3 street1 zipcode etc.
I will click on one of the listed companies and it vill populate field1 with company1 field2 street field3 zipcode etc. but I cant make it. I dont reallt know how to do this and Im trying to learn and understand but this is too complex for me so I hope any of you guys can hekp me - thanks in advance.
This is how my code looks like so far.
main page:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link href="layout.css" rel="stylesheet" type="text/css">
<link href="menu.css" rel="stylesheet" type="text/css">
</head>
<style>
.kundsok {
border: 1px solid #a8d4b1;
background-color: #c6f7d0;
margin: 2px 0px;
padding: 40px;
border-radius: 4px;
}
#ftg-list {
float: center;
list-style: none;
margin- top: -3px;
padding: 0;
width: 190px;
}
#ftg-list li {
padding: 10px;
background: #f0f0f0;
border-bottom: #bbb9b9 1px solid;
}
#ftg-list li:hover {
background: #ece3d2;
cursor: pointer;
}
#search-box {
padding: 10px;
border: #a8d4b1 1px solid;
border-radius: 4px;
}
</style>
<script src="jquery-3.2.1.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$("#search-box").keyup(function() {
$.ajax({
type: "POST",
url: "readkund_eniro.php",
data: 'keyword=' + $(this).val(),
beforeSend: function() {
$("#search-box").css("background", "#FFF url(LoaderIcon.gif) no-repeat 165 px ");
},
success: function(data) {
$("#suggesstion-box").show();
$("#suggesstion-box").html(data);
$("#search-box").css("background", "#FFF");
}
});
});
});
function selkund(val, val2) {
$("#search-box").val(val);
$("#foretag_name").val(val);
$("#stad").val(val2);
$("#suggesstion-box").hide();
}
</script>
<body>
<div id="sidlayout">
<div id="content">
<?php include "menukunder.php"; ?>
<div class="kundsok">
<center>
<input type="text" id="search-box" name ="search-box" placeholder="kund" >
<div id="suggesstion-box"></div>
</form>
<h1></h1>
<H3></H3>
<center>
<form action="sida3ka.php" method="post">
<fieldset>
<label title="Skriv in företagets namn" for="foretag_name">Företag:</label>
<input type="text" name="foretag_name" id="foretag_name">
<label title="Skriv in stad" for="stad">Stad:</label>
<input type="text" name="stad" id="stad">
</fieldset>
</form>
</div>
</div>
</body>
</html>
on the other page called readkund_eniro.php the code looks like this
$url = 'https://api.eniro.com/cs/search/basic?profile=Martens&key=3653823918839001013&country=se&version=1.1.3&search_word
=' . $_POST["keyword"] . '&geo_area=stockholm';
$response = file_get_contents($url);
$json = json_decode($response, true);
if(!empty($json)) {
?>
<ul id="ftg-list">
<?php
foreach($json['adverts'] as $ftg) {
?>
<li onClick="selkund('<?php
echo $ftg["companyInfo"]['companyName'];
echo $ftg["address"]['streetName'];
?>');"><?php
echo $ftg["companyInfo"]['companyName'];
?>
</li>
<?php
}
?>
</ul>
<?php
}
I the database respons will be
$ftg["companyInfo"]['companyName']
$ftg["address"]['streetName']
$ftg["address"]['postCode']
and so on. thanks again
Best regards Johan
i think there is problem in API url at readkund_eniro.php file. can you please try with as below.
$url = "https://api.eniro.com/cs/search/basic?profile=Martens&key=3653823918839001013&country=se&version=1.1.3&search_word=".$_POST['keyword']."&geo_area=stockholm";
another thing i found with your response text inside
<li onClick="selkund('<?php echo $ftg["companyInfo"]['companyName'];?>', '<?php echo $ftg["address"]['streetName'];?>');"><?php
echo $ftg["companyInfo"]['companyName']. ', '. $ftg["address"]['streetName'].', '. $ftg["address"]['postCode'] ;
?>
</li>

Running jquery funtion over php mysql while loop

The main aim is to display the row when the master row is clicked, there will be multiple records for one single incident id. how to apply jquery function for this type of output. Helps appreciated.
I tried using jexpand function but its not working.
The main aim is to get output like, when one particular row is clicked the remaining set of row with same id should be expanded and vice-versa.
The table results are fetched from mysql database.
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
body { font-family:Arial, Helvetica, Sans-Serif; font-size:0.8em;}
#report { border-collapse:collapse;}
#report h4 { margin:0px; padding:0px;}
#report img { float:right;}
#report ul { margin:10px 0 10px 40px; padding:0px;}
#report th { background:#7CB8E2 url(header_bkg.png) repeat-x scroll center left; color:#fff; padding:7px 15px; text-align:left;}
#childALL { background:#C7DDEE none repeat-x scroll center left; color:#000; padding:7px 15px; }
#report tr.td { background:#fff url(row_bkg.png) repeat-x scroll center left; cursor:pointer; }
#report div.arrow { background:transparent url(arrows.png) no-repeat scroll 0px -16px; width:16px; height:16px; display:block;}
#report div.up { background-position:0px 0px;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#report tr:siblings").show();
$("#report tr:siblings").hide();
$("#report div.arrow").click(function(){
$(this).next("#childALL").toggle();
$(this).find(".arrow").toggleClass("up");
});
//$("#report").jExpand();
});
</script>
</head>
<body>
<center>
<img src="abc.jpg" width="400px" height="100px" />
</center>
<?php
$con= mysqli_connect("172.28.212.145", "root", "root", "xxx");
if(!$con)
{
die('not connected');
}
$con= mysqli_query($con, "Select Incident_id,name,qualification from masterdata;");
?>
<div>
<center>
<table id="report">
<tr>
<th>Incident Id</th>
<th>name</th>
<th>Qualification</th>
<th></th>
</tr>
<?php
$incident = null;
while($row = mysqli_fetch_array($con))
{
if( $row['Incident_id'] != $incident )
{
$incident = $row['Incident_id'];
?>
<tr>
<td>
<?php echo $row['Incident_id']; ?>
</td>
<td>
<?php echo $row['name']; ?>
</td>
<td>
<?php echo $row['JournalUdpdateChanges']; ?>
</td>
<td><div class="arrow"></div></td>
</tr>
<?php } else { ?>
<tr id="childALL">
<td >
<?php echo $row['Incident_id']; ?>
</td>
<td >
<?php echo $row['name']; ?>
</td>
<td >
<?php echo $row['qualification']; ?>
</td>
<td >
<?php echo $row['Priority_im']; ?>
</td>
</tr>
<?php
}
}
?>
</table>
</center>
</div>
</body>
</html>
Bootstrap makes really easy work out of this.
Bootstrap Accordion

Trouble with PHP success response via ajax - jquery

I am having a bit of trouble getting a search function working using ajax to bring up results as the user types in a name.
This is the site in question (you can click view all to see what is searchable)
http://ra-yon.com/beta/Test_sites/HFE/admin/contact.php
The query in action
http://ra-yon.com/beta/Test_sites/HFE/include/queryc.php?query=ra-yon&clause=email
The code in question
<html>
<head>
<style type="text/css">
body
{
background:black;
color:black;
width:100%;
}
#center
{
width:90%;
height:110%;
background:white;
margin:0 auto;
text-align:center;
color:black;
}
#insert{
background:navy; color:white; font-family:impact; font-size:18px;width:170px; height:170px; border-radius:50%;
margin:0 auto;
float: left; margin-left: 100px;
top:200px;
position: relative;
}
#insert:hover
{
background:white;
color:navy;
}
label
{width:150px;}
td
{
border:solid 2px black;
max-width: 250px;
text-align: center;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
function sendPHP(){
$('#table,#table2').css('display','none');
var query = $('#searchname').attr('value');
var clause = $('#searchclause').attr('value');
$.ajax({
url: '../include/queryc.php?,
type: 'POST',
data: "query="+query+"&clause="+clause,
dataType: 'html',
success:
function(data) {
$(data).appendTo('#table');
}
});
return false;
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script></head>
<body>
<h4 style="float:right; color:blue; position: relative; left:-100px;" id="goback"> Go back? </h4>
<div id="center">
<div id="queryform1" >
View All?
<span style="color:black;">search</span> <input type='text' onKeyUp="sendPHP();" name='searchname' id="searchname" />
<span style="color:black;">search by</span> <select name="searchclause" id="searchclause">
<option value="name">Name</option>
<option value="email">Email Address</option>
<option value="subject">Subject</option>
<option value="date">Date</option>
</select>
Download file?
<div id="table2" style="display: none; margin: 0 auto; position: relative; top:40px; max-width:700px;">
<div id="viewall">
<?php
include '../include/include.php';
$sql = 'select * from contactus' ;
//print_r($sql);
$result=mysql_query($sql);
?>
<table>
<tbody>
<th>Name</th><th>Email</th><th>Subject</th><th style="width:200px;">Message</th><th>Date</th>
<tr>
<?php
while ($client = mysql_fetch_array($result, MYSQL_ASSOC)){
echo "
<tr>
<td >".$client[name]."</td>
<td >".$client[email]."</td>
<td >".$client[subject]."</td>
<td >".$client[message]."</td>
<td >".$client[date]."</td>
</tr>";
} ?>
</tbody></table>
</div></div><div id="table">TestTestTest</div>
</div></div>
</body>
</html>
Its a bit messy right now, I am planning on cleaning it up after I get it working.
Thank you all so much!
Checked your code in Console. Your function is failing. You are missing a single quote here:
url: '../include/queryc.php?',
I use Google Chrome's Console as well as the Console found in the Firbug extension for Mozilla Firefox. They both are invaluable in helping sort out the minor issues

How to pass selected value by jQuery

I want to pass selected value on invoice.php file using jQuery. After sending value on invoice.php file. I want to show invoice.php file echo result on index.php page selected input box. Like an example: If anyone select Item then rate show on rate input box. Here is my code and image
index.php file code:
<html>
<head>
<title>Invoice</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".item").change(function(){
calculate();
});
});
function calculate() {
var item = [];
$(".item").each(function() {
var num=(this.value);
item.push(num);
});
$('input[name=rate]').each(function(i){
$.get(
'/invoice_final_2.php',
{'product':item[i]},
function(data) {
$(this).html(data);
});
});
}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
</script>
<style type="text/css">
table
{
border: 1px solid black;
border-bottom: none;
width: 300px;
}
td
{
border-left: 1px solid black;
border-bottom: 1px solid black;
padding:5px 5px 5px 5px;
}
#first
{
border-left: none;
border-bottom: 1px solid black;
}
</style>
</head>
<body>
<form method='post' name='form1' action='welcome.php'>
<table cellpadding="0" cellspacing="0">
<tr>
<td id="first">Item</td>
<td>Rate</td>
</tr>
<?php
$num=4;
for ($i=0; $i<$num; $i++)
{
echo "
<tr>
<td id='first'>
<select class='item' name='item'>
<option>Select one</option>
<option>Deluxe Plan</option>
<option>Premium Plan</option>
<option>Standard Plan</option>
<option>Economy Plan</option>
</select>
</td>
<td><input class='rate' type='text' name='rate'/></td>
</tr>";
}
?>
</table>
</form>
</body>
</html>
invoice.php file code:
<?php
include "dbconnect.php";
$product=$_GET['product'];
$query="select * from item where item_name='$product'";
$result=mysql_query or die (mysql_error());
$row=mysql_fetch_assoc($result);
$rate=$row['rate'];
echo "$rate";
?>
I'm not sure what you are trying to achieve, but you don't need to use each and send values one by one using indexes, you can send the array once.
function calculate() {
var items = $(".item").map(function() {
return this.value;
}).get();
$.get('/invoice_final_2.php',
{'product': items },
function(data) {
//
}
);
}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Categories