Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php $wpdb不工作,即使验证结果为正_Php_Wordpress - Fatal编程技术网

Php $wpdb不工作,即使验证结果为正

Php $wpdb不工作,即使验证结果为正,php,wordpress,Php,Wordpress,我想知道是否有人能帮助我。我正在尝试向wordpress数据库中的表中添加一些数据。我使用$wpdb类,每次运行代码时,得到的验证结果都是肯定的。但是当我检查数据库中的表时,它是空的 我的代码: // Define global $wpdb global $wpdb; // Retrieve information from the form $location = $_POST['txtLocation']; $price = $_POST['txtP

我想知道是否有人能帮助我。我正在尝试向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;
//定义全局$wpdb
全球$wpdb;
//从表单中检索信息
$location=$_POST['txtLocation'];
$price=$_POST['txtPrice'];
$type=$_POST['sltType'];
$revenue=$_POST['txtRevenue'];
$surgeries=$_POST['txtSurgeries'];
$任期=$_职位['sltTenure'];
$upload=$_POST['txtUpload'];
//SQL语句将表单中的信息插入数据库
$sql=$wpdb->prepare(“插入到实践中('Location'、'Price'、'Type'、'Revenue'、'No.of Surgeries'、'Requirement'、'PDF')值(%s、%s、%s、%s),$Location、$Price、$Type、$Revenue、$Surgeries、$Requirement、$upload);
$result=$wpdb->query($sql);
如果(!结果){
echo'

将练习上载到数据库时出现问题; }否则{ echo“

实践已上载到数据库中

”; } echo$wpdb->last_查询;
有人知道我的代码为什么这样做吗

谢谢

在您的查询中忘记了关闭
。 这里

尝试:

也是

if (!$result) {
     ^

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


MySQL希望列标识符使用backticks括起来:`。

Nope仍然没有将数据添加到数据库更改$result错误类型,并且刚刚调试了“将实践上载到数据库时出现问题”,我得到:WordPress数据库错误:[您的SQL语法有错误;请检查与您的MySQL服务器版本对应的手册,以了解第1行“位置”、“价格”、“类型”、“收入”、“手术数量”、“任期”、“PDF”)VAL”附近使用的正确语法]插入到实践中(“位置”、“价格”、“类型”、“收入”、“手术数量”、“任期”、“PDF”)值('Newport'、'56000'、'nhs'、'876000'、'1'、'freehold'、'
 $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) {
     ^