Jump to content

Calling Javascript after PHP check?


galvin

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.