Two functions on a button

0

I created this answer to a question, it works perfectly, inserts into the database and everything. I only wanted one thing, when I pressed this button, it saved the database, but also went to another page where you have another question.

if ($_POST['post'] == '3'){

   $db->query("INSERT INTO resp3 (id, tonemai)VALUE  (NULL ,'to nem ai, morra!')");
}

html

<form action="" method="post">
    <input name="post" type="hidden" value="3"/>

    <input type="image" src="7.jpg" onclick="this.form.submit()" id="botao3">
    
asked by anonymous 22.04.2016 / 03:52

1 answer

1

As you are submitting a form, the redirection must be done by the BackEnd of your application. (You can do this by FrontEnd ).

There are 2 ways to do the redirection. The first is using the header method in PHP .

header('Location: http://www.example.com/');

And the second is inserting a Script into your page.

echo "<script>location.href = \"http://www.example.com\"</script>";
  

The first method is more recommended, the second can be said to be a bit of gambiara.

    
22.04.2016 / 04:07