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
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.

Link to comment
Share on other sites

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";

      }

  }

}

 

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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';

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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');
	}
}
}
?>

Link to comment
Share on other sites

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');
}
}

?>

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

Link to comment
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.