Finish Final Stage of Social Networking Button
Results 1 to 3 of 3

Thread: Finish Final Stage of Social Networking Button

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    12

    Finish Final Stage of Social Networking Button

    Hi,

    I am trying to complete a button which allows someone to follow somone else. It is designed to be a social networking button. I could get the button to work whever the page is loaded which is highly undersirable but I cant make it work when the button is pressed.

    I have really stuck on this, does anyone have any suggestions on what I can try to get it to work.

    Code:
    <?php
     
    	
    
     $followerid = intval($_SESSION['userID']);
            $profileid  = intval($row['id']);
    		
    
    	
    if(isset($_POST['followbutton']) && $_POST['followbutton'] == 'true'){
    
    
    	if($profileid =  $followerid) {
            $errors['profileid'] = "This is a test error.";
        }
    
    
    
    if(!$errors){
            //Validation of input vars passed, attempt to run query
            //Force vars to be ints to be safe for query statement
    
    		
    		    $followerid = intval($_SESSION['userID']);
            $profileid  = intval($row['id']);
    
            $query = "INSERT INTO `follow` (`user_id`, `follow_user_id`) VALUES ('{$profileid}', '{$followerid}')";
            $result = mysql_query($query);
    
    		
            if (!$result)
            {
                    $errors[] = "Query: {$query}<br>Error: " . mysql_error();
    
            }
    	}	
    	}
    	
    	
    ?>

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,410
    First and foremost: Stop Using the MySQL Extension!.

    Have you tried debugging the code at all? For example, have you at least tried:

    1. Tracing through the code (using a debugger preferably; can also be done with echo statements placed throughout the code) to determine which branches you're getting into?
    2. Outputting variables of interest (especially external variables) either directly or, if contained within an array (e.g. $_POST), by examining the array altogether via print_r(). Note that var_dump() can be used to get even more information on what a variable contains.
    3. Outputting the SQL query and visually inspecting it.
    4. Checking to see if mysql_query() indicated an error has occurred and, if so, outputting the error message provided by MySQL (see mysql_error()).

    ?

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    12
    Thanks,

    I have tried to use PDO before but I just dont understand it. I dont understand how it is similar or to differs to MySQL.

    I have tried option 2 and it echoes all the values I was expecting. How can I use Option 1. What is a debugger?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •