Jump to content

Trying to make a simple form to send to PHP. PLEASE HELP!


Joefuss

Recommended Posts

I'll admit it upfront: I am a total noob to this, so please bare with me.

I'm trying to create a simple PHP program with an HTML form to submit an input into PHP which then echos back the user's input but I keep getting an "Object not found!" error when I push the submission button on the page. If you could please tell me what I'm doing wrong, I would really appreciate it. My code is:

 

<form action="index.php" method="post">

<input type="text" name="user_input" size="20">

<input type="submit" name="press" value="Press da button!">

</form>

 

<?php

if (isset($_POST['user_input']))

{ $post= $_POST['user_input'];

echo "You posted $post .";

}

?>

 

Again, thanks a ton.

Your code worked fine for me, I changed it a tiny bit.

<form action="" method="post">

<input type="text" name="user_input" size="20">

<input type="submit" name="press" value="Press da button!">

</form>

 

<?php
$user_input = trim($_POST['user_input']);
if (isset($_POST['user_input']) && $user_input != '') {
 
    echo "You posted ".$user_input.".";
    
} else {
    echo "Insert Something";
}

?>

Leaving the action empty will take it to same page as the script is.

Trim removes whitespace, no need for blank values, also added a check for if was blank

QuickOldCar, the variable $user_input should be inside of the if statement, otherwise it will display an error. Providing that errors are set to be displayed, which they should be.

<?PHP
 
  if($_SERVER['REQUEST_METHOD'] == 'POST') {
    $user_input = isset($_POST['user_input']) ? trim($_POST['user_input']) : FALSE ;
 
    if(empty($user_input)) {
      echo 'No user input entered.';
    } else {
      echo 'User Input: '. $user_input;
    }
  }
 
?>

<form action="" method="POST">
  <input type="text" name="user_input" size="20">
  <input type="submit" name="press" value="Press da button!">
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.