Jump to content

No idea whats wrong?


imdead

Recommended Posts

I can't honestly see whats wrong with this code,

it's print'ing correct with the print_r.

Array ( [value1] => 2 [option] => - [value2] => 1 ) 

 

however i can't actually echo out the value1,value2 or option?

It says the vars are empty yet it can still print_r the values so i know there not empty

<?php
if(isset($_POST["submit"])){
$value1=$_POST["value1"];
$value2=$_POST["value2"];
$option=$_POST["option"];
}
print_r($_POST);
echo"$value1";
?>
<form action="index.php" name="submit" method="post">
<input type="text" name="value1">
<select name="option">
  <option>+</option>
  <option>-</option>
  <option>*</option>
  <option>/</option>
</select>
<input type="text" name="value2">
<input type="submit" value="submit">
</form>

Link to comment
Share on other sites

Hmm I don't know why the variable is showing as undefined but you can use the following code and it works. Also remember your <html> & <body> tags :P

 

<?php

if(isset($_POST["submit"])){
        $value1=$_POST["value1"];
        $value2=$_POST["value2"];
        $option=$_POST["option"];
}
echo $_POST['value1'];
?>
<html>
<body>
<form action="test.php" name="submit" method="post">
<input type="text" name="value1">
<select name="option">
  <option>+</option>
    <option>-</option>
      <option>*</option>
        <option>/</option>
        </select>
        <input type="text" name="value2">
        <input type="submit" value="submit">
        </form>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.