Jump to content

Strange problem


glenelkins

Recommended Posts

Hi

Ok 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?
Link to comment
https://forums.phpfreaks.com/topic/16781-strange-problem/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/16781-strange-problem/#findComment-70592
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/16781-strange-problem/#findComment-70601
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/16781-strange-problem/#findComment-70767
Share on other sites

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.