“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
(28个答案)
When to use single quotes, double quotes, and backticks in MySQL
(12个答案)
两年前关闭。
我只是想做一个简单的选择,但我不知道为什么它不起作用。
只是在这个页面上不起作用。我确信我的mysql数据库中有这些数据,我认为这应该起作用。。
<?php
require_once 'includes/db_connection.php';
require_once 'includes/functions.php';
require_once 'includes/profile/get_the_id.php';
require_once 'app/profile/header/head-profile.php';
$query = "SELECT * FROM `description` WHERE 'user_id'=$id";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result)){
$intro = $row['introducere'];
}
$query = "SELECT * FROM `images` WHERE 'user_id' = '$id'";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result)){
$img = $row['img'];
}
?>
错误消息是:
Notice: Undefined variable: intro in C:\xampp\htdocs\New\profile.php on line 33
Notice: Undefined variable: img in C:\xampp\htdocs\New\profile.php on line 33
在这个页面中,我也有两个必需的页面,这是html部分所必需的,我正在尝试建立一个像facebook这样的网站,这些页面是描述和横幅和个人资料图像部分。
<?php
$conn = mysqli_connect('localhost','root','','forum');
$username = $_SESSION['username'];
require_once 'get_the_id.php';
$target =" ";
if (isset($_POST['upload'])) {
$target = "./img/" . basename($_FILES['image']['name']);
$image = $_FILES['image']['name'];
$query = "INSERT INTO `images` VALUES('','$id','$image')";
mysqli_query($conn,$query) or die(mysqli_error($conn));
$query = "UPDATE `users` SET `img_profil` = '$image' WHERE `users`.`id` = '$id'";
mysqli_query($conn,$query) or die(mysqli_error($conn));
$msg="";
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)){
$msg="Success";
}else{
$msg="Fail";
}
$_SESSION['image'] = $image;
}
$query = "SELECT * FROM `images` WHERE 'user_id'='$id'";
$result = mysqli_query($conn,$query);
while ($row = mysqli_fetch_assoc($result)){
$img = $row['img'];
}?>
蚂蚁这个:
<?php
$conn = mysqli_connect('localhost','root','','forum');
require 'includes/profile/get_the_id.php';
$desc = $_SESSION['desc'];
$username = $_SESSION['username'];
$_SESSION['intro'] = " ";
if(isset($_POST['save'])){
$intro =mysqli_real_escape_string($conn,trim($_POST['intro']));
if ($desc == 1) {
//daca are deja o descriere se actualizeaza
$query = "UPDATE `description` SET `introducere` = '$intro' WHERE `description`.`user_id` ='$id'";
mysqli_query($conn,$query) or die(mysqli_error($conn));
}elseif ($desc == 0) {
//daca nu are descriere se insereaza descrierea facuta acum in db
$query = "INSERT INTO `descripbion` VALUES('','$id','$username','$intro','','','')";
mysqli_query($conn,$query);
//desc devine 1 deoarece a facut o descriere
$query = "UPDATE `users` SET `desc` = '1' WHERE `users`.`id` = '$id'";
mysqli_query($conn,$query) or die(mysqli_error($conn));
}
$_SESSION['intro'] = $intro;
}
我是一名优秀的程序员,十分优秀!