[英]Errors for: mysqli_query, mysqli, mysqli_fetch_assoc, mysqli_result, mysqli_num_rows and imo wierd undefined variable
您好,我正在嘗試修復我的網站,我用它來嘗試一些東西,並在業余時間更好地學習php。 所以是的,我的主機發生了變化,所以現在我必須使用mysqli而不是mysql,而且我有很多問題,然后我認為應該使用它。
在此先感謝您的幫助!
錯誤:
profile.php:
<?php
require("functions.php");
$profileUsersData = getUsersData(mysqli_real_escape_string($con, $_GET['id']));
if(userExists(mysqli_real_escape_string($con, $_GET['id'])))
{
echo '<div class="page-header"><h2>'.$profileUsersData['firstname']." ".$profileUsersData['lastname']."'s Profile</h2></div>";
?>
<div class="row" style="margin:0 auto;">
<div class="col-lg-6">
<div class="well">
<?php echo '<font size=4>About '.$profileUsersData['firstname'].':</font>'; ?>
<br />
<?php echo $profileUsersData['about']; ?>
<br />
<br />
Country: <?php echo $profileUsersData['country']; ?>
<br />
City: <?php echo $profileUsersData['city']; ?>
<br />
Age:
<?php
$difference = time() - $profileUsersData['birthdate'];
$age = floor($difference / 31556926);
echo $age.'<font class="text-danger"> Still not working correctly</font>';
?>
<br /><p></p>
<?php
if($profileUsersData['username']==$_SESSION['username'])
{
echo '<a href="index.php?page=editprofile"><button type="button" class="btn btn-success">Edit profile</button></a>';
}
?>
</div>
</div>
</div>
<?php
}
else echo '<div class="page-header"><h2>Profile</h2></div><p><font class="text-danger"><h1>Invalid ID: '.h($_GET['id']).'</h1></font></p><br /><br /><br /><br />';
?>
dbc.php
<?php
$con = new mysqli("host","user","password","db");
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
?>
的functions.php:
<?php
require("dbc.php");
if (!function_exists('getUsersData')) {
function getUsersData($id) {
$array = array();
$q = mysqli_query($con, "SELECT * FROM `users` WHERE `id`=".$id);
while($r = mysqli_fetch_assoc($q)) {
$array['id'] = $r['id'];
$array['username'] = $r['username'];
$array['password'] = $r['password'];
$array['firstname'] = $r['firstname'];
$array['lastname'] = $r['lastname'];
$array['profileext'] = $r['profileext'];
$array['about'] = $r['about'];
$array['birthdate'] = $r['birthdate'];
$array['country'] = $r['country'];
$array['city'] = $r['city'];
}
return $array;
}
}
if (!function_exists('getId')) {
function getId($username)
{
$q = mysqli_query($con, "SELECT `id` FROM `users` WHERE `username`='".$username."'");
while($r = mysqli_fetch_assoc($q))
{
return $r['id'];
}
}
}
if (!function_exists('userExists')) {
function userExists($id)
{
$numrows = mysqli_num_rows(mysqli_query($con, "SELECT `id` FROM `users` WHERE `id`=".$id));
if($numrows==1)
return true;
else
return false;
}
}
if (!function_exists('form_row_class')) {
function form_row_class($name) {
global $errors;
return $errors[$name] ? " has-error" : "";
}
}
if (!function_exists('error_for')) {
function error_for($name) {
global $errors;
if($errors[$name]) {
return "<div class='text-danger'>" . $errors[$name] . "</div>";
}
}
}
if (!function_exists('h')) {
function h($string){
return htmlspecialchars($string);
}
}
if (!function_exists('updateProfile')) {
function updateProfile($id,$firstName,$lastName,$about,$country,$city)
{
if(mysqli_query($con, "UPDATE `users` SET `firstname`='".$firstName."', `lastname`='".$lastName."', `about`='".$about."', `birthdate`=".$birthdate.", `country`='".$country."', `city`='".$city."' WHERE `id`=".$id))
return true;
else
return false;
}
}
?>
你可以嘗試把
global $con;
在“函數getUsersData($ id){”之后
在您的functions.php中,未定義$con
因此其為空值。.您正在使用父文件中的$con
,因此必須編寫parent::$con
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.