Jump to content

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

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.