我看过以前类似问题的许多答案。然而,这是不同的,因为当一个错误被修复时,它会抛出第二个错误。
我看过的所有帖子都没有回答这两个部分。有些人甚至用一种似乎不等同于英语的语言说话,就像我认识到许多单词而不是按照他们使用的顺序一样。
我会要求你解释我的答案,好像我已经10岁了。
我的网页引发了这个错误:
PHP Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\inetpub\wwwroot\KidsCancerCharity\familyservices.php on line 10
第10行是:
$theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($theValue) : mysqli_escape_string($theValue);
我从其他帖子中了解到,缺少的参数是我的连接,我理解的是与数据库的连接。在这种情况下,它是$KCC
。
如果我将其添加到mysqli_real_escape_string($theValue)
我收到此错误:
PHP Notice: Undefined variable: KCC in C:\inetpub\wwwroot\KidsCancerCharity\familyservices.php on line 10
PHP Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\inetpub\wwwroot\KidsCancerCharity\familyservices.php on line 10
我正在更新所有内容以使用PHP v7和MYSQLi,但知道其中任何一个都没有。
我添加了整个页面代码,以防它在其他地方。代码是:
<?php require_once('Connections/KCC.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($KCC, $theValue) : mysqli_escape_string($KCC, $theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysqli_select_db($KCC, $database_KCC);
$query_rsFrontPage = "SELECT * FROM frontpage";
$rsFrontPage = mysqli_query($KCC, $query_rsFrontPage) or die(mysqli_error());
$row_rsFrontPage = mysqli_fetch_assoc($rsFrontPage);
$totalRows_rsFrontPage = mysqli_num_rows($rsFrontPage);
$idVal_rsContent = "1";
if (isset($_GET['idVal'])) {
$idVal_rsContent = $_GET['idVal'];
}
mysqli_select_db($KCC, $database_KCC);
$query_rsContent = sprintf("SELECT pagecontent.mainMenuID, mainmenu.mainMenuLabel, pagecontent.subMenuID, submenu.subMenuLabel, pagecontent.contentID, pagecontent.contentTitle, pagecontent.contentData, pagecontent.contentImage FROM submenu RIGHT JOIN (mainmenu RIGHT JOIN pagecontent ON mainmenu.mainMenuID = pagecontent.mainMenuID) ON submenu.subMenuID = pagecontent.subMenuID WHERE pagecontent.ContentID = %s", GetSQLValueString($idVal_rsContent, "int"));
$rsContent = mysqli_query($KCC, $query_rsContent) or die(mysqli_error());
$row_rsContent = mysqli_fetch_assoc($rsContent);
$totalRows_rsContent = mysqli_num_rows($rsContent);
?>
<!doctype html>
<html>
<head>
<meta charset="utf8mb4">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Kids Cancer Charity</title>
<!-- Bootstrap core CSS -->
<link href="scripts/bootstrap.css" rel="stylesheet">
<link href="scripts/jquery.smartmenus.bootstrap.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="scripts/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Local CSS goes here -->
<link href="scripts/fonts.css" rel="stylesheet" type="text/css">
<link href="scripts/kids-cancer-charity-media-queries.css" rel="stylesheet" type="text/css">
<link href="scripts/kids-cancer-charity.css" rel="stylesheet" type="text/css">
<!-- /Local CSS -->
</head>
<body>
<?php require_once('includes/kcc-logo.php'); ?>
<?php require_once('includes/navigation.php'); ?>
<article>
<div class="container">
<?php require_once('includes/page-image.php'); ?>
<div style="margin-bottom:50px; padding:10px">
<?PHP if (is_null ($row_rsContent['subMenuID'])): ?>
<h2><?php echo $row_rsContent['mainMenuLabel']; ?></h2>
<?PHP else: ?>
<h2><?php echo $row_rsContent['subMenuLabel']; ?></h2>
<?PHP endif ?>
<h3><?php echo $row_rsContent['contentTitle']; ?></h3>
<?php echo $row_rsContent['contentData']; ?>
</div>
<!--<img src="images/well-bar.png" class="img-responsive well-bar">-->
</div>
</article>
<?php require_once('includes/footer.php'); ?>
<!-- Placed at the end of the document so the pages load faster -->
<!-- JQuery core Javascript -->
<script src="scripts/jquery-3.1.0.min.js"></script>
<script src="scripts/jquery-migrate-3.0.0.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script src="scripts/bootstrap.min.js"></script>
<!--<script src="scripts/npm.js"></script>-->
<script src="scripts/jquery.smartmenus.min.js"></script>
<script src="scripts/jquery.smartmenus.bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="scripts/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
<?php
mysqli_free_result($rsFrontPage);
mysqli_free_result($rsContent);
?>
KCC.php的代码是:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_KCC = "localhost";
$database_KCC = "database_name";
$username_KCC = "user_name";
$password_KCC = "user_password";
$KCC = mysqli_connect($hostname_KCC, $username_KCC, $password_KCC) or trigger_error(mysqli_error(),E_USER_ERROR) ;
?>