Jump to content

PHP not printing varible in echo command


cs.punk

Recommended Posts

From the database

game_src

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="550" height="400">
<param name="movie" value="[color=red]$dir[/color]">
<param name="quality" value="high">
<embed src="[color=red]$dir[/color]" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400">
</embed>
</object>

 

PHP:

	<?php
	$sql = "SELECT * FROM games";
	$query = mysqli_query($con, $sql) or die;

	while ($row = mysqli_fetch_assoc($query))
	 {$dir = $row['path'];
	   $game_src = $row['game_src'];
	   echo "<h2>{$row['title']}</h2>
	 			$game_src";
	 }
	?>

 

HTML Source shows:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="550" height="400">
<param name="movie" value="$dir">
<param name="quality" value="high">
<embed src="$dir" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400">
</embed>
</object>

 

Where am i going wrong?

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="550" height="400">
<param name="movie" value="[color=red]<?php echo $dir ?>[/color]">
<param name="quality" value="high">
<embed src="[color=red]$dir[/color]" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400">
</embed>
</object>

maybe?

For a long time (I'm tired) I didn't get the question or the answer!  I'm not sure i do now.

 

If the question is to get $ dir to appear as a variable then it's presumably just a quoting problem unless you have sanitised the database content in a way that makes $dir look like plain text.  Certainly if i mock up your code just by assigning values manually and then escape the quotes it works fine:

 

<?php

$row['title']="fred";	

$dir="./fred/";

$game_src="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"550\" height=\"400\">
<param name=\"movie\" value=\"$dir\">
<param name=\"quality\" value=\"high\">
<embed src=\"$dir\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"550\" height=\"400\">
</embed>
</object>";

echo "<h2>{$row['title']}</h2>
	 			$game_src";

?>

 

As for the answer it seems to me that what you are suggesting is something like this:

echo "stuff to echo <?php echo "more stuff to echo but we're already in an echo"; ?> including php code";

 

Ok I'll try and explain again..

 

Database entry: "You are $x years old"

 

In the actual database there is for example varible $x.

In my php code i set varible $x as 50.

 

I then echo out the database entry.

But instead of saying "You are 50 years old"(which is what i want) Instead it prints a literal  $x "You are $x years old".

 

:) Hope i explained myself better...

Try to narrow this down by commenting out the database bit for now and manually assigning the data to variables before you echo it.  If that then works (obviously there will be just one object) you know it is something to do with the data in the database.  If it doesn't work then maybe look at the quoting.  If you want to attach the whole file I could have a look but the snippet doesn't seem to want to make sense to me for some reason (it's not your code though just my general dumbness!).

I've never heard of the curly brace thing so I'd be interested to know if it works.

 

If not try:

 

str_replace('$dir', $dir, $whateveryourdatafromMySQLwascalled);

 

 

Yeah it worked and guess thats the only option.. Still see it as a waste of resources but oh well.

 

Oh and the {} never worked so..

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.