/    Sign up×
Community /Pin to ProfileBookmark

PHP and JavaScript

Hi,

Is it possible to use PHP within a JavaScript If..Then. I am trying to have a confirm button come up and if the users say yes to the confirm button steps will be carried out if they say no they won’t. This is the code i tired (i got the message a run-time error has occured):-

if (isset($_POST[‘submit’])) {
?>
<script language=”JavaScript”>
var agree=confirm(“Are you sure you want to log out of the inventory system”);
if (agree) {
</SCRIPT>
<?php
if (isset($_
POST[‘UserDelete’]) && (count($_POST[‘UserDelete’] > 0))) {
$a=$_
POST[‘UserDelete’];
$i=0;
foreach ($a as $v) {
$query = “DELETE FROM users WHERE user_id = $a[$i]”;
mysql_query($query) or die (mysql_error());
$query = “DELETE FROM tasks WHERE user_id = $a[$i]”;
mysql_query($query) or die (mysql_error());
$i++;
}
}
}
?>
<SCRIPT>
}
</SCRIPT>

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@AdamGundryDec 17.2003 — No, you cannot use PHP and Javascript together like this. PHP runs on the server-side, before the page has been sent to the web browser, but Javascript runs on the client-side, after it has been sent. Instead, you will need to have the confirm box load a different page, which executes the second part of your PHP code.

Adam
×

Success!

Help @hibbeac1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...