Jump to content

Trouble with quotes


gamesmstr

Recommended Posts

Not sure if this is the right place for this.  It is a mix of JS and PHP but the formatting problem I am having is in the PHP part.  I am using an onclick event to call the following function:

 

<script type="text/javascript">
function movenorth() {
	document.getElementById("outlandsbox").innerHTML = "<?php 
		if ($_SESSION['email']){
			$email=$_SESSION['email'];
			$password=$_SESSION['password'];
		}
		$id=$_SESSION['uid'];
		$uy=$_SESSION['uy'];
		$_SESSION['reload']='y';
		if ($uy > 0){
			mysql_query("Update outland_user_data set uy=uy-1 where id='$id'");
		} 
		OutlandsMain($email, $password);
	?>";
}	
</script>

 

The fuction doesn't work, but the query launches every time the page is loaded.  I know it has to do with my use of quotes.  I also noticed that when I tried this:

 

echo 'test $email $password';

 

it returns this:

 

test $email $password

 

instead of the values of the variables.  help?

Link to comment
https://forums.phpfreaks.com/topic/133221-trouble-with-quotes/
Share on other sites

Use double quotes to display the actual variable data and single quotes to display the literal version of the variable.

 

<?php
$pass = "test";
echo $pass; // = test
echo '$pass'; // = $pass
echo "$pass"; // = test
echo '' . $pass . ''; // = test
echo '{$pass}'; // = test (because of the { } )
?>

 

Hope that clears it up.

Link to comment
https://forums.phpfreaks.com/topic/133221-trouble-with-quotes/#findComment-692862
Share on other sites

Well you asked for an in-depth explanation and that is why. If you want more help I would suggest posting the code for

 

OutlandsMain($email, $password);

 

Because that is what outputs to the JS, not the code above, the issue/error would be in there.

Link to comment
https://forums.phpfreaks.com/topic/133221-trouble-with-quotes/#findComment-692871
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.