Does anyone know of a Javascript + MySQL script that will allow me to dynamically request mysql information through javascript instead of having to make a seperate php file for each individual Ajax request i have?
I ask since I made a dynamic script that will insert MySQL info, and was curious if there was already one out there that can request it.
I hear that this idea could cause a security problem. Any ideas how to still make this possible? I have many AJAX requests and I don't want to make tens if not hundreds small PHP scripts for this...
Thanks!
I found the answer! By using hashes. I can simply add an md5 to the ajax (the md5 will contain the string info + some random code, this will be created using a php script). Then the script that actually inserts or requests the info from the database (php) will attempt to create the same md5 hash. If it is successfull, it is legit, if not, then stop the database request or post.
http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=391
Related
I'm trying to import the excel data to mysql database by PHP Ajax method. When the user upload an excel, the jQuery will fetch each row by loop and send it to PHP via ajax but there are about 500++ rows. Due to that, the PHP is running the query simultaneously and causing the database error already has more than 'max_user_connections' active connections. Some of the query are working but some not.
the jQuery will fetch each row by loop and send it to PHP via ajax
...this is a design flaw. If you try to generate 500 AJAX requests in a short space of time it's inevitable, due to its asynchronous nature, that a lot of them will overlap and overload the server and database...but I think you've realised that already, from your description.
So you didn't really ask a question, but are you just looking for alternative implementation options?
It would make more sense to either
just upload the whole file as-is and let the server-side code process it.
Or
If you must read it on the client-side, you should at least send all the rows in one AJAX request (e.g. as a JSON array or something).
I have PHP up to 5.4, Perl 5.8, C and Python available server-side.
So basically I have JavaScript client-side and I'm generating a string. I'd like to save this string server-side.
I know how to load a string from a file in the server with XMLHttpRequest. But I don't like the idea to use a file for just storing a string even if it's a big one.
So what I'm looking is an example from a string which goes from Javascript to PHP (or something available for me) and back from PHP to JavaScript.
If it does not involved MySQL it is better (I just want to save a string).
I have nothing about jQUERY but I'm not planning to look into it right now.
EDIT 1 : To precise what I need, the user will connect to the website play with the JS application and in the middle save some simple stuff (the string). I want that afterward when he'll come back (or another user) to the website he can get his stuff back.
EDIT 2 : since it cannot be done as nnnnnn says in the comment. I changed the question to :
I'd like to save a string during the use of a JS application and restore it for the next user.
EDIT 3 : I'm looking for a simple example for saving the string in a file, as no other solution is feasible.
If I understand correctly:
send needed to server and save it to some temporary place (file, db, whatever)
next load, ask via ajax if there is any change or data saved
if so, load them
if data are javascript sode, you can use eval() code
Another, quite dirty solution is use cookie data
You cannot expect that supported features in new browsers are supported in old ones as well - savind localy is not possible.
As per my understanding, you want to share data between user. So that, you are sending information to the server and server is responsible to give the same data later. And you dont want to use file as well as database. Session is not suitable to keep large data.
Then,
An alternate solution is store your data in Memcache server. This is more suitable in your case. But you have to remember one thing about Memcache, That is, Memcache is not persistent storage. But you can increase Memcache flushing interval as much as you want.
Note: Memcache is RAM consuming process.
Alright, so I've looked at a ton of questions, but I only found 1 that resembled what I am trying to do. Here is the link to it: Passing POST data from one web page to another with PHP
I want to pass data from one PHP file(we'll call it editData.php) to another PHP file(we'll call it submitData.php). Neither file has any HTML elements (pure PHP code I mean). The first file(editData.php) receives $_POST data, edits it, and needs to send it to the second file. The second file(submitData.php) needs to be able to read in the data using $_POST. No sessions nor cookies can be used I'm afraid.
In the linked question above, the answer accepted was to create hidden fields inside a form and POST the data from there. This worked for the OP because he had user interaction on his "editData.php", so when the user wanted to go to "submitData.php", he would POST the data then.
I can't use this solution(at least, I don't think I can), because I am accessing (and sending $_POST data to) editData.php from a javascript AJAX call and there will be no user interaction on this page. I need the modified data to be POSTed by code, or some other way that does the transfer 'automatically'(or 'behinid-the-scenes' or whatever you want to call it). submitData.php will be called right after editData.php.
I don't know if I can rewrite submitData.php to accept GET data, so count that out as well (it's a matter of being able to access the file). I really don't want to echo stuff back to my original JavaScript function(and then AJAX again). I am encrypting info in editData.php, and (while it sounds silly to say it) I don't want to make it easy for someone to develop a cipher for my encryption. Returning values after being encrypted(viewable with Inspect Element) would make it too easy to decipher if you ask me.
I feel like this issue could come up a lot, so I'd expect that there is something obvious I'm missing. If so, please tell me.
tl;dr? How can I send data to a PHP file via the POST method while only using code in another PHP file?
Well you might consider just streamlining your approach and including the submitData logic at the end of the editData file. But assuming that this is not possible for some reason (files live on different systems, or whatver), your best bet might be to use cURL functionality to post the data to the second script.
If the files are on the same server though I would highly recommend not posting the data to the second script as this will basically just double the amount of requests your web server needs to handle related to this script.
how we can update mysql detabase by using ajax...
any help or consept..
Ajax will have to call a remote script which will have to take care of the databse interaction. The code depends on the script language your database handling script will be written in.
You may have a look here for an example of ajax and mysql interaction.
You need to call a url from javascript, and do the job serverside.
We cannot update mysql database by using ajax!
Thus, divide your task into 2 parts:
make ordinal php script that updates a database by usual POST request.
debug it and make it to work
make AXAX code to make such a request.
debug it and make it to work
this way you can get your application working
I'm searching on how to do this but my searches aren't turning up things that are talking about what I'm trying to do so maybe I'm not searching with the right terms or this isn't possible, but figured I would ask here for help.. this is what I am trying to do..
I have PHP scripts that are called asyncrhonously, so it is called and it just runs, the calling PHP doesn't wait for a response, so it can go on to do other stuff / free things up so another asynch php process can be run.
I would still like to get back a result from these "zombie" scripts or whatever you want to call them, however the only way I can think of doing it that I know for sure will work is something like make this "zombie" script save its final output to a database and then have my AJAX UI make periodic requests to this database to check if the needed value exists in the place it is supposed to.. which would allow it to get the output from the zombie PHP script..
I am thinking it would be better if somehow this zombie script could do a sort of page refresh to the AJAX ui but the ajax ui would intercept this and just take the received data from PHP and use it as needed (such as display in a DIV for user to see).. basically I'm wondering if you can make PHP force this kind of thing rather than needing to involve a database in this and making AJAX do repeated requests to check for a specific value that way..
Thanks for any advice
No, a background script has no way to influence the client's front-end because it has no connection to it.
Starting a background script, having the script write status data into a shared space - be it a database or a memcache or a similar solution - and polling the status through Ajax is usually indeed the best way to go.
One alternative may be Comet. It's a technique where a connection is kept open over a long time, and updated actively from the server side (instead of frequent client-side Ajax polling). I have no practical experience with this but I imagine it most probably needs server side tweaking to be doable in PHP - it's not the best platform for long-running stuff. See this question for some approaches.