0
 <?php
    define('upload', 'images/');

    if (isset($_POST['submit'])) {

         $name=$_POST['name'];
         $score=$_POST['score'];
         $screenshoot=$_FILES['screenshoot']['name'];
         $target=upload.$screenshoot;
         move_uploaded_file($_FILES['screenshoot']['tmp_name'], $target);           
         if(!empty($name)&&!empty($score)){
          $dbc=mysqli_connect('localhost','root','57317019','guitar_game');
          $query="INSERT INTO guitargame(id,date,name,score,screenshoot".
          "values(0,NOW(),'$name','$score','$screenshoot')";
          $result= mysqli_query($dbc,$query);

          mysqli_close($dbc);
            }
         else{
            echo "Please fill out all the blanks";
             }

          }

         echo "<p>Thanks for adding your new high score!</p>";
         echo "<p><strong>Name:</strong>"."$name</p>";
         echo "<p><strong>Score:</strong>"."$score</p>";
         echo '<img src="'.$target.'">';
         echo '<p><a href="index.php">Back to high scores</a></p>';
       ?>

l wanna asked what does the img src="'.$target.'" means? Why not use img src="$target" instead? Thanks in advance! I am new to php.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Mr.tang
  • 85
  • 2
  • 7

2 Answers2

-1

The difference between

echo '<img src="'.$target.'">';

and

echo "<img src=\"$target\">";

is that in the former strings are concatenated whereas in the latter the double quotes need to be escaped inside the string to use double quotes which are required to process the variable inside the string. Using just img src="$target" would not work in the echo in either case.

wogsland
  • 9,106
  • 19
  • 57
  • 93
-1

Short answer:

echo '<img src="'.$target.'">';

gives an equal result to

echo "<img src=\"$target\">";

Longer answer: the PHP parser looks inside the "..."-style tags for any variables to replace. It doesn't look inside the '...'-style tags. So the latter is a bit faster. You will only notice a difference when this is inside a loop that is executed hundreds of times.