Make new users automatically follow a user in php

Started on the old forum in October 2015 · view the original in the archive · old links redirect here

3 replies · 217 views · started 11 years ago · 2 min read

3 participants
strange8 Newbie · 2 posts #1

I am working on a php site with uses mysql as database, now my site is a social network like site where users follow each other, now if a user joins in he is following nobody so his stream remains empty so they leave the site quickly as well,i want users to be following my account account automatically when he joins in. Can you please tell me how to do it

here are the two tables

Table structure for table `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;

Table structure for table `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;

and the php code is

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

}
subzero Super moderator Fellow · 3,954 posts #2

Please remember to use forum codes [ code ] and to close [ /code ] but no space. it would be clean and clear 😉

You can add a sql line with his/her username in sign up ... Like

 
 $array = array( 'id' => Your_ID, 'username' => Your_Name );    

into
sn_follows

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

strange8 Newbie · 2 posts #3

can you please show me how to do it on my code?

arnage Lead · 811 posts #4

Just add your ID as default value in SQL table...

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close