简体   繁体   中英

How to save data in database

Please refer code below. I'm using phpMyAdmin to store my data in xampp(as my server). 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.
I suggest you use PDO, read more here: https://phpdelusions.net/pdo

You must learn database commands. Update, delete, select etc. You can do everything for db after that. And you can search update database or mysqli update

You have to use sql queries for inserting the data into database. You can start with CRUD Operations for learning. For your current code i am suggesting you to use ajax with jquery to submit data into the database. Alternatively you can also use core php to save data into database.

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