PDA

View Full Version : merging javascript with php


duniyadnd
10-27-2002, 07:59 AM
The problem lies in the fact that I click on a link and its a javascript function call "confirm" If user accepts, function goes to a particular page, if its false, it stays on the same page.

The problem lies in where if the user accepts, I have to keep an ID from the Php on the page, but don't know how to merge it in with javascript when I'm calling it to the new page, hope all this makes sense. This is the stripped down script:

**********


//this is where we click to get the confirm call
<a href="javascript:confirmDel();">Delete Entry</a>



//this is the function call specifically
<script language="JavaScript" type="text/javascript">
<!--
function confirmDel()
{
if(confirm("Are you sure you want to delete this entry?"))
{ clubDelete.phtml?clubID=$clubID"; }
else
{ alert('Confirming you are not deleting the entry'); }
}
//-->
</script>



//this is the query code for the page where the error is apparently coming from
$query = "DELETE FROM club" .
"WHERE clubID = '$clubID' ";


The error I'm specifically getting is: You have an error in your SQL syntax near 'clubID = $clubID' ' at line 1

If anyone knows how I can get the $clubID value over to the next page, would greatly appreciate it.

Thanks
Duniyadnd

Ökii
10-27-2002, 12:38 PM
Are you echoing out the entire javascript?

You stripped too much of the coding for the page transition btw - anyway....

if(confirm("Are you sure you want to delete this entry?"))
{
document.location.replace("clubDelete.phtml?clubID=<?php echo $clubID; ?>"); }

...should get you on track

mordred
10-27-2002, 02:10 PM
//this is the query code for the page where the error is apparently coming from
$query = "DELETE FROM club" .
"WHERE clubID = '$clubID' ";


This query is invalid. If you print it, it would look like this:

DELETE FROM clubWHERE clubID = '123'

All you need is a blank space or new line between club and WHERE, so the MySQL parser can interpret your query correctly. So


$query = "DELETE FROM club " .
"WHERE clubID = '$clubID' ";


should work.

duniyadnd
10-27-2002, 03:30 PM
Thanks, that was why I was getting the error, and that's why I probably didn't think my original attempts of doing what
Ökii said was working.

Thanks to both of you.
Duniyadnd

Ökii
10-27-2002, 03:52 PM
well spotted mordred :) 'specially for a Sunday.