查询在phpMyAdmin中有效,但在php中无效 [英] Query works in phpMyAdmin but not in php
问题描述
如果我运行以下代码,我会收到一条错误消息
If I run the following code I get an error saying
警告:mysqli_error()恰好期望1个参数,第13行的/home/u913241783/public_html/meeting_new.php中给出的参数为0"
"Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/u913241783/public_html/meeting_new.php on line 13"
这是从$r1d
开始的查询所在的行.但是,如果我在phpMyAdmin中运行查询,则效果很好.
which is the line with the query that starts $r1d
. However if I run the query in phpMyAdmin it works fine.
我尝试按照另一个问题的建议将两个查询拆分为单独的<? ?>
,但仍然无法正常工作.
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'] . ")";
}
推荐答案
我猜测meetingid
没有任何价值.
I'm guessing that meetingid
has no value.
按照建议的方法进行错误捕获并非总是可行.如果查询语法有效,则不会触发任何错误,但不会得到任何结果.
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";
然后,如有必要,将回显的查询复制并粘贴到phpMyAdmin中的SQL查询框中.
Then if necessary copy and paste the echoed query into the SQL query box in phpMyAdmin.
这篇关于查询在phpMyAdmin中有效,但在php中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!