【发布时间】:2015-10-12 22:50:13
【问题描述】:
我正在开发一个使用 mysql 作为数据库的 php 网站,现在我的网站是一个类似社交网络的网站,用户可以互相关注,现在如果用户加入,他就没有关注任何人,所以他的流仍然是空的,所以他们离开了网站也很快,我希望用户在加入时自动关注我的帐户。你能告诉我怎么做吗
这是两张表
表sn_users的表结构
CREATE TABLE IF NOT EXISTS `sn_users` (
`id` int(11) NOT NULL,
`username` varchar(225) NOT NULL,
`email` varchar(225) NOT NULL,
`password` varchar(225) NOT NULL,
`name` varchar(225) DEFAULT NULL,
`picture` varchar(100) NOT NULL,
`cover` varchar(100) DEFAULT NULL,
`job` varchar(225) DEFAULT NULL,
`address` varchar(225) DEFAULT NULL,
`date` int(11) NOT NULL,
`reg_id` text,
`active` int(11) NOT NULL DEFAULT '1'
) ENGINE=MyISAM AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;
表sn_follows的表结构
CREATE TABLE IF NOT EXISTS `sn_follows` (
`id` int(11) NOT NULL,
`from` int(11) NOT NULL,
`to` int(11) NOT NULL,
`date` int(11) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=74 DEFAULT CHARSET=utf8;
而php代码是
public function userRegister($array)
{
$username = $this->__GB->__DB->escape_string($array['username']);
$email = $this->__GB->__DB->escape_string($array['email']);
$password = md5($array['password']);
if (strlen(trim($username)) <= 4) {
$response = array(
'done' => false,
'message' => 'Username too short'
);
$this->__GB->prepareMessage($response);
} else if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
$response = array(
'done' => false,
'message' => 'Invalid E-mail'
);
$this->__GB->prepareMessage($response);
} else if (strlen(trim($array['password'])) <= 5) {
$response = array(
'done' => false,
'message' => 'Password too short'
);
$this->__GB->prepareMessage($response);
} else if ($this->UserExist($username)) {
$response = array(
'done' => false,
'message' => 'Username already exists'
);
$this->__GB->prepareMessage($response);
} else {
if (isset($_FILES['image'])) {
$imageID = $this->__GB->uploadImage($_FILES['image']);
} else {
$imageID = null;
}
$array = array(
'username' => $username,
'password' => $password,
'email' => $email,
'date' => time(),
'picture' => $imageID
);
if ($this->__GB->GetConfig('emailactivation', 'users') == 1) {
$array['active'] = 0;
}
$insert = $this->__GB->__DB->insert('users', $array);
if ($insert) {
if ($this->__GB->GetConfig('emailactivation', 'users') == 1) {
$this->sendEmailActivation($this->__GB->__DB->lastID(), $email);
}
$response = array(
'done' => true,
'message' => 'Your account has been created'
);
$this->__GB->prepareMessage($response);
} else {
$response = array(
'done' => false,
'message' => 'Oops Something Went Wrong'
);
$this->__GB->prepareMessage($response);
}
}
}
【问题讨论】:
-
当您创建新用户时,明确添加“帐户”作为要关注的内容。这与数据库无关。只需在应用程序中做你想做的事。