Hi,I am a beginner in php. And I am trying to create this php program where a user selects a picture and it displays it! Theare is an input page which is html and an processing page which is php! I seemes to have a problem in the processing page of the program.The problem is on line 22 in the processing page and it relates to escape character. How do I fix my issue please help I alredy spend more the several hours on it and still can't figure it out!

Here are the code for the processing page:
The major problem is on line 5 where it says:
Print "<img src=\ "Photos/$Random\"alt="Smiley face"height="50%" width="50%" border="5" <br/>";
There are issue with escape character and i can't fix it!

<?php
if(isset($_POST['Random']))
{
$Random = rand(0,12)." .jpg";
Print "<img src=\ "Photos/$Random\"
alt="Smiley face"height="50%" width="50%" border="5" <br/>";
}
else
{
if (isset($_POST['Anime']))
{
$Arr=$_POST['Anime'];
displayPhotos($Arr);
}
else 
{
echo "You need to select photo.<br />";
}
function displayPhotos($Arr)
{
foreach ($Arr as $element)
{
print " <br/>";
Switch ($element){
Case 1:
    echo "<img src="Photos/1.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 2:
    echo "<img src="Photos/2.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 3:
    echo "<img src="Photos/3.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 4:
    echo "<img src="Photos/4.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 5:
    echo "<img src="Photos/5.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 6:
    echo "<img src="Photos/6.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 7:
    echo "<img src="Photos/7.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 8:
    echo "<img src="Photos/8.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 9:
    echo "<img src="Photos/9.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 10:
    echo "<img src="Photos/10.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 11:
    echo "<img src="Photos/11.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
Case 12:
    echo "<img src="Photos/12.jpg" alt="Smiley face" 
    height="50%" width="50%" border="5" <br/>";
    break;
    }
  }

}   

}

?><
  • Can someone also look at the rest of the code and tell me whats wrong and fix it for me Thank You!

Here is the input page incase anyone needs to lok at to solve the processing page codes:

<i>Please click any checkboxes to select a photo!</i>
<script type="text/javascript" language="javascript">// <![CDATA[
function checkAll(formName, checktoggle)
{
  var checkboxes = new Array();
  checkboxes = document[formName].getElementsByTagName('input');

  for (var i=0; i<checkboxes.length; i++)  {
    if (checkboxes[i].type == 'checkbox')   {
      checkboxes[i].checked = checktoggle;
    }
  }
}
// ]]></script>

<fieldset>
<a onclick="javascript:checkAll('getIt', true);" 
href="javascript:void();">check all</a>
<a onclick="javascript:checkAll('getIt', false);" 
href="javascript:void();">uncheck all</a><br/>
<form  action="Process_Page of the Project.php" method="post" name="getIt">
<input type="checkbox" name="Anime[]" value="1" />Code Geass Lelouch Of The Rebellion<br/>
<input type="checkbox" name="Anime[]" value="2" />Death Note<br/>
<input type="checkbox" name="Anime[]" value="3" />A Certain Magical Index<br/>
<input type="checkbox" name="Anime[]" value="4" />Kaze No Stigma<br/>
<input type="checkbox" name="Anime[]" value="5" />One Piece<br/>
<input type="checkbox" name="Anime[]" value="6" />Trigun<br/>
<input type="checkbox" name="Anime[]" value="7" />Tengen Toppa Gurren Lagann<br/>
<input type="checkbox" name="Anime[]" value="8" />Prince Of Tennis<br/>
<input type="checkbox" name="Anime[]" value="9" />Fairy Tail<br/>
<input type="checkbox" name="Anime[]" value="10" />Katekyo Hitman Reborn<br/>
<input type="checkbox" name="Anime[]" value="11" />Bleach<br/>
<input type="checkbox" name="Anime[]" value="12" />Silver Spoon(Gin no Saji)<br/><br/>


<input type="submit" name="formSubmit" value="Submit Choices" />  
</form>
</fieldset>
<br/>
<fieldset>

<form action="Process_Page of the Project.php" method="post">
You can also click the Random button to view a random photo.<br/><br/>
<button name="Random" type="submit" value="R"> Randomize Me!</button>
</form>
</fieldset>

</p>
</body>
</html>

Please debug and tell me how you did it with comments! Thank You!

your escape character isn't working as there is a speace between the \ and the " so it's not escaping the ". You also missed the closing > for your image tag before the br in all your echo statements.

On all of your echo statements (I also suggest using echo vice Print) in your code for img tags you're enclosing your properties with " which is going to end your echo tag and cause an error. You have to be careful when echo'ing HTML that you don't mix quotes up. The best course of action for your scenario would be to not use escapes anduse single quotes inside your img tags instead of the double like so:

5. echo "<img src='Photos/$Random' alt='Smiley face' height='50%' width='50%' border='5'> <br/>';

Give that a try hopefully it helps you out. If you're still having issues, post your new code and I'll take a look again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.