简体   繁体   English

如何在数据库中保存数据

[英]How to save data in database

Please refer code below.请参考下面的代码。 I'm using phpMyAdmin to store my data in xampp(as my server).我正在使用 phpMyAdmin 将我的数据存储在 xampp(作为我的服务器)中。 I found this code and add into my website.我找到了这段代码并添加到我的网站中。 My question is;我的问题是; how to save the result in database.如何将结果保存在数据库中。 Anyone??任何人??

 <!DOCTYPE html> <html> <head> <title>Geo City Locator by geoip-db.com</title> </head> <body> <div>Country: <span id="country"></span></div> <div>State: <span id="state"></span></div> <div>City: <span id="city"></span></div> <div>Postal: <span id="postal"></span></div> <div>Latitude: <span id="latitude"></span></div> <div>Longitude: <span id="longitude"></span></div> <div>IP address: <span id="ipv4"></span></div> </body> <script> var country = document.getElementById('country'); var state = document.getElementById('state'); var city = document.getElementById('city'); var postal = document.getElementById('postal'); var latitude = document.getElementById('latitude'); var longitude = document.getElementById('longitude'); var ip = document.getElementById('ipv4'); function callback(data) { country.innerHTML = data.country_name; state.innerHTML = data.state; city.innerHTML = data.city; postal.innerHTML = data.postal; latitude.innerHTML = data.latitude; longitude.innerHTML = data.longitude; ip.innerHTML = data.IPv4; } var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://geoip-db.com/json/geoip.php?jsonp=callback'; var h = document.getElementsByTagName('script')[0]; h.parentNode.insertBefore(script, h); </script> </html>

In order to "talk" with your database (for inserting, deleting, updating or creating) you'll need to use an SQL library, PDO or MySQLi.为了与您的数据库“对话”(插入、删除、更新或创建),您需要使用 SQL 库、PDO 或 MySQLi。
I suggest you use PDO, read more here: https://phpdelusions.net/pdo我建议您使用 PDO,请在此处阅读更多信息: https : //phpdelusions.net/pdo

You must learn database commands.您必须学习数据库命令。 Update, delete, select etc. You can do everything for db after that.更新、删除、选择等。之后你可以为 db 做任何事情。 And you can search update database or mysqli update你可以搜索update databasemysqli update

You have to use sql queries for inserting the data into database.您必须使用 sql 查询将数据插入数据库。 You can start with CRUD Operations for learning.您可以从 CRUD Operations 开始学习。 For your current code i am suggesting you to use ajax with jquery to submit data into the database.对于您当前的代码,我建议您使用 ajax 和 jquery 将数据提交到数据库中。 Alternatively you can also use core php to save data into database.或者,您也可以使用核心 php 将数据保存到数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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