Author Topic: PHP not printing varible in echo command  (Read 508 times)

0 Members and 1 Guest are viewing this topic.

Offline cs.punkTopic starter

  • Enthusiast
  • Posts: 406
  • Gender: Male
  • Uhm er well...
    • View Profile
PHP not printing varible in echo command
« on: March 13, 2010, 01:09:16 AM »
From the database
game_src
Code: [Select]
<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:
Code: [Select]
<?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:
Code: [Select]
<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?
Life isn't just simply being alive... Or is it?

Offline Rustywolf

  • Enthusiast
  • Posts: 72
    • View Profile
Re: PHP not printing varible in echo command
« Reply #1 on: March 13, 2010, 01:47:33 AM »
<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?

Offline DaiLaughing

  • Enthusiast
  • Posts: 111
    • View Profile
    • Learn HTML, XHTML, CSS, Javascript, PHP and MySQL - Your Web Skills
Re: PHP not printing varible in echo command
« Reply #2 on: March 13, 2010, 02:55:55 AM »
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";

Offline cs.punkTopic starter

  • Enthusiast
  • Posts: 406
  • Gender: Male
  • Uhm er well...
    • View Profile
Re: PHP not printing varible in echo command
« Reply #3 on: March 14, 2010, 03:02:55 AM »
Ok I'll try and explain again..

Code: [Select]
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...
Life isn't just simply being alive... Or is it?

Offline DaiLaughing

  • Enthusiast
  • Posts: 111
    • View Profile
    • Learn HTML, XHTML, CSS, Javascript, PHP and MySQL - Your Web Skills
Re: PHP not printing varible in echo command
« Reply #4 on: March 14, 2010, 03:40:49 AM »
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!).

Offline cs.punkTopic starter

  • Enthusiast
  • Posts: 406
  • Gender: Male
  • Uhm er well...
    • View Profile
Re: PHP not printing varible in echo command
« Reply #5 on: March 14, 2010, 07:39:36 AM »
It is the database! Almost as if its escaped... But in the HTML source (in a browser) its shows $dir..

So php isn't really er... whats the word? *word*.. its just echoing the actual entry..

Preg replace perhaps?..
Life isn't just simply being alive... Or is it?

Offline Instigate

  • Irregular
  • Posts: 10
    • View Profile
Re: PHP not printing varible in echo command
« Reply #6 on: March 14, 2010, 07:58:45 AM »
Just do this:

Try putting Moustaches ( { } ) around your variables inside a variable.

Offline DaiLaughing

  • Enthusiast
  • Posts: 111
    • View Profile
    • Learn HTML, XHTML, CSS, Javascript, PHP and MySQL - Your Web Skills
Re: PHP not printing varible in echo command
« Reply #7 on: March 14, 2010, 08:51:58 AM »
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);

Offline cs.punkTopic starter

  • Enthusiast
  • Posts: 406
  • Gender: Male
  • Uhm er well...
    • View Profile
Re: PHP not printing varible in echo command
« Reply #8 on: March 16, 2010, 05:55:08 AM »
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..
Life isn't just simply being alive... Or is it?