PHP用户ID分配不起作用 [英] php user id assignment not working
本文介绍了PHP用户ID分配不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用户创建类似于Facebook的用户组系统,但是我在分配用户ID时遇到问题.
I am trying to user create user group system like facebook but i have problem with user id assignment.
我的用户表数据库设计:
My database design for users table:
username
uid
password
email
我对group_user的数据库设计:
My database design for group_user:
group_id
group_name
group_information
group_cover
uid_fk
这样,uid_fk
是用户表中的uid
.当用户创建组时,我想将uid
分配给uid_fk
In this way uid_fk
is uid
from users table. When user create group i want to assign uid
to uid_fk
这是我的PHP代码:
group_user.php
<?php
class group_user
{
public function Create_User_group($group_name,$group_information,$uid)
{
$group_name= mysql_real_escape_string($group_name);
$group_information= mysql_real_escape_string($group_information);
$qu= mysql_query("SELECT group_id FROM group_users WHERE
group_name='$group_name'");
if(mysql_num_rows($qu)==0)
{
$query = mysql_query("INSERT INTO
group_users(group_name, group_information, uid_fk)
VALUES('$group_name','$group_information','$uid')");
$sqll = mysql_query("SELECT group_id
FROM group_users
WHERE group_name='$group_name'
and uid_fk='$uid'");
$row = mysql_fetch_array($sqll);
$group_id = $row['group_id'];
$group_query = mysql_query("INSERT INTO
group_friends(group_f_one, group_f_two, role)
VALUES('$group_id','$group_id','me')");
return $blog_id ;
} else {
return false;
}
}
}
?>
create_group.php
<?php
include_once 'includes/db.php';
include_once 'includes/group_user.php';
//Create group
$group_user = new group_user();
$reg_error='';
if($_POST['group_name'] && $_POST['group_information'] )
{
$group_name=$_POST['group_name'];
$group_information=$_POST['group_information'];
if (strlen($group_name)>0 && strlen($group_information)>0)
{
$regg=$group_user->Create_User_group($group_name,$group_information);
if($regg)
{
$_SESSION['group_id']=$regg;
header("Location:group.php");
}
else
{
$reg_error="<span class='registererror'>Group name Already exist.</span>";
}
}
}
?>
问题是,当用户创建组uid_fk自动为0而不是uid
时.我该怎么办才能解决这个问题?
The problem is, when user create group uid_fk is automatically '0' not uid
. What can i do to solve this problem?
推荐答案
您刚刚忘记将第三个参数放在对
You have just forgotten to place the third parameter on your call to
// missing param 3
$regg=$group_user->Create_User_group($group_name,$group_information);
应该是
$regg=$group_user->Create_User_group($group_name,$group_information, $THE_UID_PARAM);
这篇关于PHP用户ID分配不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文