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
https://forums.phpfreaks.com/topic/247854-no-idea-whats-wrong/
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
https://forums.phpfreaks.com/topic/247854-no-idea-whats-wrong/#findComment-1272690
Share on other sites

To be valid markup, the <option> tags need a name= attribute also. Not necessarily saying that's the cause of this problem, but some browsers may choose not to send a value for the <select> field if the <option> tags are missing the name= attributes.

Link to comment
https://forums.phpfreaks.com/topic/247854-no-idea-whats-wrong/#findComment-1272694
Share on other sites

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.