How To Fix This JavaScript Function? - javascript

I want to add confirm box by using JavaScript. So, here is the code that I have used. When I click on the Delete button, it shows me a Confirmation message and when I click Ok, it doesn't delete my row.
What is wrong with this? How can I fix this?
Here is the Index Page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="row"> <!-- Start Of The Row Class -->
<div class="col-md-8 col-sm-4 hero-feature"> <!-- Start Of The Col Class -->
<br><br>
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
include('ksdb.php');
// get results from database
$result = mysql_query("SELECT * FROM academic")
or die(mysql_error());
?>
<table class='table table-bordered'>
<tr class='danger'>
<th>ID</th>
<th>Name</th>
<th>Username</th>
</tr>
<?php
// display data in table
while($row = mysql_fetch_array( $result )) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><a href="AdminChangePw.php?id=<?php echo $row['id']; ?>" alt="edit" >Change</a></td>
<td><a href="AdminEdit.php?id=<?php echo $row['id']; ?>" alt="edit" >Edit</a></td>
<td><input type="button" onClick="deleteme(<?php echo $row['id']; ?>)" name="Delete" value="Delete"></td>
</tr>
<script language="javascript">
function deleteme(delid)
{
if(confirm("Do you want Delete!")){
window.location="AdminDel.php?id=' +id+'";
return true;
}
}
</script>
<?php
}
?>
</table>
</div> <!-- End Of The Col Class -->
</div> <!-- End Of The Row Class -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></script>
</body>
</html>

Change the id to 'delid'. You are calling the function as deleteme(delid).
So You Must use delid, instead of id.
function deleteme(delid)
{
if(confirm("Do you want Delete!")){
window.location.href="AdminDel.php?id="+delid; /*Change id to 'delid'*/
return true;
}
}

Use
window.location.href
Instead of window.location

There are a couple of problems with your function:
function deleteme(delid) {
if(confirm("Do you want Delete!")){
window.location="AdminDel.php?id='+id+'";// this should be delid, also bad quotes, also you want to set the href, not the location
return true;
}
}
Fixed:
function deleteme(delid) {
if(confirm("Do you want Delete!")){
window.location.href="AdminDel.php?id=" + delid;
return true;
}
}

Related

How can i display the list of his/her orders that made by my login user?

