How to handel php error

I'm using two files one is of html and another is of php In my html file I have created this

code for my html file : index.html

<html>
<body>
<form method='get' action='ans.php'
<input type="text" name="name">
<input type="button" name="submit">
</form>
</body>
</html>

When user enter the input into the input tag it will take the user to the ans.php file in which I have coded some php

My php file: ans.php

<?php

$text= $_GET['name'];
echo $text
?>

Answers


if(isset($_GET['name']))
{
 echo $_GET['name']; 
}
else 
{

}

Use empty() to check if the variable is present and not empty or false. Add a check -

if(!empty($_GET['name'])){
   $text= $_GET['name'];
   echo $text;
}

If the variable may contain false then Hanky 웃 Panky's answer will work.


Need Your Help

ssh forward - bidirectional

ssh forward bidirectional

When using ssh forwarding Im able to commit with cvs and ftp against a remote server. Is it possible to let the server initiate a request against my machine - I would like the web application on the

How to add data to file in javascript?

javascript override using activexobject

I want to make registration form and write the data into data.txt using ActiveXObject.