BrianM Posted June 7, 2008 Share Posted June 7, 2008 Can this be done -- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" href="setup.css" /> <script type="text/javascript"> function incomplete_field() { alert("You must complete all fields!"); } </script> <title>Setup</title> </head> <?php if (isset($_POST['finish'])) { // basic setup variables $site_name = $_POST['site_name']; $site_url = $_POST['site_url']; $administration_username = $_POST['administration_username']; $administration_password = $_POST['administration_password']; // mysql setup variables $mysql_server_name = $_POST['mysql_server_name']; $mysql_username = $_POST['mysql_username']; $mysql_password = $_POST['mysql_password']; $mysql_database_name = $_POST['mysql_database_name']; $mysql_table_prefix = $_POST['mysql_table_prefix']; if (!$_POST['site_name'] | !$_POST['site_url'] | !$_POST['administration_username'] | !$_POST['administration_password'] | !$_POST['mysql_server_name'] | !$_POST['mysql_username'] | !$_POST['mysql_password'] | !$_POST['mysql_database_name'] | !$_POST['mysql_table_prefix']) { function incomplete_field() } else { $mysql_connect = mysql_connect("$mysql_server_name", "$mysql_username", "$mysql_password") or die(mysql_error()); } } ?> The Javascript is there in the head. I'm wanting to use an alert box when any field is left blank. I get this error: Parse error: parse error, expecting `'{'' in C:\Program Files\Apache Group\Apache2\htdocs\mps\setup\setup.php on line 34 And line 34 is - } else { Quote Link to comment Share on other sites More sharing options...
ILYAS415 Posted June 7, 2008 Share Posted June 7, 2008 try changing... function incomplete_field() to incomplete_field() your trying to create a function in the above one. wat u relally want to do is run an existing function it seems. Quote Link to comment Share on other sites More sharing options...
aseaofflames Posted June 7, 2008 Share Posted June 7, 2008 you can't directly call a javascript function from php. however you could use php to create a body onload event to run the script. example: if (!$_POST['site_name'] || !$_POST['site_url'] || !$_POST['administration_username'] || !$_POST['administration_password'] || !$_POST['mysql_server_name'] || !$_POST['mysql_username'] || !$_POST['mysql_password'] || !$_POST['mysql_database_name'] || !$_POST['mysql_table_prefix']) { echo "<body onload=\"incomplete_field()\">"; //tells the browser to run incomplete_field() when the page loads } else { $mysql_connect = mysql_connect("$mysql_server_name", "$mysql_username", "$mysql_password") or die(mysql_error()); } i changed your | to || (the correct or in php) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 7, 2008 Share Posted June 7, 2008 i changed your | to || (the correct or in php) That's not the correct OR, that's the logical OR. The other one that he had is a bitwise OR. Although you'd be correct in saying that a majority of the time you'd use || or &&, you don't when you actually need to work with bitwise operators. EX: if (imagetypes() & IMG_PNG) { echo "PNG enabled". } Quote Link to comment Share on other sites More sharing options...
aseaofflames Posted June 9, 2008 Share Posted June 9, 2008 That's not the correct OR, that's the logical OR. The other one that he had is a bitwise OR. Although you'd be correct in saying that a majority of the time you'd use || or &&, you don't when you actually need to work with bitwise operators. EX: oh sorry i didn't know that || has always worked fine for me Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.