justlukeyou
-
Posts
957 -
Joined
-
Last visited
Posts posted by justlukeyou
-
-
Hi,
I changed it to this and it now inserts the current_user_id into the database. However Im struggling to understand how I can seperate out the two different id numbers.
If I click on the profile of 350 I have the ID 350. But how do I seperate that from ID 355? Whatever I do have the ID showing as 355 if I am logged is as 355.
<?php $id = $_SESSION['userID']; $user_id = $_SESSION['userID']; $current_user_id = $_SESSION['userID']; if (($_GET['do'] !== 'follow') || (int)$_GET['id']) { // just send away if ($_SESSION['current_user_id'] == $_GET['current_user_id']) { // other checks here to determine various ID's are numeric, etc. $sql = "INSERT INTO `follow` (`user_id`, `follow_user_id`) VALUES (". (int)$_SESSION['current_user_id'] .", ". (int)$_GET['id'] .")"; if (!mysql_query($sql)) { if (mysql_errno($link_identifier) == 1062) { //$link_identifier is necessary to avoid conflicting error notices due to multiple openning/closing SQL connections // duplicate attempt to follow // handle accordingly } } } } ?>
-
Hi,
A member of this forum kindly provided code which I was doing wrong. The purpose of the code is to create a 'social network' which enables people to follow other members by inserting their ID number into a database. I was inserting the ID number of the user into the same table as the main user table. However someone pointed out that I suggest use a seperate table and insert the ID number of both users into the table.
The problem is I cant get the code to work. I can echo the id but this only comes from the first line of code. Nothing else seems to work. I have tried manually inserting one of the id's to see if they would help.
I am trying to insert id 354 as the follower of 350. Any suggestions what I can try please?
<?php $id = $_SESSION['userID']; if (($_GET['do'] == 'follow') && !empty($_GET['id'])) { // check if user is logged in if (($_SESSION['auth']) && !empty($_SESSION['current_user_id'])) { // whatever your $_SESSION variable is for logged in users if ($_SESSION['current_user_id'] == $_GET['current_user_id']) { // other checks here to determine various ID's are numeric, etc. $sql = "INSERT INTO `follow` (`user_id`, `follow_user_id`) VALUES (". (int)$_SESSION['current_user_id'] .", ". (int)$_GET['id'] .")"; if (!mysql_query($sql)) { if (mysql_errno($link_identifier) == 1062) { //$link_identifier is necessary to avoid conflicting error notices due to multiple openning/closing SQL connections // duplicate attempt to follow // handle accordingly } } } } } ?> </div> <div class="forminputcell"> <div class="datainput"> <div class="forminputleft"> Follow: </div> <div class="followbutton"> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?do=follow&id=354"><img src="/images/follow.png" class="submit-button"/></a> </div> </div> </div> </div> <?php echo $id; ?> <br> <?php echo $current_user_id; ?> <br> </div>
-
Cheers dude.
I have around 15 columns to search so it could get long!
$where .= "`firstname` LIKE '%$keyword%' OR `surname` LIKE '%$keyword%'";
-
Thanks,
When I try that it stops the code from working.
foreach($keywords as $key=>$keyword) { $where .= "`firstname` AND `surname` LIKE '%$keyword%'"; if ($key != ($total_keywords - 1)) { $where .= " AND ";
-
Hi,
I will be using a template but I plan to use 3. One for each user group. For example the Xbox one will feature the official Twitter feed. The Playstation will feature the official Playstation feed etc. However with this it makes the navigation harder.
If I had just one profile I can just echo the users data onto the one profile page. But using 3 profile pages makes the navigation harder.
For example if the user logs on to the homepage and they want to view their profile how can I determine what of the 3 profile templates it will be. Like I say the simplest method seems to be to echo the user type into the link.
-
Hi,
I have search script which will only search one row at a time. The first two codes below work however the third fails to work but I am using the same code to query the two rows for the results string.
Can anyone advise how search more than one row at a time?
This searches firstname
$where .= "`surname` LIKE '%$keyword%'";
This searches surname
$where .= "`surname` LIKE '%$keyword%'";
This search fails
$where .= "`firstname`, `surname` LIKE '%$keyword%'";
<?php function search_results ($keywords) { $returned_results = array(); $where = ""; $keywords = preg_split('/[\s]+/', $keywords); $total_keywords = count($keywords); foreach($keywords as $key=>$keyword) { $where .= "`surname` LIKE '%$keyword%'"; if ($key != ($total_keywords - 1)) { $where .= " AND "; } } $results = "SELECT `firstname`, `surname` FROM `users` WHERE $where"; $results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0; if ($results_num === 0) { return false; }else{ while ($results_row = mysql_fetch_assoc($results)) { $returned_results[] = array( 'firstname' => $results_row['firstname'], 'surname' => $results_row['surname'], );
-
Hi,
The plan is two have 3 profile pages. Each with a different design. Making 3 pages, each with its own design sounds very simple compared to having one single page which is generated based on a query.
-
Hi,
I am an amateur PHP programmer but I am learning all the time(some would argue). My site will have 3 user groups and I originally planned to have 3 different tables, 1 for each user group. The navigation of my site would be based on set links making the navigation easy. However as a number of people have pointed out I should use one table which I have now adopted. This however creates a problem with the navigation.
The best solution I can think of is to echo the user type (which I am collecting) into the link.
For example:
(current link) www.website.com/profiles/xboxprofile.php - I would then echo all the content based on Xbox designed profile
(new link) www.website.com/profiles/<php echo $usertype; ?>profile.php
The thing I haven't used this process before.
The only other method I can think is to use lots of if statements and echo different designs onto the page however this sounds very complicated and more time consuming to set up.
Any suggestions please from professional programmers?
-
Thanks everyone. Got there.
function trim_array($ar) { return array_map("trim",$ar); } if(isset($_POST['form_id'])) { $_POST = mysql_real_escape_array($_POST); $_POST = trim_array($_POST); if($error == "") { $newpassword = trim($_POST['resetpassword']); $md5password = md5($newpassword); $sql = " UPDATE users SET password = '$md5password'"; $result = mysql_query($sql) or die("An error occurred ".mysql_error()); } }
-
Hi,
I am issuing a random password in the previous script. The purpose of this script is to allow someone to change their password from the random password. I can log in using the random password.
$random_password=md5(uniqid(rand()));
-
Thanks mrMarcus,
But I'm not sure what you mean by "Why are you hashing 'resetpassword'?"
What I currently have...someone can register with a password, if they reset their password a random password is emailed to them which they can continue to use if they wish. If they want to change it to their own password they can.
I thought this piece of code allows someone to add their own password in the 'resetpassword' field which then inserts it into the database in a hashed MD5 format. Is that not the case? Im not sure where the identical password issue comes into it?
-
I also contacted my host about the php.ini and they said that it is set up to return all errors in the code. Hope they are telling the truth!
-
Muddy Funster, you might want me to trade childish insults with you but Im not going to. It is complicated. Espectially for someone with no coding experience before. Saying someone has learning difficulties is just childish and silly. If you've nothing good to say then its not worth hearing.
But like I keep saying my site is improving all the time. I just keep getting stuck thats all.
For example I've just trying to finish a password reset script. It to literally 2 minutes to set it up to enter a plain text password but when I apply MD5 it says:
An error occurred Unknown column 'd41d8cd98f00b204e9800998ecf8427e' in 'field list'
To me it looks logical enough. I am saying that the input from the field is resetpassword which I want to be converted to MD5. Im then saying that I want it to be string $newpassword which I want to insert into password.
Like I said it took literally two minutes to set it up to accept plain text but when I try to add MD5 I get stuck.
<?php $errors = array(); $success = array(); function mysql_real_escape_array($t) { return array_map("mysql_real_escape_string",$t); } function trim_array($ar) { return array_map("trim",$ar); } if(isset($_POST['form_id'])) { $_POST = mysql_real_escape_array($_POST); $_POST = trim_array($_POST); if($error == "") { $newpassword = md5('resetpassword'); $sql = " UPDATE users SET password = $newpassword"; $result = mysql_query($sql) or die("An error occurred ".mysql_error()); } } ?> <div class="registerinfopagecell"> <div class="registerpageheaderorganiser"> Choose a New Password </div> <div class="registerform"> <form class="form_id" class="appnitro" method="post" action=""> <ul > <div class="forminputcell"> <div class="datainput"> <li class="li_1" > <div class="forminputleft"> Your New Password: </div> <div class="forminputright"> <input name="resetpassword" type="text" class="field" width="600" /> </div> </li> </div> </div> </li> </div> </div>
-
Actually I cant wait to show my site. I think its a cracking idea. I did some research and found a site operating in a different country which turned over $6.25m last year.
-
Just give up, MrMarcus: You're only wasting your time. As Jessica said the OP either cannot learn, or he doesn't want to learn and is just trolling. I'm not quite sure what would be the best, but either way trying to "help" him is a utter and complete waste of time.
Its not a waste of time. My site is really coming together and Im learning new things all the time. Its improving every time I work on it.
-
Hi MrMarcus,
This is looks very good but its getting very complicated. Lets say the first person joins would their ID automatically be added to the table 'follow' or would it be when the first person follows them.
Why is it best to have seperate table for followers?
-
I know for a fact you've been told to research normalization, and you've also been spoon-fed information on proper normalization. You consistently ask questions about the same thing you've already been told how to handle it.
Dogs have this thing where they are unable to generalize concepts. Are you a dog? Because that might explain why you need to be told every time to normalize your data, and stop pooping everywhere.
As we have discussed a few points can you please be specific in what this related to. This could be a useful exercise to learn this normalization wizardy you speak of.
-
The plan is to use 'follow', 'follow1', 'follow2' etc... and when a user clicks the follow button their ID number enters into the next available follow row.
Its the only way I can think of doing it.
-
Oh right so its the php.ini file I need to change. Thanks.
How can I get a user to follow another user. I need seperate the ID of the profile against the ID of the person who is logged in.
-
Hi,
The plan is that User 123 can insert there ID into the follow row of User 456. Is that how its done?
Currently it only lets User 123 follow 123 but its getting there.
-
By validating that the user submitting the follow is logged in, and using their id.
So it will only accept the logged in users ID? Sounds fine. I shall give that a go. I need to change it so that I can view another users profile and follow them. Currently it only allows my to follow myself but its getting there.
-
Hi,
I have added this the HT Access file but it creates an internal server error. Does anyone know why this is please?
ini_set('display_errors',1);
-
So how would I stop someone from saying that someone wants to follow someone when then dont want to?
Currently I can make 321 follow 456 when 321 did not click the follow button.
-
I notice that I can change the follower id in the link.
So I can change the ID from 323 to 324. To stop this do I just amend the HT Access file so this information is not visible?
followtest.php?do=follow&id=324
Code Only Fully Works On Page Refresh
in PHP Coding Help
Posted
Hi,
I have the following code which only fully works when I refresh the page.
When I click the button it only inserts the $followerid into the database. However when I press F5 to refresh the page it inserts both the $profileid and $followerid
It seems quite strange and I haven't seen an issue like this before. It some sort of silly mistake does anybody know?