0

I am looking for help to a change the colour of a cell in a table. It works if I remove if(isset($_POST['showapp'])){ but I only want it to happen when the button is clicked. Help is very much appreciated.

print '<input name="showapp" type="submit" value="Show Appointments">';
$sqlapp = "SELECT StudentID FROM timetable WHERE Username='{$_SESSION["student"]}'";
$resultapp = mysql_query($sqlapp);
if(isset($_POST['showapp'])){                   
    if (in_array($resultapp, $myarray0)){
        $colour0="yellow";
    }

    if (in_array($resultapp, $myarray1)){
        $colour1="yellow";
    }

    if (in_array($resultapp, $myarray2)){
        $colour2="yellow";
    }

    if (in_array($resultapp, $myarray3)){
        $colour3="yellow";
    }

    if (in_array($resultapp, $myarray4)){
        $colour4="yellow";
    }

    if (in_array($resultapp, $myarray5)){
        $colour5="yellow";
    }

    if (in_array($resultapp, $myarray6)){
        $colour6="yellow";
    }

    if (in_array($resultapp, $myarray7)){
        $colour7="yellow";
    }
}
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • do you receive any errors? – R A Dec 15 '16 at 14:04
  • No the button just does nothing. Like i said if i remove (isset(....)) then the cell light up yellow. – Razold1406 Dec 15 '16 at 14:11
  • All the colours are yellow... also you are setting a different variable each time – Quintin Balsdon Dec 15 '16 at 14:42
  • If you're writing new code, **_please_ don't use the `mysql_*` functions**. They are old and broken, were deprecated in PHP 5.5 (which is so old it no longer even receives security updates), and completely removed in PHP 7. Use [`PDO`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Dec 17 '16 at 14:32

1 Answers1

0

You need to put your input in <form></form> tags. It won't work without it.

<form method="post"> <input name="showapp" type="submit" value="Show Appointments"> </form>

R A
  • 827
  • 13
  • 25