I want to know. How can i change or improve my codes so that the login user can only see his/her order items? He/she cannot see others orders that not made by him/her.
this is senarai_tempahan.php. This is the interface for displaying the list of orders from tbl_orders.
<?php
include('session.php');
include_once 'orders_crud.php';
if(isset($_SESSION['login_user'])){
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="icon.ico">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>EZ-Wedding4U : Senarai Tempahan</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<style type="text/css">
#import "main.css";
</style>
</head>
<body>
<?php include_once 'nav_bar3.php'; ?>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<div class="page-header">
<h2>Tempahan Saya</h2>
</div>
<table class="table table-striped table-bordered">
<tr>
<th>Gambar</th>
<th>Tempahan ID</th>
<th>Tarikh Tempahan</th>
<th>Nama Produk</th>
<th>Kuantiti</th>
<th>Harga per Unit</th>
<th>Jumlah Harga (RM)</th>
<th>Saiz</th>
<th>Nama Pelanggan</th>
<th>Alamat Pelanggan</th>
<th>Notel Pelanggan</th>
<th>Nama Syarikat</th>
<th></th>
</tr>
<?php
// Read
$per_page = 5;
if (isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 1;
$start_from = ($page-1) * $per_page;
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM tbl_orders, tbl_pelanggan WHERE
tbl_orders.nama_pelanggan = tbl_pelanggan.nama_penuh AND
tbl_pelanggan.nama_pengguna = '".$_SESSION['username']."' AND id =:oid
LIMIT $start_from, $per_page");
$stmt->execute();
$result = $stmt->fetchAll();
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
foreach($result as $readrow) {
?>
<tr>
<td> <?php if ($readrow['id'] == "" ) {
echo "No image";
}
else { ?>
<img src="produk/<?php echo $readrow['img'] ?>" class="img-responsive">
<?php } ?></td>
<td><?php echo $readrow['id']; ?></td>
<td><?php echo $readrow['tarikh_tempah']; ?></td>
<td><?php echo $readrow['nama_produk']; ?></td>
<td><?php echo $readrow['kuantiti']; ?></td>
<td><?php echo $readrow['harga']; ?></td>
<td><?php echo $readrow['total_harga']; ?></td>
<td><?php echo $readrow['saiz']; ?></td>
<td><?php echo $readrow['nama_pelanggan']; ?></td>
<td><?php echo $readrow['alamat_pelanggan']; ?></td>
<td><?php echo $readrow['notel_pelanggan']; ?></td>
<td><?php echo $readrow['namaSyarikat']; ?></td>
<td>
Kemas kini
Batal
</td>
</tr>
<?php } ?>
</table>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<nav>
<ul class="pagination">
<?php
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM tbl_orders, tbl_pelanggan
WHERE tbl_orders.nama_pelanggan = tbl_pelanggan.nama_penuh AND
tbl_pelanggan.nama_pengguna = '".$_SESSION['username']."' AND id =
:oid ");
$stmt->execute();
$result = $stmt->fetchAll();
$total_records = count($result);
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
$total_pages = ceil($total_records / $per_page);
?>
<?php if ($page==1) { ?>
<li class="disabled"><span aria-hidden="true">«</span></li>
<?php } else { ?>
<li><span aria-hidden="true">«</span></li>
<?php
}
for ($i=1; $i<=$total_pages; $i++)
if ($i == $page)
echo "<li class=\"active\">$i</li>";
else
echo "<li>$i</li>";
?>
<?php if ($page==$total_pages) { ?>
<li class="disabled"><span aria-hidden="true">»</span></li>
<?php } else { ?>
<li><span aria-hidden="true">»</span></li>
<?php } ?>
</ul>
</nav>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="main.js">
</script>
</body>
</html>
I have try this code but it is error. I think that this code is wrong but I do not know how to fix it. I'm just want to display the data from tbl_orders that nama_pelanggan is equal to nama_penuh from tbl_pelanggan based on the login user data. please help me and thank you for your time and answers.
You can do it very simply.
Just use WHERE id='$_SESSION["login_user"]'

Problems with Ajax when adding items to my shopping Cart PHP

I just started to learn how to program and I have been having issues with ajax when it comes to adding items to my cart. Everything is fine when it comes to adding items, its the ajax that is not working and my page constantly keeps refreshing. For the code since there is a lot of it I will put the things I think are the most important.
Index.php
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<title></title>
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click', '.add_to_cart', function(){
var product_id = $(this).attr("id");
var product_name = $('#name'+product_id+'').val();
var product_price = $('#price'+product_id+'').val();
var product_quantity = $('#quantity'+product_id).val();
if(product_quantity > 0)
{
$.ajax({
url:"index.php",
method:"POST",
data:{product_id:product_id, product_name:product_name, product_price:product_price, product_quantity:product_quantity},
success:function(data)
{
alert("Item has been Added into Cart");
}
});
}
else
{
alert("lease Enter Number of Quantity");
}
});
});
</script>
</head>
<body>
<header>
<?php
include_once'widget/header.php';
if (isset($_SESSION['u_id'])) {
include_once"include/addcart.php";
include_once "widget/shoppingcart.php";
}
?>
</header>
<main>
<div class="item-container">
<?php
$item = mysqli_query($db,"SELECT * FROM itemlist ORDER BY title");
include_once 'widget/container.php';
?>
</div>
</main>
Addcart.php
<?php
$row_ids = array();
//session_destroy();
//check if Add to Cart button has been submitted
if(filter_input(INPUT_POST, 'add_to_cart')){
if(isset($_SESSION['shopping_cart'])){
//keep track of how mnay products are in the shopping cart
$count = count($_SESSION['shopping_cart']);
//create sequantial array for matching array keys to products id's
$row_ids = array_column($_SESSION['shopping_cart'], 'id');
if (!in_array(filter_input(INPUT_POST, 'id'), $row_ids)){
$_SESSION['shopping_cart'][$count] = array
(
'id' => filter_input(INPUT_POST, 'id'),
'name' => filter_input(INPUT_POST, 'name'),
'price' => filter_input(INPUT_POST, 'price'),
'quantity' => filter_input(INPUT_POST, 'quantity')
);
// header("Location:index.php?addedtocart");
}
else { //product already exists, increase quantity
//match array key to id of the product being added to the cart
for ($i = 0; $i < count($row_ids); $i++){
if ($row_ids[$i] == filter_input(INPUT_POST, 'id')){
//add item quantity to the existing product in the array
$_SESSION['shopping_cart'][$i]['quantity'] += filter_input(INPUT_POST, 'quantity');
// header("Location:index.php?multtocart");
}
}
}
}
else { //if shopping cart doesn't exist, create first product with array key 0
//create array using submitted form data, start from key 0 and fill it with values
$_SESSION['shopping_cart'][0] = array
(
'id' => filter_input(INPUT_POST, 'id'),
'name' => filter_input(INPUT_POST, 'name'),
'price' => filter_input(INPUT_POST, 'price'),
'quantity' => filter_input(INPUT_POST, 'quantity')
);
}
}
if (filter_input(INPUT_POST, 'delete')) {
//loop thru intil products in shop cart == variable
foreach ($_SESSION['shopping_cart'] as $key => $row) {
if ($row['id'] == filter_input(INPUT_POST, 'id')) {
unset($_SESSION['shopping_cart'][$key]);
}
}
$_SESSION['shopping_cart'] =array_values($_SESSION['shopping_cart']);
}
?>
Shoppingcart.php
<div class="cart-container" align="right">
<div class="table-responsive">
<table class="table">
<table class="table">
<tr><th colspan="5"><h5>Order Details</h5></th></tr>
<tr>
<th width="40%">Product Name</th>
<th width="10%">Quantity</th>
<th width="20%">Price</th>
<th width="15%">Total</th>
<th width="5%">Action</th>
</tr>
<?php
if(!empty($_SESSION['shopping_cart'])):
$total = 0;
foreach($_SESSION['shopping_cart'] as $key => $product):
?>
<tr>
<td><?php echo $product['name']; ?></td>
<td><?php echo $product['quantity']; ?></td>
<td>$ <?php echo $product['price']; ?></td>
<td>$ <?php echo number_format($product['quantity'] * $product['price'], 2); ?></td>
<td>
<form method="post">
<input class="delete" type="submit" name="delete" value="Delete">
<input type="hidden" name="id" value="<?php echo $product['id']; ?>">
</form>
</td>
</tr>
<?php
$total = $total + ($product['quantity'] * $product['price']);
endforeach;
?>
<tr>
<td colspan="3" align="right">Total</td>
<td align="right">$ <?php echo number_format($total, 2); ?></td>
<td></td>
</tr>
<tr>
<!-- Show checkout button only if the shopping cart is not empty -->
<td colspan="5">
<?php
if (isset($_SESSION['shopping_cart'])):
if (count($_SESSION['shopping_cart']) > 0):
?>
Checkout
<?php endif; endif; ?>
</td>
</tr>
<?php
endif;
?>
</table>
</div>
</div>
Container.php
<?php
while ($row = mysqli_fetch_assoc($item)) {
?>
<div class='item-box'>
<img class='item_img' src="itemimg/<?php echo $row['img']; ?>"><figcaption><?php echo $row['title']; ?></ficgcaption>
<form method="post" class="add-form">
<div class='input-group xs-2'>
<input class="form-control" type="text" id="quantity<?php echo $row['id'] ?>" name="quantity" value="1">
<input class="btn btn-outline-primary btn-sm add-btns add_to_cart" type="submit" id="<?php echo $row['id'] ?>" name="add_to_cart" value="Add To Cart">
</div>
<input type="hidden" id="name<?php echo $row['id'] ?>" name="name" value="<?php echo $row['title'] ?>">
<input type="hidden" id="price<?php echo $row['id'] ?>" name="price" value="<?php echo $row['price']; ?>">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
</div>
</form>
<?php
}
?>
Your page will refresh because you are not telling your form to not submit by the default method (which is to reload the page as a POST). To stop the page from reloading and let ajax do the submission, you need to inject the event and then use preventDefault():
$(document).on('click', '.add_to_cart', function(e){
// This will stop the form from submitting and allow the rest of the
// ajax to continue working. If you don't have this, you will immediately
// submit the form which negates the use of ajax
e.preventDefault();

Update Selected Image Based on Checkbox check

I need to upload selected image but I don't have any idea to make it. Anyone could help me on this problem? Included code below. Thank you for helping in advance.
Test.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
function myFunction1(isChecked2){
$('.chckbox1').change( function() {
var isChecked2 = this.checked;
if(isChecked2) {
$(this).parents("tr:eq(0)").find(".product_img").prop("disabled",false);
} else {
$(this).parents("tr:eq(0)").find(".product_img").prop("disabled",true);}
})};
</script>
</head>
<body>
<form method="post" action="UPDATE.php">
<div class="row">
<div class="col-xs-4">
<table id="simple-table" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th class="center">Select</th>
<th class="center">Product Image</th>
<th class="center">New Image</th>
</tr>
</thead>
<tbody>
<?php
//connect to database
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//select table from database
mysql_select_db("MBTR", $con);
$result = mysql_query("SELECT * from maray_product_img WHERE product_id='P100044'");
//query resutl
$countrow = 1;
//read result
while($row = mysql_fetch_array($result))
{
$img_id=$row['img_id'];
$p_id = $row['product_id'];
$product_img_name = $row['product_img_name'];
$product_img = $row['product_img'];
$product_img_path = $row['product_img_path'];
//$product_quantity = $row['product_quantity'];
?>
<tr>
<td class="center" style="vertical-align:middle"> <input name="img_id[]" type="checkbox" id="check[]" class="chckbox1 ace" value="<?php echo $img_id;?>" onclick="myFunction1(this)"/><span class="lbl red"><input type="hidden" name="product_id[<?php echo $img_id;?>]" value="<?php echo $p_id;?>"></span><input type="hidden" name="product_img_name[<?php echo $img_id;?>]" value="<?php echo $product_img_name;?>"></td>
<td class="center"><img src="<?php echo $row['product_img_path'];?>" width="60" height="60"></td>
<td class="center" style="vertical-align:middle"><input type="file" name="product_img[<?php echo $img_id;?>]" id="product_img[]" class="product_img form-control" disabled></td>
</tr>
<?php
$countrow++;
}
?>
</tbody>
</table>
</div><!-- /.span -->
</div><!-- /.row -->
<button type="submit" name="submit">Update</button>
</form>
</body>
</html>
UPDATE.php
<?php
error_reporting(E_ALL & ~E_NOTICE);
include ("dbconfig.php");
require_once('auth.php');
$product_img_name=$_FILES["product_img"]["name"];
if((isset($_POST['img_id'])))
{
$rand = rand(5,987897899);
foreach($_POST["img_id"] as $imgId)
{
//$product_img_name= $_POST['product_img_name'][$imgId];
$tmpName = $_FILES['product_img_name']['tmp_name'][$imgId];
$imagetmp=addslashes (file_get_contents($tmpName));
$name=basename($_FILES['product_img_name']['name'][$imgId]);
$t_name=$_FILES['product_img']['tmp_name'][$imgId];
$dir='upload';
$new_name= date('dmY')."_".$product_code."_".$rand."_".$name;
if(move_uploaded_file($t_name,$dir."/".$new_name))
{
$query = mysql_query("UPDATE maray_product_img set product_img_name='$imagename',
product_img_path='upload/$imagename', product_img='$imagetmp' where img_id='$imgId' LIMIT 1");
echo "<script>alert ('Successfull! Data has been changed.')</script>";
echo "<script>window.location = 'test.php'</script>";
}
else
{
echo "<script>alert ('Failed to update. Please try again')</script>";
}
}
}
?>
Hope experts can help me on this. I'm new to PHP. Some of the code which I got from others. Really need help. Thank you in advance.

DataTables javascript could not be applied to repeating tables

I have a table function (table_view.php)
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="test_coding_rosa/table_design2.css">
</head>
<body>
<?php
$row_id="";
if($_GET['page']==1 || isset($_GET['page'])==false){
$row_id=1;
}elseif (isset($_GET['page']) && $_GET['page']>1) {
$row_id=($_GET['page']-1)."1";
}
$doc = JFactory::getDocument();
$doc->addScript('http://code.jquery.com/jquery-1.11.0.min.js');
$doc->addScript('http://datatables.net/download/build/nightly/jquery.dataTables.js');
$doc->addScriptDeclaration('
jQuery(document).ready( function () {
jQuery("#main-table").DataTable();
});
');
?>
<h1><?php echo $this->title ?></h1>
<table id="main-table" border="<?php echo $this->tableBorder ?>" class="display" <?php if(!empty($this->tableWidth)) echo 'width="'.$this->tableWidth.'"';?> >
<thead>
<?php
if(!$this->hideHeaderTable)
{
if($_GET['t']!='maklumat_ringkas'){
echo "<tr><th width='10px'>Bil</th>";
}
foreach($this->tableData[0] as $key=>$tableHeader)
{
?>
<th width="<?php echo $this->tableData[1][$key] ?>" scope="col"><?php echo $this->tableData[0][$key] ?></th>
<?php
}
?>
</tr>
</thead>
<?php
}
$lenData = count($this->tableData);
for ($j=3;$j < $lenData; ++$j)
{
?>
<tbody>
<tr class="centertable" <?php if($j % 2==1) echo 'bgcolor="#EFF4FB"'?>><?php if($_GET['t']!='maklumat_ringkas'){echo "<td>".$row_id++."</td>";}?>
<?php
foreach($this->tableData[0] as $key=>$tableHeader)
{
?>
<td width="<?php echo $this->tableData[1][$key] ?>" <?php echo $this->tableData[2][$key] ?>><?php echo stripslashes($this->tableData[$j][$key]) ?></td>
<?php
}
?>
</tr>
</tbody>
<?php
}
?>
</table>
</body>
</html>
This table_view.php is the default table for all data in the site. As you can see in the photo below, there are multiple tables being called from table_view.php.
The problem here is, I wanted to use DataTables.net to include the pagination of the tables. However, only the first table has been successfully implemented with DataTables.net plugin.
How can I implement it on all of the tables? Since all the tables are being called from the same function file (table_view.php), the table id is the same.
UPDATED declaration
$doc = JFactory::getDocument();
$doc->addScriptDeclaration("
jQuery('[id='main-table']').each(function(i,e) {
var id=jQuery(this).attr('id');
jQuery(this).attr('id', id+'_'+i);
jQuery(this).addClass('datatable-identifier');
}); ");
$doc->addScript('http://code.jquery.com/jquery-1.11.0.min.js');
$doc->addScript('http://datatables.net/download/build/nightly/jquery.dataTables.js');
$doc->addScriptDeclaration('
jQuery(document).ready( function () {
jQuery(".datatable-identifier").dataTable();
} );
Having multiple elements with the same id is a very bad habit :) You should really try to avoid it. Though HTML is forgiving, it results as you see in all kind of problems when trying to access elements in javascript.
If it is impossible to avoid, you could run the following function before calling dataTable() :
jQuery('[id="main-table"]').each(function(i,e) {
var id=jQuery(this).attr('id');
jQuery(this).attr('id', id+'_'+i);
jQuery(this).addClass('datatable-identifier');
});
This will rename the table id's to main-table_1, main-table_2 and so on. The class datatable-identifier is just a dummy class used when initializing the dataTables, change your code to :
jQuery(document).ready( function () {
jQuery(".datatable-identifier").dataTable();
});

ajax with jquery php not working properly? [duplicate]

This question already has answers here:
undefined index text fields php database?
(2 answers)
Closed 8 years ago.
how exactly ajax jquery working. i am new in ajax and jquery.
i want to delete row my using ajax.
index.php
<head><link rel="stylesheet" type="text/css" href="css/style.css"></head>
<h1>Login Here</h1>
<form name="f1" action="login.php" method="post">
<table border="1">
<tr><td>username</td><td><input type="text" name="t1"></td>
</tr>
<tr><td>password</td><td><input type="password" name="t2"></td></tr>
<tr><td><input type="submit" value="login"></td>
<td class="error"><?php if(isset($_GET['wrong_detial'])){
echo "RE-ENTER username and password !! "; }?>
</td>
</tr>
</table>
</form>
login.php
<head>
<script type="text/javascript" src="jquery.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript">
function del() {
var info = 'id=' + id;
$.ajax({
type: 'get',
url: 'delete.php',
success: function (result) {
$("#div1").html(result);
}
});
return false;
}
</script>
</head>
<?php
include "db/db.php";
$user=$_POST['t1'];
$pass=$_POST['t2'];
$result=mysql_query("select * from registor where username='$user' and password='$pass' ")or die(mysql_error());
$row=mysql_fetch_row($result);
?>
<h1>Welcome Mr. <?php echo $user;?></h1>
<?php
if(!$user == $row[1] || !$pass ==$row[2]){ //if username or password not matched with database
header("location:account.php?wrong_detial");
}
else{
if($user == 'admin'){ //if admin login
?>
<table border="1">
<tr><td>User ID</td><td>Username</td><td>Password</td><td>Email-ID</td><td>delete</td></tr>
<?php
$admin_result=mysql_query("select * from registor");
while($admin_db=mysql_fetch_row($admin_result)){
?>
<tr>
<td><?php echo $admin_db[0];?></td>
<td><?php echo $admin_db[1];?></td>
<td><?php echo $admin_db[2];?></td>
<td><?php echo $admin_db[3];?></td>
<td id="div1">
Delete <!-- Deleting single record-->
</td>
</tr>
<?php
}
?>
</table>
<?php }
?>
delete.php
<?php
include "db/db.php";
if($_GET['delete']){
$drop=$_GET['delete'];
}
$result=mysql_query("delete from registor where username='$drop'");
if($result){
echo "deleted";
}
?>
what is the solution of this.
is there better way to delete record from database using ajax jquery.
Missing end curly braces in login.php for else block.
</table>
<?php }
?>
should be
</table>
<?php }
}
?>

Categories

Resources