Jump to content

justlukeyou

Members
  • Posts

    957
  • Joined

  • Last visited

Posts posted by justlukeyou

  1. 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?

     

     

    
    <?php
    
     $followerid = $_SESSION['userID'];
     $profileid = $row['id'];
    
    
      $error = "";
    			   if($error == "") {
    				    // other checks here to determine various ID's are numeric, etc.
    				    $sql = "INSERT INTO `follow` (`user_id`, `follow_user_id`) VALUES ('" . $profileid . "', '" . $followerid . "')";
    
        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>
     <?php echo $profileid; ?> Profile ID <br>
     <?php echo $followerid; ?> Follower ID <br>
    </div>
    
    
    
    
    
      <div class="followbutton">
       <a href="<?php echo $_SERVER['PHP_SELF']; ?>"><img src="/images/follow.png" id="followbutton" class="submit-button"/></a>
        </div>
    

  2. 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
    						    }
    				    }
    		    }
    }
    ?>
    

  3. 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>
    

  4. 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.

  5. 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'],	
    );
    

  6. 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?

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

  8. 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?

  9. 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>
    
    
    

  10. 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.

  11. 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.

  12. 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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.