Jump to content

[SOLVED] Is this coded correctly?


datalee100

Recommended Posts

I host an online trading card game that has their members play games for cards that they can trade and earn rewards from.  Recently, I found a tutorial at my personal site's host for a slot game that you play and if the three pictures match up, the prizes appear.  Once coded, I uploaded this page to my server and I got the error of: 

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/unspoke/public_html/darkfutures/slots.php on line 32

 

With the coding in question being:

 

<?php

if ($one==$two) {
   if ($two==$three) {
   echo " <?php 
echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";
echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";
echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";
?> ">\n";
      if ($one=="images/slots/04.GIF") {
      echo " <?php 
echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";
echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";
echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";
?>  ">\n";
      }
   }
}

?>

 

But when it's coded like this:

 

<?php

if ($one==$two) {
   if ($two==$three) {
   echo " <?php include('rand-cards.php')?> \n";
      if ($one=="images/slots/04.GIF") {
      echo " <?php include('rand-cards.php')?>  \n";
      }
   }
}

?>

 

There's no error, but nothing shows up when the prizes are supposed to show up.  That include works on every other normal page and shows a card, while the other code that it took the place of from the first to the second.  Is another randomizer script that runs the slots.  My question is:  Did I do something wrong with my coding and is it possible to use both codes in the echo to achieve the result that I would like?

Link to comment
https://forums.phpfreaks.com/topic/59535-solved-is-this-coded-correctly/
Share on other sites

As stated by another poster above me, you don't need to use echo multiple times here. If you do something like..

 

<?php

  echo'
  <img src="'.$img_1.' border="0"><br />
  <img src="'.$img_2.' border="0"><br />
  <img src="'.$img_3.' border="0"><br />';

?>

 

Should work fine.

And yeah...looks odd...the way you went about your coding method.....and look at the bolded red text....

 

if ($one==$two) {

  if ($two==$three) {

  echo " <?php

echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";

echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";

echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";

?> ">\n";

      if ($one=="images/slots/04.GIF") {

      echo " <?php

echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";

echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";

echo "<img src=" . $special[array_rand($special,1)] . $digits2[array_rand($digits2,1)] . ">\n";

?>  ">\n";

      }

  }

}

 

?>

So I should get rid of the php code endings and get rid of the multiple echos and it should work?  What about the include?  Is there a better way to do that as well?

 

[EDIT] Doing the above steps got me this:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ']' in /home/unspoke/public_html/darkfutures/slots.php on line 31

Well, for one, you don't need to close and open php tags all over the place and you can echo/print HTML within the PHP....

 

<?php

  if($a == $b) {
    echo'somethingthing here<br />';
  }

    else {
      echo'something else<br />';
   }

  $variable = 'myvalue';
  $variabletwo = 'othervalue';

?>

So for this:

 

<?php

if ($one==$two) {
   if ($two==$three) {
   echo " <?php include('rand-cards.php')?> \n";
      if ($one=="images/slots/04.GIF") {
      echo " <?php include('rand-cards.php')?>  \n";
      }
   }
}

?>[/

 

If I coded it as:

 

<?php

if ($one==$two) {
   if ($two==$three) {
   echo " include('rand-cards.php') \n";
      if ($one=="images/slots/04.GIF") {
      echo " include('rand-cards.php')  \n";
      }
   }
}

?>

 

It would work?

There is no need to echo/print out the include.  Doing that will do exactly that.  It will output what ever is in parenthesis as text.

 

<?php

if ($one == $two)
{
if ($two == $three)
{
	include('rand-cards.php');

	if ($one=="images/slots/04.GIF")
	{
		include('rand-cards.php');
	}
}
}
?>

You can combine the two if statements.  Also, why are you echoing an include statement?

 

<?php

if ($one == $two && $two == $three) {
echo "All three cards matched!!";
include('rand-cards.php');

if ($one == "images/slots/04.GIF") {
	echo "Card one was 04.GIF";
	include('rand-cards.php');
}
}

?>

Yeah...  I wasn't too sure about whether or not an echo would produce the extent of the include...  I'm not good using the echoes...  So, what you're saying with combining them...  I'm going to go and try that one.

 

Thanks about the include out of echo stuff!

To change the order of viewing the include and the echo, I switched the places of them in the coding and now I get:

 

Parse error: syntax error, unexpected T_ECHO in /home/unspoke/public_html/darkfutures/slots.php on line 31

 

Should I leave them a certain way?

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.