0

I want to trigger a function when I push the button with the name 'toevoegen'. I'm calling the button wit php. When the button is pushed, nothing happens.

My code:

if (isset($_POST['toevoegen']))
{
    echo "hello world";
}

........

<?php
$query = "SELECT * FROM product";

$result = mysqli_query($link, $query) or die("Er is een fout opgetreden bij het uitvoeren van de query: \"$query\"");

$i=0;

echo("<table id=\"product\">");
echo("<tr>");

while($rij = mysqli_fetch_array($result))
{
    $i++;
    $afbeelding = $rij['Img'];
    echo("
            <td><img src=$afbeelding>
            <p>&euro;".$rij['Prijs']."</p>
            <p>".$rij['Naam']."</p>
            <p><form action=\"\">
                <input class=\"nummers\" type=\"number\" name=".$rij['ID']." min=\"1\" max=\"20\">
                <input type=\"submit\" value=\"In mandje\" name= \"toevoegen\">
            </form></p></td>");
    if ($i==3) 
    {
        echo("</tr>");
        echo("<tr>");
        $i=0;
    }

}
echo("</table>");


mysqli_close($link);
}
?>
Manariba
  • 376
  • 6
  • 16

2 Answers2

0

You didn't write what kind of method is used to send form that is why GET is used by default so you can check it

if (isset($_GET['toevoegen']))
{
    echo "hello world";
}

or add method="POST" in form tag as @Epodax suggested in comment. Moreover, the question is if you really needs form there, I think that simple anchor is enough.

Robert
  • 19,800
  • 5
  • 55
  • 85
0

Instead of using too many \ you can use ' when you are using ".

and forms are declared as

 <form method='post' action='yourActionFile.php'>
 //post or get, whatever you want to do
 </form>

You can still define actions on form submission via javascript or jquery.

onsubmit() event is used in javascript.

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78