PHP MySQL 用户 ID

标签 php mysql

此代码应该从我的数据库中获取用户 ID,但它返回的是:Resource id #6

那么我该如何编写代码以使其返回用户 ID?这是我目前的代码,我知道 mysql_query 已经过时了:

<?php
include("login_check.php");
include("dbconnect.php");
mysql_select_db("maxgee_close2");
$username = $_COOKIE['maxgee_me_user']; 
$user_id = mysql_query("select user_id from users where username = '$username'");
echo "$user_id";
?>

最佳答案

mysql_connect("localhost", "mysql_user", "mysql_password") or 
  die("Could not connect: " . mysql_error());
mysql_select_db("maxgee_close2");
$result = mysql_query("select user_id from users where username = '$username'");
$row = mysql_fetch_array($result);
echo $row['user_id'];    
mysql_free_result($result);

关于PHP MySQL 用户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13040166/

相关文章:

mysql - Sphinx 索引器错误 : index 'PhoneNumbers2' : Error writing file '/tmp/MYbP6cIt' (Errcode: 28)

php - 如何使用PHP/HTML显示不同的文章

php - 如何计算数组中的相同值并将其存储到变量中?

php - 如何使用 php 删除最后一个点之后的所有数据?

php - 带有 React SPA 返回 419 页面的 Sanctum 已过期

php - 条件 mySQL 语句。如果为真 UPDATE,如果为假 INSERT

MySQL 触发器强制执行约束

mysql - alter table 在mysql中添加分区和子分区

php - 如何使用 codeigniter 更新和删除 SQL 数据库中的项目?

php - 在 php 中打印 <<< HTML?