How display errors in html without refreshing the form [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
this is the php code im using and want these errors(Echos) to be displayed in the html form without refreshing it after the submit button is clicked
.
THANK YOU
<?php
include 'index.php';
........
if (mysqli_num_rows($num_u) > 0 && mysqli_num_rows($num_e) > 0 ) {
echo "User Already Excist";
}
<html>

Unfortunately, changing page content without refreshing a page isn't possible in PHP. PHP runs when the page loads but once it's finished processing the only way to start the same or a new script is to make a new request. You'll have to use Javascript to execute an ajax request to populate the error.

You need to use JQuery's ajax methods.
They can get data from the server and update your dom on the fly without a page reload.
This is pretty straightforward using Get or Post
JQuery also has some other ajax methods which may be useful as well.
You can check this Create Login Form Using jQuery blog for more details, I hope it's help to you

Related

Submit a form and refresh to the bottom of the page [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
when submitting a form in php i am using: "header('Location: contact.php');" to redirect back to the current page after hitting submit. However the form is at the bottom of the page and each time submit is hit it is redirected back to the top of the page. is there anyway to redirect back to the bottom of the page?
Yes, You can take a id to part of a page you want to return to and then return to it, see following code:
for example you want to return to bellow div:
<div id="bottom"></div>
your php code to redirect to this:
header('Location: contact.php#bottom');
You could check if your page was the pre ious page with window.history and if so, scroll down with window.scroll to.
I really recommend to not to that and use AJAX

PHP Include = AJAX? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I think this will be quite a stupid question, but is the PHP include comparable to AJAX? Because I made a little page in which i load the contents via one index.php in which i have a pages array with every content page. And when I click on a link in the nav it seems to dynamically get the content, rather than reloading the page.
Can someone explain me, where the difference between AJAX and include is? Or is include in fact reloading the page rather than "swapping" contents?
is the PHP include comparable to AJAX
No.
Ajax is the process of making an HTTP request from JavaScript without leaving the current page.
A PHP include just includes some content (and may run some PHP) when the page initially loads.
And when I click on a link in the nav it seems to dynamically get the content, rather than reloading the page.
If that happens, it isn't because of an include.
The most you could get from an include is to load a complete new HTML document which has some content that is identical to the previous HTML document.
If the page loads very quickly then the user might not notice the whole page reloading, but it will still do that.

Is it possible to run a PHP file which doesn't contain any html? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is it possible to run a PHP file which doesnt contain any html?
I have a form, from which I want to submit data to a database. If I were to have the submit buttons action property set to a php file which solely deals with data submission, and then have a redirect on this page to the next visible webpage, would this work?
My reason for asking is I have quite a few different forms, some of which use the same submission code. If I were to have all this on one page and then use conditional logic to determine where the data came from (thus being able to determine what data was submitted and which page to load next) it would make my webpages much more readable, and the submission code much more re-usable.
PHP can take care of all kinds of things behind the scenes. That's the basic meaning of server-side scripting. So yes -- HTML or on-screen presentation are not necessarily in the code everywhere.

How to execute another PHP file? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
My question is: is there a way to execute another php file after HTML form post? I don't want to use header, because i don't want to go to the php page, i only want to execute it.
Clarification:
My i have an addmatch.php, which shows a form where you can add fiels to a table with matches + it shows the table with matches. This PHP page executes the insert.php, which adds data to the SQL database. After adding a field/match, i want to return (i use a header in the insert.php) to the addmatch.php with the updated tabel. So far so good, it works.
But now i my problem: after adding a field, i want to execute another php file. This file, named json.php, is responsible for echoeing json objects of the SQL data. This works. But now my problem is: it only works when i refresh this page after adding a field to the table. But i want to refresh it automatically after adding a field/match on the addmatch.php file WITHOUT open this php file. Is this possible? And how?
Thanks in advance.
if i understand your question .... you may use jquery & ajax . on submit run the ajax code without need to refresh the page .

Ajax for DB Updation [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am updating 100,000 records. So the page looks blank while the update query process runs on the backend. Can someone tell me how to display the text "Please wait blah blah" until the update ends?
Well depending on your script and the structure, the easiest way would be to change a div's css property called display. When a user clicks on a link that starts the php script, you could add a javascript code like :
$(#+THEIDOFYOURDIV).show("slow");
});
and once its done, you can call another js function to close it like :
$(#+THEIDOFYOURDIV).hide("slow");
});
*NOTE I am using jquery functions, so you would need to include jquery in your pages.
There is another way you could do this using php ONLY, I had the same issue so take a look at this: how to show results while a php script is still running

Categories