I created this simple Php example to begin my study.
This is Index.html:
<!DOCTYPE html>
<html>
<head>
    <title>Prova</title>
</head>
<body>
<form action="script.php" method="get"/>
<table>
    <tr>
        <td>Cognome</td>
        <td><input type="text" name="cognome" id="cognome"/></td>
    </tr>
</table>
<table>
    <tr>
        <td><input type="submit" value="Invia"/></td>
    </tr>
</table>
</form>
</body>
</html>
This is script.php:
<?php
    $cognome = $_REQUEST['cognome'];
    if ($cognome = "Giacomo" )
        {
        echo "<p><img src='Giacomo.jpg'<p>/>";
        }
    else 
        {
        echo "<img src='IMG.jpg'<p>/>";
        }
?>
Its run, but if i write Giacomo show Giacomo.jpg and image.jpg. I want only Giacomo.jpg.
Thanks
You have at least two options:
1) Use the === or == operator
<?php
  $cognome = $_REQUEST['cognome'];
  if ($cognome === "Giacomo")
  {
    echo "<p><img src='Giacomo.jpg'<p>/>";
  } else {
    echo "<img src='IMG.jpg'<p>/>";
  }
?>
2) Use the strcmp function:
<?php
  $cognome = $_REQUEST['cognome'];
  if (strcmp($cognome,"Giacomo") === 0)
  {
    echo "<p><img src='Giacomo.jpg'<p>/>";
  } else {
    echo "<img src='IMG.jpg'<p>/>";
  }
?>
I hope I have helped you in it.
You are assigning $cognome = "Giacomo" in the if statement (which is evaluated to true after that), you should compare with == or === instead:
if ($cognome === "Giacomo")
   echo "<p><img src='Giacomo.jpg'></p>";
else
   echo "<p><img src='IMG.jpg'></p>";
P.S. It should be <p></p> and <img >.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With