我正在尝试用户创建像facebook这样的用户组系统,但我有用户ID分配的问题。
我的用户表数据库设计:
username
uid
password
email
我对group_user的数据库设计:
group_id
group_name
group_information
group_cover
uid_fk
这样,来自用户表的uid_fk
为uid
。当用户创建群组时,我想将uid
分配给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
时。我该怎么做才能解决这个问题?
答案 0 :(得分:1)
您忘记在调用
时放置第三个参数// 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);