我有一个WordPress主题,我正在尝试将数据从HTML表单保存到数据库中.
我创建了HTML表单并添加了一个"保存并关闭"按钮,该按钮调用一个名为JavaScript的函数saveData(),该函数从表单中获取数据并将其发送到addrow.php该函数,该函数应将数据保存到名为的数据库表中vel.
我认为问题在于,addrow.php因为在WordPress中,需要使用全局$wpdb或其他东西.
一个简单的例子是如何将数据从HTML表单保存到WordPress驱动的应用程序中的数据库表中?
该addrow.php代码:
<?php
require("phpsqlinfo_dbinfo.php");
// Gets data from URL parameters
$nombre = $_GET['nombre'];
$direccion = $_GET['direccion'];
$lat = $_GET['lat'];
$lng = $_GET['lng'];
$tipo = $_GET['tipo'];
// Opens a connection to a MySQL server
$connection = mysql_connect ("localhost", $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use …Run Code Online (Sandbox Code Playgroud)