gpt4 book ai didi

php - 无法重新分配自动全局变量 _POST

转载 作者:可可西里 更新时间:2023-11-01 01:01:53 25 4
gpt4 key购买 nike

我收到以下错误: fatal error :无法在第 47 行的 C:\Program Files (x86)\Zend\Apache2\htdocs\includes\class-insert.php 中重新分配自动全局变量 _POST 当试图访问我的 class-insert.php 页面(或我的大部分其他页面)时。此代码来自以下视频:https://www.youtube.com/watch?v=Wgbmgf84ZOo可以在这里找到:http://www.johnmorrisonline.com/lesson/how-to-create-a-social-network-using-php/

class-insert.php:

<?php
require_once('class-db.php');

if ( !class_exists('INSERT') ) {
class INSERT {
public function update_user($user_id, $postdata) {
global $db;

$table = 's_users';

$query = "
UPDATE $table
SET user_email='$postdata[user_email]', user_pass='$postdata[user_pass]', user_nicename='$postdata[user_nicename]'
WHERE ID=$user_id
";

return $db->update($query);
}

public function add_friend($user_id, $friend_id) {
global $db;

$table = 's_friends';

$query = "
INSERT INTO $table (user_id, friend_id)
VALUES ('$user_id', '$friend_id')
";

return $db->insert($query);
}

public function remove_friend($user_id, $friend_id) {
global $db;

$table = 's_friends';

$query = "
DELETE FROM $table
WHERE user_id = '$user_id'
AND friend_id = '$friend_id'
";

return $db->insert($query);
}

public function add_status($user_id, $_POST) {
global $db;

$table = 's_status';

$query = "
INSERT INTO $table (user_id, status_time, status_content)
VALUES ($user_id, '$_POST[status_time]', '$_POST[status_content]')
";

return $db->insert($query);
}

public function send_message($_POST) {
global $db;

$table = 's_messages';

$query = "
INSERT INTO $table (message_time, message_sender_id, message_recipient_id, message_subject, message_content)
VALUES ('$_POST[message_time]', '$_POST[message_sender_id]', '$_POST[message_recipient_id]', '$_POST[message_subject]', '$_POST[message_content]')
";

return $db->insert($query);
}
}
}

$insert = new INSERT;
?>

谢谢!

最佳答案

您不能将超全局变量用作函数参数的变量名。如果您使用备用名称,您仍然可以将超全局变量传递给该函数,或者您可以从参数列表中删除超全局变量,并且无论如何都可以访问它,因为它随处可用。

List of superglobals

选项 1:

function print_post( $post_data ){
print_r($post_data);
}
print_post($_POST);

选项 2:(错误形式)

function print_post(){
print_r($_POST);
}
print_post();

关于php - 无法重新分配自动全局变量 _POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22459557/

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