Two functions on one button

Asked

Viewed 96 times

0

I created this answer for a question, it works perfectly, inserts it into the database and everything. I wanted just one thing, when I pressed this button it besides saving in this database,.

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">
  • You can use require("outra_pergunta.php"); after query, it would display the html content of a file called outra_pergunta.php that you had in the same directory as the current script

1 answer

1


As well as you are submitting a form, the redirect should be done by Backend of its application (It is possible to Frontend).

There are 2 ways to redirect. The first is with the use of the method header in PHP.

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

And the second is inserting a Script on 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.

  • I removed the comment about the tag as I already corrected the question.

  • I’ll try really hard thank you

  • Diego, thank you very much, this is for a project at my college that’s going to become my TCC, God willing, and you’re now part of that project with your help. Thank you very much!

  • @Jairoborges, if the answer solved your problem, you can click on V next to the answer to indicate that your problem has been solved.

  • Remember to redirect before sending any data to the page, to send the header sending notices

Browser other questions tagged

You are not signed in. Login or sign up in order to post.