Jump to content

Archived

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

glenelkins

Strange problem

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?

Share this post


Link to post
Share on other sites
its not giving an error, its just not updating the value in the database to '1' if the user clicks ok

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
i disagree with you on this one, as it was updating the value and now is not

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.