Jump to content


Photo

Strange problem


  • Please log in to reply
6 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 07 August 2006 - 11:19 AM

Hi

Ok this script is bugging me, its not updating the database as it should

// 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>
		<?
	}

ideas?
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 shopies

shopies
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 07 August 2006 - 11:28 AM

What kind of errors it gives you?

#3 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 07 August 2006 - 11:30 AM

its not giving an error, its just not updating the value in the database to '1' if the user clicks ok
http://thewebsolutionprovider.com - A Solution For Everything Web!

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 August 2006 - 11:41 AM

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.

#5 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 07 August 2006 - 11:53 AM

i disagree with you on this one, as it was updating the value and now is not
http://thewebsolutionprovider.com - A Solution For Everything Web!

#6 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 07 August 2006 - 12:03 PM

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
http://thewebsolutionprovider.com - A Solution For Everything Web!

#7 alecjw

alecjw
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationHatfield, Herts, UK

Posted 07 August 2006 - 04:53 PM

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:
} else {
Then doing:
<?	
				$sql = "UPDATE weddings SET finished='0' WHERE user_id=" . $_SESSION['user_id'];
				$result = mysql_query($sql) or die (mysql_error());
				?>
Then printing:
			}
		</script>
		<?
	}




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:

// 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>
		<?
	}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users