2
I am no longer using extra pages to use functions inside the PHP page. That is PDO use with a php for functions and use everything on the page without loading anything external.
My doubt is how to use ajax in this case.
I want to send a button from a form, but the function is inside the page.
I quote the code.
This is an example to delete data:
Form sent to this snippet
if (isset($_POST['deletepost'])){
if(empty($errors) === true){
$postiddel = $postid;
$users->deletepost($postiddel);
header('Location: home');
exit();
}
}
HTML
<form method="post" name="deleteform" action="">
<input type="text" name="postid" hidden value="<?php echo $postid; ?>">
<li><button type="submit" name="deletepost" class="dropdownbutton">Eliminar publicação</button></li>
</form>
What I need to do, is run php that is inside the same page without refreshing the page.... I do not know if this is possible, but I hope it is, because I am tired of using external pages.
Have you read this question/answer? http://answall.com/a/6634/129
– Sergio
I’ve been looking at most of the posts on stackoverflow, but even this isn’t quite what I’m looking for... Because that’s not quite what I’m looking for, I’m looking for an ajax function that sends the form without loading the page... I’m going to add some inlustrations to help
– user3465632
What I wanted was something like this but without an external page: http://stackoverflow.com/questions/12614167/delete-record-without-refresh-page-using-php
– user3465632
PHP is never "inside the page". It mounts the page, and sends the result to the client. When the client sees the assembled page, PHP has already done its part (at least in the part the client has already received). The most you’ll get is to run the same PHP again, or another mechanism, through a call by the client (either via JS, form sending, or Websockets).
– Bacco