gpt4 book ai didi

php - Mysql 将资源 #16 插入数据库表

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

您好,我在这里遇到问题,在我的代码中,用户可以添加 friend ,但是当按下按钮接受请求时,他们会得到确认,并且他们的名字存储在数据库中,但是他们接受的用户存储为资源 ID #16。它还将其插入数据库 10 次。请求值不会从请求表中删除。我做错了什么谢谢

<?php
include ('c://website/mysite/views/header.php');
require_once ('c://website/mysite/config/config.php');
include('c://website/mysite/config/connection.php');

mysql_connect("localhost", "user", "pass") or die(mysql_error()) ;
mysql_select_db("login") or die(mysql_error()) ;
global $user_name,$page_owner,$username;

$user_name = trim(strip_tags($_SESSION["user_name"]));
//This is the user who logged into the system or logged in session

$page_owner = trim(strip_tags($_SESSION["user_name"]));
// This is the owner of the page viewed

$username = mysql_query("select * from request where friend ='".$_GET["username"]."'");
$user_id = mysql_query("select user_id from users where user_id = 'user_id'");

$check_request = mysql_query("select * from `request`
where `username` = '".$user_name."'
and `friend` = '".$username."'
or `friend` = '".$user_name."'
and `username` = '".$username."'")
or die(mysql_error()) ;

if(mysql_num_rows($check_request) > 0);
//If already added as friend, friendship confirmed

mysql_query("delete from `request`
where `username` = '".$user_name."'
and `friend` = '".$username."'");

mysql_query("delete from `request` where `username` = '".$username."' and `friend` = '".$user_name."'");
@mysql_query("insert into `friends` values('', '".$username."', '".$user_name."')");

@mysql_query("insert into `friends` values('', '".$user_name."', '".$username."')");

echo "friend_ship_confirmed";

最佳答案

您应该仅选择他的用户名,而不是选择所有内容 (*)

$username = mysql_query("select username from request where friend ='".$_GET["username"]."'"); 

而不是

$username = mysql_query("select * from request where friend ='".$_GET["username"]."'"); 

关于php - Mysql 将资源 #16 插入数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21138552/

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