在php中获取输入类型按钮的值

时间:2014-11-22 21:09:24

标签: php button

我写了这段代码,但问题是,当我按下“更改背景”按钮时,没有任何变化,但是在按下它之后我应该可以看到部分内容。

<form name="change "action="index.php" method="get">
        <center><a href="index.php"><button type="button">REFRESH THE PAGE!!</button></a></center><br/>
        <center><b>WELCOME NOTE!!</b></center><br/>
        <center><textarea readonly="readonly" name="textarea" rows="6" cols="50" style="color:blue; font-size:15pt">Each day holds a surprise. But only if we expect it can we see, hear, or feel it when it comes to us. Let's not be afraid to receive each day's surprise, whether it comes to us as sorrow or as joy It will open a new place in our hearts, a place where we can welcome new friends and celebrate more fully our shared humanity.</textarea></center>
<br/>

<?php

        mysql_connect("localhost","DB","password") or die("ERROR!!");
        mysql_select_db("DB") or die("COULDN'T FIND IT!!") or die("COULDN'T FIND DB"); 


        $sql = mysql_query("SELECT * FROM background");

        $id = 'ID';
        $Blue = 'blue';
        $White = 'white';
        $Silver = 'silver';
        $Red = 'red';
        $text=$_GET['textarea'];

        while($rows = mysql_fetch_assoc($sql)){


            if (isset( $_SESSION['CurrentUser'])){

            echo '<center><button type="button" name="background">Change background</button>';
            echo '<button type="button" name="color">Change font color</button>';
            echo '<button type="button" name="size">Change font size</button></center><br/>'; 

                if (isset( $_GET['background'])){ 
                echo '<span>Choose background color</span><br/>';
                echo '<a href="?colour='.$Blue.'"><img src="red.png"></a>'; 
                echo '<a href="?colour='.$White.'"><img src="white.jpg"></a>'; 
                echo '<a href="?colour='.$Silver.'"><img src="silver.jpg"></a>';
                echo '<a href="?colour='.$Red.'"><img src="red.png"></a>'; }

            }               

    }
    ?>

    </form>


    </td></tr></table>

程序没有看到这一部分;

if (isset( $_GET['background'])){ 
                    echo '<span>Choose background color</span><br/>';
                    echo '<a href="?colour='.$Blue.'"><img src="red.png"></a>'; 
                    echo '<a href="?colour='.$White.'"><img src="white.jpg"></a>'; 
                    echo '<a href="?colour='.$Silver.'"><img src="silver.jpg"></a>';
                    echo '<a href="?colour='.$Red.'"><img src="red.png"></a>'; }

3 个答案:

答案 0 :(得分:1)

它不起作用,因为没有提交按钮就无法提交表单: 将<button type="button"替换为<button type="submit"

BTW使用mysqli_代替mysql_,因为它已被弃用

答案 1 :(得分:0)

编辑: 变化

  if (isset( $_GET['background'])){ 

 if (isset( $_GET['colour'])){ 

看看会发生什么。

结束编辑。

快速提问... 你的链接是否有&#34;背景&#34;在其中定义变量?

... page.php文件背景= 1;

如果程序没有看到那个部分,那么你需要在条件上一路向上,看看它没有达到什么条件。 要么...

A)?背景中没有设置背景= 1

B)会话CurrentUser未设置

C)你的mysql返回0行

答案 2 :(得分:0)

您是否在页面中获得了背景变量。检查网址一次。您可以通过strlen使用变量的长度来调试它($ _ GET ['background'])。 print_r($ _ GET)也会打印页面收到的所有变量

相关问题