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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.