galvin Posted July 28, 2010 Share Posted July 28, 2010 I have a javascript function that shows an alert message, but I only want it to show after a certain check is done by PHP/Mysql first. I can't get it to work, so I'm sure I'm doing something wrong. My code is below. I'm guessing I can't have Javascript inside PHP? If that's true, how would I go about doing something like this? <?php $query = "SELECT paid from users WHERE userid={$_GET['userid']}"; $result = mysql_query($query, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { $paidinfo = mysql_fetch_array($result); if ($paidinfo['paid'] == "no") { ?> <SCRIPT LANGUAGE="JavaScript"> window.onload=deadBeat; </script> <?php } else { //do nothing } } ?> This is the function... <SCRIPT LANGUAGE="JavaScript"> function deadBeat() { alert("You still owe money for your entry fee to this pool. Please pay Gary soon.") } </SCRIPT> Link to comment https://forums.phpfreaks.com/topic/209149-calling-javascript-after-php-check/ Share on other sites More sharing options...
radar Posted July 28, 2010 Share Posted July 28, 2010 just try deadBeat(); you shouldn't need the window.onload in there. Link to comment https://forums.phpfreaks.com/topic/209149-calling-javascript-after-php-check/#findComment-1092295 Share on other sites More sharing options...
galvin Posted July 28, 2010 Author Share Posted July 28, 2010 ALso, should all of this be in between the <head> tags, as in below? It's still not working so probably not haha... <SCRIPT LANGUAGE="JavaScript"> function deadBeat() { alert("You still owe money for your entry fee to this pool. Please pay Gary soon.") } <?php // check to see if they paid so they can get an alert message if they didn't $query = "SELECT paid from users WHERE userid={$_GET['userid']}"; $result = mysql_query($query, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { $paidinfo = mysql_fetch_array($result); if ($paidinfo['paid'] == "no") { ?> deadBeat(); <?php } else { //do nothing } } ?> </SCRIPT> Link to comment https://forums.phpfreaks.com/topic/209149-calling-javascript-after-php-check/#findComment-1092298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.