简体   繁体   中英

How to insert data into the database from the client side?

I'm a beginner with web development and I have an access to a website hosted on cpanel and I need to do some changes on it. The backend of this website is made by cake PHP, and I want to insert some data into its database from client side using ajax. The problem is that I don't know how to get the URL of the PHP file that is in charge to insert to database. See the code below :

var xhttp = newXMLHttpRequest();
    xhttp.onreadystatechange= function() {    
 if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "i don't know what I put here", true);
  xhttp.send();

Normally, if you are developing an application which makes use of a database, then you would ensure the database and the business tier which connects to it are as close to each other as possible. This is all about latency.

You also wouldn't want any browser to be able to talk to the database from anywhere in the world. This is about security.

I'm scratching the surface here but essentially you wouldn't want to do what you're trying to do unless you're fully aware of the above and know what you're doing

If you're trying to do a one time operation, then i'm sure your hosting provider has a process for whitelisting you to allow you to connect to the database with your preferred client-side tool (eg MySQL Workbench if your database is MySQL). This would allow you to execute your one time query. Although CPanel has it's own MySQL interface which you can make use of, and that would seem the preferred route to go in this case

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM