2014-09-28 69 views
0

我无法理解为什么这段代码不会保持转换。 应该改变什么?Php切换窗体:逻辑错误?

print_r($_POST); 
$direction = isset($_POST['direction']) ? $_POST['direction'] : 'DESC'; 
$opposite = $direction == 'DESC' ? 'ASC' : 'DESC'; 
echo ' 
    <form method="POST" > 
     <input type="submit" value="' . $opposite . ' " name="direction"> 
    </form> 
'; 
+0

thx一堆戴夫,这是粗糙的! (用光的速度回答) – Webconstructor 2014-09-28 06:05:40

回答

2

罪魁祸首是:

<input type="submit" value="' . $opposite . ' " name="direction"> 
              ^^ 

注意你是如何在值的末尾有一个额外的空间,value="' . $opposite . ' "

尝试将其更改为:

echo ' 
    <form method="POST" > 
     <input type="submit" value="' . $opposite . '" name="direction"> 
    </form> 
'; 
+0

thx一堆戴夫,粗的就是它! (以光速回答) – Webconstructor 2014-09-28 06:11:02