$wpdb不起作用,即使验证结果为阳性


$wpdb not working, even though validation comes back positive

我想知道是否有人可以帮助我。我正在尝试将一些数据添加到wordpress数据库中的表中。我正在使用 $wpdb 类,每次运行代码时,我得到的验证都会返回正值。但是当我检查数据库中的表时,它是空的。

我的代码:

    // Define global $wpdb
    global $wpdb;
    // Retrieve information from the form
    $location = $_POST['txtLocation'];
    $price = $_POST['txtPrice'];
    $type = $_POST['sltType'];
    $revenue = $_POST['txtRevenue'];
    $surgeries = $_POST['txtSurgeries'];
    $tenure = $_POST['sltTenure'];
    $upload = $_POST['txtUpload'];
    // SQL statement to insert information from the form into the database
    $sql = $wpdb->prepare("INSERT INTO practices ('Location', 'Price', 'Type', 'Revenue', 'No. of Surgeries', 'Tenure', 'PDF') VALUES (%s,%s,%s,%s,%s,%s,%s", $location, $price, $type, $revenue, $surgeries, $tenure, $upload);
    $result = $wpdb->query($sql);
    if (!result) {
        echo '<p class="sql-error">There was a problem uploading the practice to the database</p>';
    } else {
        echo '<p class="sql-success">The practice was uploaded to the database</p>';
    }
    echo $wpdb->last_query;

有人知道我的代码为什么要这样做吗???

谢谢

在查询中忘记了结束)。这里

VALUES (%s,%s,%s,%s,%s,%s,%s 
                            ^

尝试:

 $sql = $wpdb->prepare("INSERT INTO practices ('Location', 'Price', 'Type', 'Revenue', 'No. of Surgeries', 'Tenure', 'PDF') VALUES (%s,%s,%s,%s,%s,%s,%s)", $location, $price, $type, $revenue, $surgeries, $tenure, $upload);

也是

if (!$result) {
     ^

除了按照建议关闭查询中的 VALUES 语句之外,您可能会发现使用 ' 引用列名也会给您带来问题。

MySQL 希望使用反引号将列标识符括起来:".