0

I wrote this code but the problem is that when I press the "Change background" button, nothing changes but I should be able to see some part of contents after I pressed it.

<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>

Program doesn't see this part;

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>'; }
8
  • 3
    I do wanna point out that mysql functions depricated Commented Nov 22, 2014 at 21:11
  • @Dorvalla yeah but I need it. That's what my instructor wants me to do it. Commented Nov 22, 2014 at 21:15
  • 1
    You'd better format your code in order to be understandable... The half of it is hidden behind the scroll... Commented Nov 22, 2014 at 21:16
  • @Al.G. that's unnecessary part. It's just a text. Commented Nov 22, 2014 at 21:17
  • Mysql_* fonksiyonlarini birakmalisin. Pdo veya mysqli kullanmalisin. Commented Nov 22, 2014 at 21:21

3 Answers 3

1

It doesn't work because form cannot be submited without submit button: Replace <button type="button" with <button type="submit"

BTW use mysqli_ instead of mysql_ because it is deprecated

Sign up to request clarification or add additional context in comments.

Comments

0

EDIT: Change

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

TO

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

and see what happens.

END EDIT.

Quick question... does your link have the "background" variable defined in it?

...page.php?background=1;

If the program doesn't see that part then you need to work your way up through the conditions and see what condition it isn't meeting. Either...

A) ?background=1 is not set in the link

B) session CurrentUser was not set

C)Your mysql is returning 0 rows

2 Comments

The thing is that when I log in to the database, I see those "Change background", "Change font color", "Change font size" buttons so my session works well the problem is that when I press the "Change background" button after logged on, I can't see the "if (isset( $_GET['background']))" part.
Try the above edit and see what happens. You are setting the link to ?colour but then looking for ?background.
0

Are you getting background variable to the page. Check url once. You can debug it by using the length of variable by strlen($_GET['background']) . Also print_r($_GET) will print all the variables received by the page

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.