首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在php中获取输入类型按钮的值

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

Stack Overflow用户
提问于 2014-11-22 21:09:23
回答 3查看 765关注 0票数 0

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

代码语言:javascript
复制
<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>

程序没有看到这一部分;

代码语言:javascript
复制
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>'; }
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-11-22 21:31:31

它不能工作,因为没有提交按钮表单不能被提交:将<button type="button"替换为<button type="submit"

顺便说一下,使用mysqli_而不是mysql_,因为它被废弃了。

票数 1
EN

Stack Overflow用户

发布于 2014-11-22 21:19:11

编辑:更改

代码语言:javascript
复制
  if (isset( $_GET['background'])){ 

代码语言:javascript
复制
 if (isset( $_GET['colour'])){ 

看看会发生什么。

结束编辑。

快速提问..。您的链接中是否定义了“背景”变量?

...page.php?background=1;

如果程序没有看到该部分,那么您需要在这些条件下继续工作,并查看它不满足的条件。不管是..。

( A)链接中没有设置?background=1

( B)没有设置会话CurrentUser

(C) mysql正在返回0行

票数 0
EN

Stack Overflow用户

发布于 2014-11-22 21:33:39

你有没有把背景变量放到页面上。查一次网址。您可以通过使用strlen变量的长度($_GET‘背景’)来调试它。此外,print_r($_GET)将打印页面接收的所有变量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27082588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档