用$_GET获取Location传递的的数据是1,怎么办哪儿不对?

以气御码 2017-12-12 12:10:27
1.这是“车祸代码”:
文件名:“news_list.php”

if(isset($_GET["message"])){
echo $_GET["message"]."<hr>";
}

问题:只显示“1”。


2.有关message的页面和顺序
(1)文件名:“file_system.php”,判断提交的文件大小。

<?php
header("content-type:text/html;charset:utf8");
function upload($file,$file_path){
$error=$file['error'];
switch($error){
case 0:
$file_name=$file['name'];
$file_temp=$file['tmp_name'];
$destination=$file_path."/".$file_name;
move_uploaded_file($file_temp,$destination);
return "上传成功!";
case 1:
return "上传文件超过了php.ini中upload_max_filesize的限制!";
case 2:
return "上传文件超过了表单MAX_FILE_SIZE的限制!";
case 3:
return "文件只有部分被上传!";
case 4:
return "没有选择文件!";
}
}
?>


(2)文件名:“news_add.php”,这是表单页面,虽然没有message,不过一块发出来,求解答。

<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>添加新闻</title>
<link rel="icon" href="images/logo.ico" type="image/x-icon"><!--title显示logo,建议尺寸4cmX4cm(文字)-->
</head>
<body>
<!---->
<?php
if(!session_id()){
session_start();
}
include_once("functions/is_login.php");
include_once("functions/database.php");
if(!is_login()){
echo "还没有登录呢!";
return;
}
?>
<!---->
<form action="news_save.php" method="post" enctype="mulitipart/form-data">
<p>标题:<input type="text" name="title" size=""60></p>
<p>内容:</p><textarea name="content" rows="16" cols="60"></textarea><br>
<p>类别:</p>
<select name="cate_id" size="1">
<?php
include_once("functions/database.php");
get_connection();
$result_cate=mysql_query("select * from category");
close_connection();
while($row=mysql_fetch_array($result_cate)){
?>
<option value="<?php echo $row['category_id']; ?>">
<?php echo $row['category_name']; ?>
</option>
<?
}
?>
</select><br>
<p>附件:<input type="file" name="news_file" size="50"><input type="hidden" name="MAX_FILE_SIZE" value="10240"></p>
<p><input type="submit" value="提交"><input type="reset" value="重置"></p>
</form>
<!---->
</body>
</html>


(3)文件名:“news_save.php”,保存提交的表单数据页面,有message赋值,而传递message是最后一句用header。

<?php
header("content-type:text/html;charset:utf8");
session_start();
include_once("functions/file_system.php");
if(empty($_POST)){
$message="上传文件超过了php.ini中upload_max_filesize的限制!";
}else{
$user_id=$_SESSION['user_id'];
$cate_id=$_POST['cate_id'];
$title=$_POST['title'];
$content=$_POST['content'];
$current_date=date("Y-m-d H:i:s");
$clicked=0;
$file_name=$_FILE["news_file"]["name"];
$sql_news="insert into news values(null,$user_id,$cate_id,'$title','$content','$current_date',$clicked,'$file_name')";
$message=upload($_FILES["news_file"],"uploads");
if($message="上传成功!"||$message="没有选择文件!"){
include_once("functions/database.php");
get_connection();
mysql_query($sql_news);
close_connection();
}
}
//$message=urlencode($message);
header("Location:news_list.php?message=$message");
?>


(4)文件名:“news_list.php”,接收message并显示,就是一开始说的“车祸代码”。

if(isset($_GET["message"])){
echo $_GET["message"]."<hr>";
}



第一次发帖,不知道代码会不会乱,附上了截图,求大大们解答!
...全文
205 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
以气御码 2017-12-12
  • 打赏
  • 举报
回复
坐等躺等喝着茶等敲着代码等在线等
xuzuning 2017-12-12
  • 打赏
  • 举报
回复
你有 if($message="上传成功!"||$message="没有选择文件!"){ 所以不管 $message 原来是什么 $message 的值都是 1(逻辑真) 因为 $message="上传成功!"||$message="没有选择文件!" 中,=(赋值符的优先级低于逻辑运算符 || 的优先级,所以 "上传成功!"||$message="没有选择文件!" 被先行计算,恒为真(true)
Mechnaic 2017-12-12
  • 打赏
  • 举报
回复

$message=upload($_FILES["news_file"],"uploads");
echo $message;

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