5
I want to call a PHP function that I have on the same page, on the HTML button.
My PHP function:
if(isset($_POST['insert']))
{
insert();
}
function insert()
{
$requete = "INSERT INTO \"event\" (
title,
start,
end,
description
)
VALUES
(
\"$txttitle\",
\"$txtstart\",
\"$txtend\",
\"$txtdescription\"
)";
$resultat = $base_hndl->exec($requete);
return $resultat;
echo "feito";
}
And the HTML button:
<form method="post" action="insert()">
<input type=submit required name='insert' value=save>
</form>
I’m trying to do this. A new button, and a new form to display the data.
function select($dir, $base){
$base_hndl = new SQLite3($dir.$base);
$requete = "SELECT id, title, start, end, description FROM \"event\" ORDER BY id DESC";
$resultat = $base_hndl->query($requete);
$affiche = $resultat->fetchArray();
echo "<br><label><b>ID: $affiche[id]</b></label><br>";
echo "<label><b>Title: $affiche[title]</b></label><br>";
echo "<label><b>Start: $affiche[start];</b></label><br>";
echo "<label><b>End: $affiche[end]</b></label><br>";
echo "<label><b>Description: $affiche[description]</b></label><br>";
}
if(isset($_POST['mostrar']))
{
select($dir, $base); //affiche évènements
}
And the button
<input type=submit value=Mostrar name='mostrar' >
Why doesn’t it work? It’s because it has two forms?
In that case just leave the
action
of the empty form oraction="#"
– rray
If PHP is in another file you have to do
<form method="post" action="nome_do_ficheiro.php">
, otherwise it is to do as the lost said.– Sergio
That’s right, I’m using some text boxes in that same form, to call in the function, and insert into a db. Just call $txttitle. The input name is txttitle.
– akm
All elements(inputs, radios, selects etc) must be within the tag
<form>
, to redeem the values in php use$_POST['nome_do_input']
. Has noexctract()
thereabout?– rray
Why the Javascript tag and the onClick reference?
– Jorge B.