gpt4 book ai didi

php mysql..无法将变量分配给数据库中的字段名称

转载 作者:行者123 更新时间:2023-11-30 01:22:42 26 4
gpt4 key购买 nike

我需要一些帮助来查询2表相册和图像

我需要从数据库中选择一些字段,其中有一个user_id

查询:

  $album_query = mysql_query("SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`, LEFT(`albums`.`description`, 50) as `description`, COUNT(`images`.`image_id`) as `image_count`
FROM `albums`
LEFT JOIN `images`
ON `albums`.`album_id` = `images`.`album_id`
WHERE `albums`.`user_id` = '**here it must take the session created before**'
GROUP BY `albums`.`album_id`") or die(mysql_error());

这是代码块:

<?php 

ob_start();
if(!isset($_SESSION))
{
session_start();
}

require_once('include/connect.php');



if(isset($_GET['user_id']))
{
$id=$_GET['user_id'];


}
elseif(isset($_SESSION['user_id']))
{
$id= $_SESSION['user_id'];
}

else
{
require_once('index.php');

exit();

}

//function to ge the data for the album
function album_data($album_id)
{

}
//check if the album belong to the particular user
function album_check($album_id)
{
}

//get thelist of albums
function get_albums()
{

$albums = array();
$album_query = mysql_query("SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`, LEFT(`albums`.`description`, 50) as `description`, COUNT(`images`.`image_id`) as `image_count`
FROM `albums`
LEFT JOIN `images`
ON `albums`.`album_id` = `images`.`album_id`
WHERE `albums`.`user_id` = ''
GROUP BY `albums`.`album_id`") or die(mysql_error());

while($albums_row = mysql_fetch_array($album_query))
{
$albums[] = array(
'id' =>$albums_row['album_id'],
'timestamp'=>$albums_row['timestamp'],
'name'=>$albums_row['name'],
'description'=>$albums_row['description'],
'count'=>$albums_row['image_count']
);

}
return $albums;
}


function create_album($album_name, $album_description)
{
$album_name= mysql_real_escape_string(htmlentities($album_name));
$album_description= mysql_real_escape_string(htmlentities($album_description));

mysql_query("INSERT INTO albums VALUES('', '" .$_SESSION['user_id']. "', UNIX_TIMESTAMP(), '$album_name','$album_description')");

mkdir('uploads/'.mysql_insert_id(), 0744);
mkdir('uploads/thumbs/'.mysql_insert_id(), 0744);


}

?>


*elseif(isset($_SESSION['user_id']))
{
$id= $_SESSION['user_id'];
}*

这是错误,因为系统不允许我分配 album.user_id = $id数据库字段存储0

我不知道我是否以一种可以理解的方式解释了我的问题

谁能帮帮我???

最佳答案

您应该更改此行

 WHERE `albums`.`user_id` = ''

像这样:

WHERE `albums`.`user_id` = '".$id."'

关于php mysql..无法将变量分配给数据库中的字段名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18374458/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com