...

View Full Version : Are you sure you want to delete? Not working



Eggweezer
02-03-2013, 08:56 PM
I have a link that will delete an entry in my database table, but I would like a pop up that will ask if you "Are you sure". My code does not work, and I was wondering if someone could help me.
My existing code that works:


echo '<td><a href="delete_job.php?id=' . $row['ID'] . ' ">Delete</a></td>';

Now my new attempt that does not work:


echo '<td><a href="delete_job.php?id=' . $row['ID'] . ' " onclick="return confirm('Are you sure you want to delete?')">Delete</a></td>';

Thank you very much in advance.

BubikolRamios
02-04-2013, 12:44 AM
It will not work using href. Since you are using javascript already,


Look for 'location javascript' on google

Eggweezer
02-08-2013, 03:57 AM
Thanks for getting back. I will have to look into that. Thanks again.

Old Pedant
02-08-2013, 07:10 AM
Now my new attempt that does not work:


echo '<td><a href="delete_job.php?id=' . $row['ID'] . ' " onclick="return confirm('Are you sure you want to delete?')">Delete</a></td>';



I think Bubikol is totally wrong. That should work just fine.

Bring up the page in your browser.
Click on the browser's VIEW menu.
Click on the SOURCE or PAGE SOURCE menu item.
Find that line in the HTML and copy/paste the HTML here.

salesmachine
02-08-2013, 07:55 AM
you can generate the pop up using javascript functionality..

JefferyJamison
02-09-2013, 09:52 AM
HI ! Old Pedant you are write. it works.

Eggweezer
02-09-2013, 06:43 PM
Hello all.
I hate to sound ignorant, but I get an error with that line of code.
This is the error that I get:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /homepages/41/d383225633/htdocs/test38/admin/view_jobs.php on line 58

BubikolRamios
02-09-2013, 08:21 PM
I think Bubikol is totally wrong.

Hmm, realy, I tested it on FF and GC and there it works, on IE8 does not work as expected, whatewer you click it goes to href.

Anyway I don't know how java script can affect/connect to href value.
Does not look logical to me.

Eggweezer
02-09-2013, 09:28 PM
Thanks BubikolRamios.
Yeah, I don't even get it to work in Chrome.
When I upload the file and view the page, it just displays that syntax error.

BubikolRamios
02-10-2013, 02:15 AM
Try this, id does not actualy delete anything, it demonstrates linking upon confirmation.

The bottom link should work on all browsers, while upper does not work on IE 8.




<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<a href="https://www.google.si/" onclick="return confirm('Are you sure you want to delete?')">Delete href</a>
<br />
<a href ="#" onclick="if (confirm('Are you sure you want to delete?')) {window.location.href = 'https://www.google.si/';}">Delete javascript</a>

</body>
</html>






Otherwise your error looks like from PHP.
It has nothing to do with .....

When your PHP will be error free, then you wil still have to look at html page source (and that should look something like my upper code.)

I doubt you can look at PHP generated html source as old pedant suggested, at this stage, coz I asume it is nothin there, due to error.

EDIT: Not PHP man myself, but if you look here: http://php.net/manual/en/language.operators.string.php

all strings are inside "" not inside '' like in your case ..... There might be your problem.

Eggweezer
02-10-2013, 09:32 PM
Thanks BubikolRamios.

Your code did work when it was the only thing on my page, BUT.... did not work when I tried to incorporate it within my code(hyperlink).I just got a syntax error.

If you (or anyone) wouldn't mind, you can the actual domain at http://clearcreekhoney.com
That way you could actually edit it. I know it is a hassle for you, but I am getting frustrated, and am trying to cross (understand) this hurdle.

The ftp info is:
Username: u65618807-CLRcreek
Password: !clear23

My delete does work, BUT not with the "warning" popup.
Thank you. Sincerely, Eggweezer

Old Pedant
02-11-2013, 08:11 PM
Hello all.
I hate to sound ignorant, but I get an error with that line of code.
This is the error that I get:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /homepages/41/d383225633/htdocs/test38/admin/view_jobs.php on line 58
That is a PHP error. It has nothing whatsoever to do with whatever browser you are using.

