Php Dafault将值保存到mysql表中

Php Dafault将值保存到mysql表中,php,android,mysql,Php,Android,Mysql,我在一个使用mysql作为数据库的php网站上工作,现在我的网站是一个类似社交网络的网站,用户相互跟踪,现在如果用户加入,他不会跟踪任何人,所以他的流保持为空,所以他们也会很快离开网站,我希望用户在加入时自动跟踪我的帐户。你能告诉我怎么做吗 这是两张桌子 表SNU用户的表结构 表sn_的表结构如下 php代码是 public function userRegister($array) { $username = $this->__GB->__DB->escape_string(

我在一个使用mysql作为数据库的php网站上工作,现在我的网站是一个类似社交网络的网站,用户相互跟踪,现在如果用户加入,他不会跟踪任何人,所以他的流保持为空,所以他们也会很快离开网站,我希望用户在加入时自动跟踪我的帐户。你能告诉我怎么做吗

这是两张桌子

表SNU用户的表结构

表sn_的表结构如下

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);
}
}


}

为该操作创建一个MYSQL触发器。一旦用户注册社交网络,SQL触发器将创建一个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;
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);
}
}


}