user2274703
user2274703

Reputation: 13

Php : Post form does not work

Ok so i'm working in a callcenter and we have a monitor that shows the breaks every caller has taken. I'm new to this company and have gotton the assignment to make a website for this monitor.

below is my php code. I have searched for houres on what might be the problem but i can't seem to find it.

The problem is : if i click the button then my form doesnt get posted and doesnt write to csv. The code has worked before so in the main lines I know my code is correct. It must be something silly and small but I just can't find it.

My code :

<html>
<head>
<LINK REL="StyleSheet" HREF="Input_form.css">
<title>Verander Plaatsindeling</title>
<h1><center>Verander plaatsindeling<center></h1>
<hr/>
</head>
<body>
    <?php
        if(ISSET($_POST['submitMe']))
        {
        $csv = fopen("zitplaatsenAntwerpen.csv","w") or die("Kan csv niet vinden!");

        for($counter=1;$counter<=30;$counter++)
        {
            $naam = $_POST["Naam" .$counter];
            $project = $_POST["Project" .$counter];
            $csvrow = $counter . ";" . $naam . ";" . $project . "\n";
            fwrite($csv, $csvrow);
        }
    ?>
     <?php
            fclose($csv);
            echo "<SCRIPT LANGUAGE='JavaScript'>
            <!--
            window.alert('Gegevens ingeladen!')
            // -->
            </SCRIPT>";
            $informatie = array();
            $f = fopen("ZitplaatsenAntwerpen.csv","r") or die("Kan csv niet vinden!");

            while (!feof($f))
            {
                $arrM = explode(";",fgets($f));
                $informatie[$arrM[0]]["Nummer"] = ucwords($arrM[0]);
                $informatie[$arrM[0]]["Naam"] = ucwords($arrM[1]);
                $informatie[$arrM[0]]["Project"] = ucwords($arrM[2]);
            }
            fclose($f);
        }
        else
        {
            $informatie = array();
            $f = fopen("ZitplaatsenAntwerpen.csv", "r")  or die("Kan csv niet vinden!");

            while (!feof($f))
            {
            $arrM = explode(";",fgets($f));
            $informatie[$arrM[0]]["Nummer"] = ucwords($arrM[0]);
            $informatie[$arrM[0]]["Naam"] = ucwords($arrM[1]);
            $informatie[$arrM[0]]["Project"] = ucwords($arrM[2]);
            }
            fclose($f);
        }
     ?>
     <div style="word-spacing:7em;" align:center>
      Nummer    Naam    Project
     </div>

    <pre><form action="<?php echo $PHP_SELF;?>" method="post">
    <?php
        for ($teller = 1;$teller<=30; $teller++)
        {
                if(!empty($informatie[$teller]))
                {
                    echo "<div align:center>";
                    echo  "     " . $teller . "   ";
                    echo "<input type='text' name='Naam" .$teller. "' value='";
                    echo $informatie[$teller]["Naam"] . "'>";
                    echo "<input id='" .$teller. "' ";
                    echo "<input type='text' name='Project" .$teller. "' value='";
                    echo $informatie[$teller]["Project"] . "'>";
                    echo "</div>";
                }
                else
                {
                    echo "<div align:center>";
                    echo "      " . $teller . "   ";
                    echo "<input type='text' name='Naam" .$teller. "' value='";
                    echo $informatie[$teller]["Naam"] . "'>";
                    echo "<input id='" .$teller. "' ";
                    echo "<input type='text' name='Project" .$teller. "' value='";
                    echo $informatie[$teller]["Project"] . "'>";
                    echo "</div>";
                }
        }
    ?>
    </form></pre>
<div align="center">
<button style="width:100;height:50" type="submit" name="submitMe">Opslaan</button>
</div>
</body>
</html>

Any help would be appreciated. Thank you all in advance

Upvotes: 1

Views: 113

Answers (3)

Flox
Flox

Reputation: 155

This code is wrong,

<button style="width:100;height:50" type="submit" name="submitMe">Opslaan</button>

You should use

<input style="width:100;height:50" type="submit" name="submitMe" value="Opslaan" />

Upvotes: 0

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

Change this PHP

if(ISSET($_POST['submitMe']))

with this:

if(isset($_POST['submitMe']))

You have put your submit button after the closed form try to make something like this:

<input type="submit" style="width:100;height:50"  name="submitMe" value="Opslaan">
</form>

Upvotes: 2

Christian-G
Christian-G

Reputation: 2361

Your submit button is outside of your <form> tag. Look at the source of your page and you will notice it is rendered as:

<form>
....
</form>
<button...>

The button should live inside the form tags as:

<form>
<button ...>
</form>

Upvotes: 1

Related Questions