PHP code happens *BEFORE* the browser ever *SEES* the code, at all.

If you don't show the PHP code where that error is nobody can help you.

HINT: Any error message that includes T_xxxx is a PHP error. Unless you actually had a variable or function name that started with T_ there is no standard JavaScript error that would look like that.

Eggweezer
02-12-2013, 12:09 AM
Here is my code that DOES NOT give an error, and correctly goes to the hyperlink.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>
<?php
require ('mylogin.php');
$db = connectDB();

$result = mysql_query("SELECT * FROM customers order by crm ASC")
or die(mysql_error());

?>
<table border='1' cellpadding='10'>
<tr><th>Last Name</th><th>First Name</th></tr>

<?php
$count= 0;
while($row = mysql_fetch_array( $result )) {
++$count;

echo "<tr>";
echo '<td width="100">' . $row['nameLast'] . '</td>';
echo '<td width="100">' . $row['nameFirst'] . '</td>';
echo '<td><a href="delete.php?id=' . $row['ID'] . ' ">Delete</a></td>';
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>


Here is my code with only the "Delete" line modified (which DOES give the PHP error).


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>
<?php
require ('mylogin.php');
$db = connectDB();

$result = mysql_query("SELECT * FROM customers order by crm ASC")
or die(mysql_error());

?>
<table border='1' cellpadding='10'>
<tr><th>Last Name</th><th>First Name</th></tr>

<?php
$count= 0;
while($row = mysql_fetch_array( $result )) {
++$count;

echo "<tr>";
echo '<td width="100">' . $row['nameLast'] . '</td>';
echo '<td width="100">' . $row['nameFirst'] . '</td>';

echo '<td><a href="delete_job.php?id=' . $row['ID'] . ' " onclick="return confirm('Are you sure you want to delete?')">Delete</a></td>';

echo "</tr>";
}
echo "</table>";
?>
</body>
</html>

If anyone can figure this out, I would greatly appreciate it. Sincerely

BubikolRamios
02-12-2013, 12:56 AM
just a note, are you sure you need space there (marked with underline):

$row['ID'] . '_" onclick

Eggweezer
02-12-2013, 01:20 AM
I just removed the space to no avail.

If it helps, you can see it at www.clearcreekhoney.com

If it is easier for you, you can download the index.php file and play with it (of course, unless it is a hassle)

The ftp login is:
Username: u65618807-CLRcreek
Password: !clear23

Thank you.

BubikolRamios
02-12-2013, 02:08 AM
It is a hassle (-: I'm java user myself, as I think, Old Pedant too. So, no PHP here.

I would suggest to do, split problem to smaller chunks, and see on which line it dies.: ....
But again, I'm mostly guessing PHP:




$tmpStr = '<td><a href="delete_job.php?id=';
$tmpStr = $tmpStr . $row['ID'];
$tmpStr = $tmpStr . '"';
.....

and if it does not die here somewhere , it will on echo command,
then you will have $tmpStr, to see what is in it (catch it on server side....)

Eggweezer
02-12-2013, 02:10 AM
Thanks BubikolRamios,
I will try that. I appreciate your direction.

BubikolRamios
02-12-2013, 02:16 AM
Try allso replacing:
('Are you sure you want to delete?')
with
(\'Are you sure you want to delete?\')

the \ is java escape character thing, but might be also suitable for PHP

Eggweezer
02-12-2013, 02:32 AM
SOLVED!
Works perfect! Thank you very much for all of your time!
I really do appreciate it. I will be using that a lot. Awesome! :thumbsup:

Eggweezer
02-24-2013, 05:08 PM
And when I say "Solved", I mean solved by BubikolRamios.

Yes, it was fixed by adding the forward slashes to ignore the special charactors. Ex....... (\'Are you sure you want to delete?\')

Just wanted to make it clear that I did not solve it!
Thanks again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum