The scenario is when I click on the X image next to a record in the tour_manage.php, this deletes the record by which is executed by another php page called delete_tour.php
I have managed to add the pop up box to the X image and when I click on the X, the message box comes up saying OK to delete or to CANCEL. However, the problem is when I click on OK and/or CANCEL, both buttons delete the record.
Help please!
These are the 2 scripts I got.
First script is tour_manage.php
Second script is delete_tour.php
<script type="text/javascript">
function confirm() {
if(r == true) {
window.location='delete_tour.php;
} else {
window.location='tour_manage.php';
}
}
</script>
<a href="delete_tour.php?tid=<?php echo $tid ?>" onclick="return confirm('Are you sure you want to delete this tour?');" ><img src="images/delete
logo icon.png" width="15" height="15"/></a></td>`
This is the delete_tour.php script
<?php
session_start();
include('../config.php');
$id=$_GET['tid'];
$sql=mysql_query("delete from tour where tid='$id' ");
if($sql)
{
header('location:tour_manage.php');
}
?>
UPDATE
<a onclick="return confirm('Are you sure you want to delete this tour?')" href="delete_tour.php?tid=<?php echo $tid ?>">aaa</a>
Related
How can I make each button instead of going to another page to display the information on a dialog box in the same page.
This code here is in the head to call the id from the other file
<script type="text/javascript">
function getvoucher(id){
return data;
});
}
</script>
Then I have this button in my while loop:
<td><?php echo $row['voucher_id']; ?></td>
<td> <?php echo' Click here'; ?></td>
When I click on the button it displays what I want in test but instead I want it to show in a dialog box, any help?
you can use JQuery's UI dialog which is pretty widely used today. Here is the link for demo:
https://jqueryui.com/dialog/
What you can do is to set the content you want to display in the dialog div's tag and then bind the dialog to the button id.
Example
JAVASCRIPT
$("#voucher_id").click(function() {
$.get("http://52.91.139.19/inactive/test.php?id=" + id, function(data,status){
$("#content").html(data);
});
});
HTML
<div id="dialog" title="Basic dialog">
<p id="content">This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
You should then put Id on button and in script
$("#id").click(function(){
alert("You clicked the button");
});
Did you try with alert something like this echo <script>alert("Message");</script>;
Or did you try to open fancybox you can use for example <a class="className" data-fancybox-type="iframe" href="yourhreftodisplayinfoonfancybox">Open</a>
<script>
$(".className").fancybox({
maxWidth:500,
maxHeight:600,
fitToView:false,
width:'60%',
height:'100%'
}
});</script>`
If you want on button then try with onclick to rised fancybox or dialog I don't do like that
$("#id").click(function() {
$.get("http://inactive/test.php?id=" + id, function(data,status){
$("#content").html(data);
});
});
$(function() {
$("#register").dialog({
autoOpen:false,
show: {
effect:"",
duration: 1000
},
hide: {
effect:"",
duration: 1000
}
});
$("#register-opener").click(function() {
$("#register").dialog("open");
});
});
<td><a id="register-opener" href="?id=<? echo "$members_row[id]"; ?>"><i class="glyphicon glyphicon-pencil" title="Edit"></i></a></td>
So what I'm trying to accomplish is to click on a link to be able to edit a certain users information, the problem is I can only get the popup to occur when replacing the href with href="#". Can someone assist. Thanks.
You need to make some changes in jQuery to achieve this.
$("#register-opener").click(function(e) {
e.preventDefault();
$("#register").dialog("open");
});
Above script will make sure that when ever user clicks on link it doesn't go to URL mentioned in href and execute following codes.
https://api.jquery.com/event.preventdefault/
If e.preventDefault() is called then default action of the
event(click in above case) will not be triggered.
There seems to be problem with dialogue function you have. Use prompt instead and be sure to remove icon inside a tag
jQuery("#register-opener").click(function() {
var person = prompt("Please enter your name", "Harry Potter");
if (person != null) {
document.getElementById("#yourid").innerHTML =
"Hello " + person + "! How are you today?";
//Or do your thing
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<a id="register-opener" href="?id=<?php echo '$members_row[id]'; ?>">
icon<i class="glyphicon glyphicon-pencil" title="Edit">
</i>
</a>
</div>
This might be better accomplished by putting your ID in a data- attribute rather than using href, which is meant to be used for specifying a URL for the web browser to follow.
<td><a id="register-opener" href="#" data-id="<? echo $members_row[id]; ?>"><i class="glyphicon glyphicon-pencil" title="Edit"></i></a></td>
You can then access the value of the data-id attribute in jQuery by using
$("register-opener").attr("data-id");
jQuery Dialogue box is not working properly for dynamic data from database. I want to open dialogue box for multiple data fetched from database. But the problem is that when I click any of the link to open particular dialogue box for particular id of database table record but it opens all the previous id's dialogue boxes also.
For example if I click on id 2 dialogue box it opens 1 and dialogue boxes simultaneously. I want some download in dialogue box also.
jQuery code:
$(document).ready(function() {
$(function() {
$(".dialog").dialog({
autoOpen: false,
maxWidth:600,
maxHeight: 500,
width: 600,
height: 300,
dialogClass: 'main-dialog-class',
modal: true
});
$("a.To").on("click", function() {
$(".dialog").dialog("open");
});
});
PHP code:
<table>
<?php foreach($tList as $ts) : ?>
<div class="dialog" title="Dialog Form">
<?php
$sql1="select * from table where ID='".$ts["ID"]."'" ;
$result1=mysqli_query($link,$sql1);
while($rows=mysqli_fetch_array($result1)){
echo $rows["t1"];
?>
<?php echo $rows['Name'];?><br/>
<?php
}
?>
</div>
<tr>
<td style="display:none">
<?php echo $ts["ID"]; ?>
</td>
<td>
<a href="#" class="To" >
<?php echo $ts["Title"]; ?></a>
</td>
<td>
<?php echo $ts["t1"]; ?>
</td>
<td>
<?php echo $ts["t2"]; ?>
</td>
</tr>
</table>
For starters, your HTML looks like you are nesting the dialog box in a <div> inside the table, but not in a cell (that should be an error in the browser).
But in your javascript, you need a way to specifically identify each dialog box. The error you are reporting makes sense; by choosing $('.dialog'), you are saying "pick every element on the page with a classname "dialog".
I think the easiest way is to change your JavaScript to:
$("a.To").on("click", function() {
$(this).find(".dialog").dialog("open");
});
and then move the dialog box into a cell in each row in your PHP.
Otherwise, you may choose a unique identifier for each dialog box, and rename them to an id, not a class.
EDIT
Yes, you can add the unique id in PHP for the selectors, add the same id in data and then find them with a jQuery selector.
In your PHP:
<td>
<a href="#" class="To" data-dialogfinder='<?php echo $ts["ID"]; ?>'>
<?php echo $ts["Title"]; ?>
</a>
</td>
Then, in you jQuery:
$("a.To").on("click", function() {
var diabox='#'+$(this).data("dialogfinder");
$(diabox).dialog("open");
});
I don't know if that is the full code, but in what you have posted you have missing the endforeach; (to close the foreach() : opened at the beginning).
I have this code inside a while loop for fetching data from the database. I want to show a confirmation popup when the Delete link is clicked.
echo "<td><a href='delete.php?id=" . $row['serial_no'] . "'>Delete</a></td>";
How can this be done?
Try out confirm function from JavaScript, learn jQuery as fast as possible and try to seperate javascript from html ;).
http://www.w3schools.com/jsref/met_win_confirm.asp
<td>
<a href="delete.php?id=<?php echo $row['serial_no'] ?>" id="a_id">
Delete
</a>
</td>
<script type="text/javascript">
$(function() {
$('td a#a_id').click(function() {
return confirm("Are You sure that You want to delete this?");
});
});
</script>
add onClick attribute for anchor link and call the function on it. Or simply show confirm.
<a onClick = "confirm ('Are You Sure?')"
Complete Example
function disp_confirm()
{
var r=confirm("Press a button!")
if (r==true)
{
alert("You pressed OK!")
}
else
{
alert("You pressed Cancel!")
}
}
<a onclick="disp_confirm()"
try this
function DeleteClick(serial_no)
{
if(confirm('Are you sure to delete ' + serial_no + '?'))
{
alert('Data deleted');
return true;
}
return false;
}
echo "<td><a href='delete.php?id=" . $row['serial_no'] . "' onclick="return
DeleteClick(\''. $row['serial_no'].'\')">Delete</a></td>";
echo "<td>Delete</td>";
try this code,hope it will work-
<td>
<a href="#" onclick="conf("delete.php?id=".<?php echo $row['serial_no']; ?>.")">
Delete
</a>
</td>
<script type="text/javascript">
function conf(str) {
if(confirm("Your Message") == true){ location.replace(str);}
}
</script>
and in the delete.php page-just grab the id from url and run the delete query.
In 1stpage I have a table with full of data, and end of every row there is a delete link. When i click on that link, the link goes to another delete page where mysql delete query delete that particular data from database. That delete page redirect with the 1st page (location:1stpage). Now when i want to apply a javascript delete yes/no checking, every time it pops up with "Are you sure?" either i press yes or no the data is deleted from my table. I think the return false cannot working in this case. The code are in below. Please help me what should i do exactly.
Sorry for my bad english.
Thanks in advance.
1st page:
<?php
include "include.php";
?>
<script type="text/javascript">
function show_confirm()
{
var con = confirm("Are You Sure");
if (con ==true)
{
alert("You pressed OK!");
}
else
{
alert("You pressed Cancel!");
}
}
</script>
<table>
<tr>
<td align="center">EDIT OR DELETE DATA</td>
</tr>
<tr>
<td>
<table border="1">
?php
if(isset($_POST['submit']))
{
$order = "UPDATE books SET author='$_POST[author]', title='$_POST[title]', price='$_POST[price]' WHERE isbn='$_POST[isbn]'";
mysql_query($order) or die (mysql_error());
}
$order = "SELECT * FROM books ORDER BY author" or die (mysql_error());
$result = mysql_query($order);
while ($row=mysql_fetch_array($result))
{
echo ("<tr>
<td>$row[isbn]</td>
<td>$row[author]</td>
<td>$row[title]</td>
<td>$row[price]</td>
<td> Edit </td>
<td> <a href=\"delete.php?isbn=$row[isbn]\" onclick='show_confirm()'> Delete </a> </td>
</tr>");
}
?>
</table>
</td>
</tr>
</table>
the page where mysql delete query run :
<?php header("Location: editordeletedata.php"); ?>
<p> <title>delete</title> </p>
<?php
include "include.php";
?>
<?php
if(isset($_GET['isbn']))
{
$order = "DELETE FROM books WHERE isbn = '$_GET[isbn]'";
mysql_query($order) or die (mysql_error());
}
?>
Look at this simple code snippet I wrote, should get you fixed up right.
<html>
<head>
<script type="text/javascript">
function show_confirm() {
return confirm("Are You Sure");
}
</script>
</head>
<body>
<a href="http://www.google.com" onclick='return show_confirm();'> Google </a>
</body>
</html>
Fiddle
I don't see any reason why return false will not work.
function show_confirm()
{
if (confirm("Are You Sure"))
{
alert("You pressed OK!");
}
else
{
alert("You pressed Cancel!");
return false;
}
}
Disable the delete link and move the redirection to the javascript function. The link should look like this:
<a href=\"javascript:void(0)\" onclick='show_confirm($row[isbn])'> Delete </a>
And the javascript function just like this:
function show_confirm(isbn)
{
if (confirm("Are You Sure"))
{
alert("You pressed OK!");
location.replace('delete.php?isbn='+isbn);
}
else
{
alert("You pressed Cancel!");
}
}