glenelkins Posted August 7, 2006 Share Posted August 7, 2006 HiOk this script is bugging me, its not updating the database as it should[code]// Check if the user has finished creating their profile if ($finished == 0) { ?> <script language="javascript"> if (confirm ('Have You Finished Creating Your Wedding Page?')) { <? $sql = "UPDATE weddings SET finished='1' WHERE user_id=" . $_SESSION['user_id']; $result = mysql_query($sql) or die (mysql_error()); ?> } else { <? $sql = "UPDATE weddings SET finished='0' WHERE user_id=" . $_SESSION['user_id']; $result = mysql_query($sql) or die (mysql_error()); ?> } </script> <? }[/code]ideas? Quote Link to comment https://forums.phpfreaks.com/topic/16781-strange-problem/ Share on other sites More sharing options...
shopies Posted August 7, 2006 Share Posted August 7, 2006 What kind of errors it gives you? Quote Link to comment https://forums.phpfreaks.com/topic/16781-strange-problem/#findComment-70588 Share on other sites More sharing options...
glenelkins Posted August 7, 2006 Author Share Posted August 7, 2006 its not giving an error, its just not updating the value in the database to '1' if the user clicks ok Quote Link to comment https://forums.phpfreaks.com/topic/16781-strange-problem/#findComment-70589 Share on other sites More sharing options...
wildteen88 Posted August 7, 2006 Share Posted August 7, 2006 You cannot use javascript and PHP together during runtime. As the PHP code would of been parsed before the the javascript has a chance. PHP sends the output to browser, you cannot use PHP and javascript simultaniously. However you can if you use AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/16781-strange-problem/#findComment-70592 Share on other sites More sharing options...
glenelkins Posted August 7, 2006 Author Share Posted August 7, 2006 i disagree with you on this one, as it was updating the value and now is not Quote Link to comment https://forums.phpfreaks.com/topic/16781-strange-problem/#findComment-70597 Share on other sites More sharing options...
glenelkins Posted August 7, 2006 Author Share Posted August 7, 2006 ok so if i cannot use a javascript box, I have created my own php form with the same options. Now im no good at javascript so how would i open this window as a popup inside the if statement (code above)? an even such as onClick, i would use onClick="window.open etc etc but inside the If there is no event handler Quote Link to comment https://forums.phpfreaks.com/topic/16781-strange-problem/#findComment-70601 Share on other sites More sharing options...
alecjw Posted August 7, 2006 Share Posted August 7, 2006 What this script is doing is printing: <script language="javascript"> if (confirm ('Have You Finished Creating Your Wedding Page?')) {Then i'ts doing: <? $sql = "UPDATE weddings SET finished='1' WHERE user_id=" . $_SESSION['user_id']; $result = mysql_query($sql) or die (mysql_error()); ?>Then printing: [code]} else {[/code]Then doing: [code]<? $sql = "UPDATE weddings SET finished='0' WHERE user_id=" . $_SESSION['user_id']; $result = mysql_query($sql) or die (mysql_error()); ?>[/code]Then printing:[code] } </script> <? }[/code]Which means that it sends both of the MySQL queries before it prints the page, so itfist sets finished to 1, then to 0, then it prints out the page wheich should look something like this:[code]// Check if the user has finished creating their profile if ($finished == 0) { ?> <script language="javascript"> if (confirm ('Have You Finished Creating Your Wedding Page?')) {} else {} </script> <? }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16781-strange-problem/#findComment-70767 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.