Hi friend.I m faraz here for the first time. I m new in PHP and doing some basics. I m writing small scripts. I have prolem with $_POST varivle. I wanna get name from the form and print it on the screen. But my script iz not working. Plz check it and help me that whats wrong with it. Thanx
Here is the form code:

<form action="action.php" method="POST">
  <table>
    <tr>
      <td>Name:</td>
      <td><input type="text" name="name" id="name"/></td>
    </tr>
   
    <tr>
      <td colspan="2" align="center">
        <input type="submit" name="Submitbtn" id="Submit_btn" value="Send">
      </td>
    </tr> 
  </table>
</form>

And here is the action script:

<?php echo $_POST['name']; ?>

.Thnax and waiting 4 ur help

first check that in action with echo "hello" that action going on this page...

Try this to see if the $_POST array contains anything

print_r($_POST);

Friends I have checked again as you told me.But I m facing the same peoblem.
My code in all cases shows the same results. When I write something in the form and press submit or send. It shows my whole astion script on the screen. For example if I write this

<?php 
print_r($_POST);
?>

in the action.php file then this whole script appears on the screen.

$name=$_POST('name');
echo $name;

is the standard way, as you can get access to the $_POST array values and then process them eg trim leading/trailing spaces, addslashes, remove html, convert to a date, check for illegal characters, etc, etc from the variable you pass the value to. You shouldn't get into the habit of using $_POST values directly. It's dangerous.

PS name is a reserved word, so it is a bad idea to use it as a variable name - use something different eg fname for first name, theName for enire name or whatever you want. But not name="name".

Since it's printing out your PHP scripts, rather than processing them, it sounds like the issue is with your installation of PHP itself. What are the exact filenames of your form and "action script"?

You may need to modify the configuration for your webserver so that it knows it needs to re-direct PHP files to the interpreter. Do you actually have PHP installed?

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.