我正在按照教程,但本教程的作者不回答问题 - 但这是我的查询
我收到以下错误警告:mysqli_error()预计正好1个参数,0给出,问题是这行代码 -
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
Run Code Online (Sandbox Code Playgroud)
整个代码是
session_start();
require_once "scripts/connect_to_mysql2.php";
//Build Main Navigation menu and gather page data here
$sqlCommand = "SELECT id, linklabel FROM pages ORDER BY pageorder ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$menuDisplay = '';
while ($row = mysqli_fetch_array($query)) {
$pid = $row["id"];
$linklabel = $row["linklabel"];
$menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />';
}
mysqli_free_result($query);
Run Code Online (Sandbox Code Playgroud)
包含的文件包含以下行
$myConnection = mysqli_connect("$db_host","$db_username","$db_pass","$db_name") or die ("could not …Run Code Online (Sandbox Code Playgroud) 我完全遵循w3schools.com中的代码.但是我仍然遇到上述错误,数据库表也没有更新.
我的html和php代码如下:
<form action="register.php" method="post">
<select name="title" size="1">
<option>Mr.</option>
<option>Ms.</option>
<option>Prof.</option>
<option>Dr.</option>
</select>
<label class="label">Given Name: <input name="givenname" type="text" value="Enter Your First Name" maxlength="30" /></label>
<label class="label">Surname: <input name="surname" type="text" /></label>
<label class="label">Address: <input name="address" type="text" maxlength="80" /></label>
<label class="label">Phone No: <input name="phoneno" type="text" /></label>
<label class="label">Email ID: <input name="emailid" type="text" /></label>
<label class="label">Fax: <input name="fax" type="text" /></label>
<label class="label">Pincode: <input name="pincode" type="text" /></label>
<label class="label">Country: <input name="country" type="text" /></label>
<input name="submit" type="submit" />
</form>
<?php
$con=mysqli_connect("my_Ipaddress","abcd","abcd");
//database connection
if …Run Code Online (Sandbox Code Playgroud) 我是一个PHP初学者所以请温柔:-)
我在试验mysqli_error.以下代码段检查连接$cxn.
7 ini_set('display_errors',1);
8 error_reporting(E_ALL);
9
10
11 echo "<html>
12 <head><title>Test MySQL</title></head>
13 <body>";
14 $host = "localhost";
15 $user = "test";
16 $password = "test";
17 $database = "PetCatalogFail";
18
19 $cxn = mysqli_connect($host,$user,$password,$database);
20
21 if(!$cxn)
22 {
23 var_dump($cxn);
24
25 $message = mysqli_error($cxn);
26 echo "$message";
27 echo "</body>";
28 echo "</html>";
29 die();
30 }
Run Code Online (Sandbox Code Playgroud)
$database故意被选为不正确的企图使其变为$cxn虚假.但是我收到以下消息:
警告:mysqli_error()要求参数1为mysqli,第25行/var/www/test.com/public_html/temp.php中给出布尔值
var_dump($cxn)给出输出为bool(false).我希望将结果错误消息存储$message并回显它.我使用mysqli_error不正确吗?