简体   繁体   English

查询在phpMyAdmin中有效,但在php中无效

[英]Query works in phpMyAdmin but not in php

If I run the following code I get an error saying 如果我运行以下代码,我会收到一条错误消息:

"Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/u913241783/public_html/meeting_new.php on line 13" “警告:mysqli_error()恰好希望有1个参数,第13行的/home/u913241783/public_html/meeting_new.php中给出的参数为0”

which is the line with the query that starts $r1d . 这是从$r1d开始的查询行。 However if I run the query in phpMyAdmin it works fine. 但是,如果我在phpMyAdmin中运行查询,则效果很好。

I've tried splitting the two queries into separate <? ?> 我尝试将两个查询拆分为单独的<? ?> <? ?> as suggested on another question but it still did not work. <? ?>关于另一个问题的建议,但仍然无法正常工作。

 <?php
    session_start();
    $input2 = $_SESSION[ 'unitid' ];

    include 'connect_db.php'; 

    $q1c="INSERT into meetings (unitid) VALUES ('$input2')";
    $r1c = mysqli_query($dbc,$q1c);

    $q1d = "SELECT max(meetingid) as newmeeting FROM meetings LIMIT 1)";
    $r1d = mysqli_query ($dbc, $q1d);
    while($row1d = mysqli_fetch_assoc($r1d))

    {
    echo" header ('location:editmeeting.php?id=" . $row1d['newmeeting'] .  ")";
    } 

I'm guessing that meetingid has no value. 我猜meetingid没有价值。

Trapping on an error as suggested will not always work. 如建议的那样陷阱错误并不总是有效。 If the query syntax is valid then no error is triggered, but you get no results. 如果查询语法有效,则不会触发任何错误,但不会得到任何结果。

Add an echo to your code: 在您的代码中添加回显:

$q1d = "SELECT max(meetingid) as newmeeting FROM meetings LIMIT 1)";
$r1d = mysqli_query ($dbc, $q1d);
echo mysqli_error() . "<br/>$q1d";

Then if necessary copy and paste the echoed query into the SQL query box in phpMyAdmin. 然后,如有必要,将回显的查询复制并粘贴到phpMyAdmin中的SQL查询框中。

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

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