I have made an english to persian dictionary using php and a database,I get the english word from the user and post it to process.php and then in that file I search for the entered word in my database and I return the persian meaning.This works fine but my problem is when the entered word is not in my database the code does not enter the else condition and it does not print the "0 result" statement.I'll be really thankfull if someone could help . so this is my first file :
<html>
<head>
<style>
body {
background-image: url("final.jpg");
}
#par {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin-left:auto;
margin-Right:auto;
position: absolute;
top: 20%;
left:35%;
text-align: center;
background-color:Powderblue;
}
#footer{
margin-top:45%;
background-color:#C7BDBB;
text-align:right;
}
</style>
<title>niloofar-dictionary</title>
</head>
<body>
<div id=par>
<?php
$username="raanaste_niloo1";
$password="Nt13541372";
$dbname="raanaste_niloofar-dictionary";
$usertable="dictionary";
$yourfield = "english";
$yourfield1 = "persian";
//Connect to the database
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname, $connection);
$name = $_POST["word"];
//Setup our query
$query = "SELECT persian FROM $usertable WHERE english='{$_POST["word"]}'";
//Run the Query
$result = mysql_query($query);
//If the query returned results, loop through
// each result
if($name)
{
if($result!=NULL)
{
while($row = mysql_fetch_array($result))
{
$na = $row["$yourfield1"];
echo "word in persian: " . $na;
}}
else {
echo "0 results"
}
}
?>
</div>
<div id="footer">
<h4> COPYRIGHT: © 2017 niloofartarighat. </h4></div>
</body>
</html>
and this is the process.php