Insert records into mysql database without reloading page - mysql

What is the most simple way to insert values into a mysql database without reloading the page? In this particular example, I'd like to have a form with one input field, and when the form is submitted, the user's input to the field is inserted into a mysql database table, but the page is not reloaded.

You can use AJAX to send content to a server side file (without reloading) and that file can insert row(s) in the database. Here's an example : http://www.9lessons.info/2009/08/vote-with-jquery-ajax-and-php.html Here, this guy creates a digg like vote button and it inserts and updates rows without reloading the page. Check it out.

Look at jquery ajax() or the jquery.form() plugin.

This requires AJAX.
You CAN do this with plain JS, but jQuery makes your life a lot easier.
See this post for a good example:
Inserting into MySQL from PHP (jQuery/AJAX)

Related

New MySQL query on each page refresh

I'm trying to to guarantee that fresh JSON is sent to my page every time a user clicks refresh. Currently, if the JSON is updated the webpage will not reflect the change until Apache is restarted.
I have tried the following approaches -
Create a nocache function and call the decorator in the page function
I have tried putting headers in my HTML
Using Command + Shift + R in Chrome for MacOS for a "hard" refresh
No good... I'm beginning to think I'm misunderstanding something. Can someone point out the error of my ways? I copy and pasted the code presented in those links. The first link even speaks about JSON specifically. I can show my exact code being used if desired, but like I said; copy and paste.
Maybe its not even a caching issue, I'm not sure, but I'm open to any ideas!
EDIT:
I know now that my no-cache headers ARE being passed to the HTML. The issue lies somewhere in that the Flask isn't asking MySQL for updated data every time the page is loaded, only when Apache is restarted. So even if fresh data is in MySQL DB it will not be displayed for the user unless Apache gets restarted.
I finally found another post on Stack Overflow regarding my question.
Turns out I need to make my DB connection and form the JSON in the same function. Before I was calling the data from the DB in a separate function and then referencing it to create JSON and pass it to the HTML in a different one. Now everything is inline see HERE.

Save table row to a cookie or html5 storage

What I'm looking to do is have a button on every row of a table that when clicked saves that row to a cookie or HTML5 webstorage (cookies were my initial thought, but it sounds like webstorage might be a better alternative). I'd also like that row to be removed from this table to show that it was selected.
When I or the user is finished selecting different rows, we would then go to a new page that lists all of the data from the cookie or webstorage in a new table.
Tohaku, you idea does not clear where the data is coming, so you will delete/update/save it? but just trying following are suggestions.
If it is coming from database backend server, than simply make table and add button and assign onclick event in javascript with ajax so each row can be deleted from database.
How do you remove that row, simply put class identifier on td column, make java script to remove that td which is deleted. As for saving you don't need as it is already done in your ajax request. So here there is no need to use any web storage.
As question need more explanation, but if in case you must have to use web storage, you should use indexedDB, as webstorage is depreciated and no more being maintain. Another reason is I have also made full app of mobile on web storage but I found that it don't delete columns individual either it can drop whole table but no individual column deletion. IndexedDB also have many issue and support is in only latest versions but safari/ios does not support it so you also need some shiv solutions.
On first run it will retrieve all your data from database, so use javascript function to load on ready stat of page. Now put same two button with javascript so when delete is pressed it will delete row and save is (as no right explanation so will save in another database). IndexDB is nosql database which is based on object, key storing.
How to do it with indexDB read here https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB

ajax upload using iframe

I need an information. If I have a form, used for uploading a file and having it target an Iframe.
I then use Ajax to get the Upload progress. Let say that a simple layout with 2
column only.
The Form being on column 1 and the Iframe on column 2. I want to still be
able to use the column 1.
So while the the upload is still in process. Will I be able to use column 1 to show other page content?
Possibly, using a pre-built solution may solve your needs and provide greater functionality. I know that you can continue using the rest of the page when uploading via Uploadify. You may want to look into this.
Dont things to as everything upload process would have to finish first. You could display info in Collumn 1 prior to starting the Upload process. You wont be able to have any POST backs tho as that will cancel the upload process.
Flash/ASP could be your solution.

Enable viewstate in php and Html

I am trying to make an html form submit data for processing to a php form. This works fine but when the data is validated and there are errors, somehow the data is cleared from the fields. I will like to know if there is a way to maintain the contents of the form controls even if I call the form on the php page that does the validation. I am a student and am new to php so please forgive me if I sound childish. Any elaborate explanation is welcomed. Thanks in advance
if the validations are static use javascript to do so.
but if you are doing things with PHP (getting data from DB and such) I recommend that you pass all the field info thru a get or post to be "RE-FILLED"

Insert SEO friendly dynamic data into HTML without Javascript

I have some static websites. By static I mean all the pages are simple HTML without JavaScript (all the data are hard-coded).
I have a server side program that creates dynamic data that I'd like to insert into my static sites. By dynamic I mean the data changes very often.
How should I do this?
Here is a scenario: On the server side my program generates the current time-stamp in every millisecond. When a user open one of my static sites the page gets the current time-stamp from the server and render it.
I'd like it to work with search engines, so I can't use JavaScript.
It's not possible to change the HTML structure client side without Javascript, so your solution is to add some handler server side for files with .htm and .html extensions.
About JS: Please note that most spiders (if not all) won't be able to see data rendered by javascript since most of them are analyzing the plain HTML that is returned by the server.