Jump to content

justlukeyou

Members
  • Posts

    957
  • Joined

  • Last visited

Posts posted by justlukeyou

  1. Hi,

     

    I have a code which inserts a value into a cell when there is a standard button. However I cannot make it work when I use an image as the button. Can anyone advise/quote how I can use an image as a button?

    <form method="post" enctype="multipart/form-data">
    <?php
    // make sure session is started before anything else
    if (!isset($_SESSION)) session_start();
    ?>
    
    
    
    
    <?php
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'follow') {
    
        $profileid  = (int)$_GET['ID'];
        $followerid = $_SESSION['userID'];
    
        if ( !($profileid > 0 && $followerid > 0) ) {
            $errors[] = 'Bad call. You might need to login.';
        } else if ($profileid == $followerid) {
            $errors['sameprofile'] = "You cannot follow your own profile.";
        } else {
            // check if already following
            $query = mysql_query("SELECT * FROM follow WHERE user_id = $profileid AND follow_user_id = $followerid");
            $duplicatefollow = null;
            if (mysql_num_rows($query) > 0) {
                $duplicatefollow = 'You Already Follow This Profile.';
                $errors['duplicatefollow'] = "You Already Follow This Profile.";
            } else {
                $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();
                }
            }
        }
    }
    
    
    
    
    
    $loginprofile = intval($_SESSION['userID']);
    
    $query_rsSearch = "SELECT * FROM follow WHERE `follow_user_id` = '$loginprofile'";
    $rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
    $row_rsSearch = mysql_fetch_assoc($rsSearch);
    $totalRows_rsSearch = mysql_num_rows($rsSearch);
    
    // no need to have php end tags if it's the last thing in a file.
    // you risk getting the "headers already sent" error
    
    
    ?>
    
    
    <div class="followbuttonbox">   
    <input name="followbutton" type="image"  />
    </div>
    </form>
    
    <?php
     
    $profileid = (int)$_GET['ID'];
    $followerid = $_SESSION['userID'];	
    
    
    $query = mysql_query("SELECT * FROM follow WHERE user_id = $profileid AND follow_user_id = $followerid"); 
    
    $duplicatefollow = null;
    if (mysql_num_rows($query) > 0) 
    { 
    $duplicatefollow = 'You Already Follow This Profile.'; 
    }   
    else
    {
      
    if(isset($_POST['followbutton'])) {
    
    
    $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();
    	}
    }  
    }     
      
             if(($profileid) == ($followerid)) {
    $errors['sameprofile'] = "You cannot follow your own profile.";
    }
      
      $loginprofile = intval($_SESSION['userID']); 
      
      $query_rsSearch = "SELECT * FROM follow WHERE `follow_user_id` = '$loginprofile'";
    $rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
    $row_rsSearch = mysql_fetch_assoc($rsSearch);
    $totalRows_rsSearch = mysql_num_rows($rsSearch);
     
    
            
    ?>
    
    
    
    
    <form method="post" enctype="multipart/form-data">
    <div class="followbuttonbox">   
    <input name="followbutton" type="image" type="submit" src="/images/follow.png"   />
    <input name="followbutton" type="submit" value="Follow Button" />
    </div>
    </form>
    
  2. Hi,

     

    I have added this which returns the error message however I cant work out how to stop the duplicate input.  Can anyone who knows PHP able to advise how to stop the PHP insert once the error message runs?

     

     

        $query = mysql_query("SELECT * FROM follow WHERE follow_user_id  = '". $followerid ."'");
    $duplicatefollow = null;
    if (mysql_num_rows($query) > 0)
    {
    $duplicatefollow = 'You Already Follow This Profile.</a>.';
    }   
    
     
    if(isset($_POST['followbutton'])) {
    
    
    $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();
        }
    }       
     
  3. Hi,

    I am trying to come up with a way of stopping duplicate inserts from being into a table. I have got this point which creates an error message for duplicate follows but I am stuck on what to try next. Any suggestions please?

     

    As far as I can tell I need something in the insert code that says if the value is already in the table it cannot be re-inserted and then echo the message.

     

     

     

    $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();
    
        }
    
    }
    
    
    
    if(($profileid) == ($followerid)) {
    
    $errors['sameprofile'] = "You cannot follow your own profile.";
    
    }
    
    
    
    $loginprofile = intval($_SESSION['userID']);
    
    
    
    $query_rsSearch = "SELECT * FROM follow WHERE `follow_user_id` = '$loginprofile'";
    
    $rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
    
    $row_rsSearch = mysql_fetch_assoc($rsSearch);
    
    $totalRows_rsSearch = mysql_num_rows($rsSearch);
    
    
    
    $duplicate = $profileid;
    
    
    
    
    
    if(($loginprofile) == $row_rsSearch['follow_user_id']) {
    
    $errors['duplicatefollow'] = "You already follow this profile.";
    
    }
    

     

    I have this across a number of pages so I should be able to re-use it quite often.

  4. I have it now so that it only runs when the button is pressed however I want to remove the button and only use the image. Any suggestions please? (Almost there with it)

     

     

    <code>

    <div class="followbuttonbox">

    <a href="<?php echo $_SERVER['PHP_SELF']; ?>?ID=<?php echo $profileid; ?>"><img src="/images/follow.png" name="followbutton" type="submit" /></a>

    <input name="followbutton" type="submit" value="Follow Button" />

    </div>

    </code>

  5. Hi,

     

    I have been trying to make this work for 3 months now. Firstly I got it working only when the page is loaded. Now it works when both the page is loaded and the button is pressed.

     

    But I just cant seem to make it work only when the button is pressed.

     

     

    I somehow need to match these two parts together but I cant seem to be able to do it.

    <code>

    if($ID != "") {

     

    <input name="followbutton" type="hidden" id="followbutton" value="followbutton" value="true" />

    </code>

     

    <code>

    <form action="" method="post" enctype="multipart/form-data">

    <?php

     

    $ID = mysql_real_escape_string($_GET['ID']);

    $followerid = intval($_SESSION['userID']);

    $profileid = $ID;

     

     

     

    if($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();

    }

     

    }

     

     

     

    ?>

     

     

     

    <div class="followbuttonbox">

    <a href="<?php echo $_SERVER['PHP_SELF']; ?>?ID=<?php echo $profileid; ?>"><img src="/images/follow.png" /></a>

    <input name="followbutton" type="hidden" id="followbutton" value="followbutton" value="true" />

    </div>

    </form>

    </code>

  6. Sorted.

     

    I tried do this earlier but put the $accounty = Y; in the wrong place.

     

     

    $accounty = Y;	
    $loginPassword = md5($loginPassword);
    $query = 'SELECT * FROM users WHERE email = "' . mysql_real_escape_string($loginEmail) . '" AND password = "' . $loginPassword . '" AND accountconfirmed = "' . $accounty . '"';
               $result = mysql_query($query);
    

  7. Oh right, so I need something like this? ....

     

    But this still allows me to login into unconfirmed accounts.

     

           $query_rsSearch = "SELECT * FROM users WHERE `email` = '$emailAddress'";
    $rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
    $row_rsSearch = mysql_fetch_assoc($rsSearch);
    $totalRows_rsSearch = mysql_num_rows($rsSearch);
    
       $accounty = ('Y');
    
       // Login attempt
       if(isset($_POST['loginSubmit']) && $_POST['loginSubmit'] == 'true')
       {
           $loginEmail = filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL);
           $loginPassword    = trim($_POST['password']);
           $accounty = $row_rsSearch['accountconfirmed'];
    

  8. Hi,

     

    I dont understand what you mean. If their account is not confirmed I dont want a user to log in. Are you suggesting that I let someone logging in even if they have not confirmed their account?

     

    I do not know how to block a user from logging in if they have not confirmed their account.

  9. But I dont know how to stop them from logging in.

     

     

    $emailAddress = $_POST['email'];
    
    $query_rsSearch = "SELECT * FROM users WHERE `email` = '$emailAddress'";
    $rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
    $row_rsSearch = mysql_fetch_assoc($rsSearch);
    $totalRows_rsSearch = mysql_num_rows($rsSearch);
    
    $activeStatus = $row_rsSearch['accountconfirmed']; 
    
    if($totalRows_rsSearch == 0) {
    $errors['loginEmail'] = "Your email address is not registered";
    } else {
    if($activeStatus != "Y") {
    
    $errors['confirmedaccount'] = "Your account has not yet been confirmed. Please request a confirmation email.";
    }
    }
    
    

  10. Thanks,

     

    I have now got it like this. It returns the correct error messages when someone has not confirmed their account but only their enters their email address. However it does block someone from logging in when they enter both their email address and password.

     

    How would I block someone from logging in if their account is not confirmed?

     

     

    $emailAddress = $_POST['email'];
    
    $query_rsSearch = "SELECT * FROM users WHERE `email` = '$emailAddress'";
    $rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
    $row_rsSearch = mysql_fetch_assoc($rsSearch);
    $totalRows_rsSearch = mysql_num_rows($rsSearch);
    
    $activeStatus = $row_rsSearch['accountconfirmed'];
    
    if($totalRows_rsSearch == 0) {
    $errors['loginEmail'] = "Your email address is not registered";
    } else {
    if($activeStatus == "Y") {
    //'Y' MEANS ACCOUNT HAS BEEN ACTIVATED - SHOW WEBSITE
    
    } else {
    //ACCOUNT HAS NOT BEEN ACTIVATED YET .
    $errors['confirmedaccount'] = "Your account has not yet been confirmed. Please request a confirmation email.";
    }
    }
    

  11. Hi,

     

    It is 21:45 and I have spent 8 hours today trying to finish off my login page. The last stage is stop someone from logging in if their account is not confirmed. This is the closest I have got to it.

     

    If the user has confirmed their account it should have a Y in the 'accountconfirmed' row.

     

    Can anyone please advise how I return a message and block someone from logging into an unconfirmed account?

     

    $accounty = ('Y'); 
    
    $query_rsSearch = "SELECT * FROM users WHERE `accountconfirmed` = '$accounty'";
    $rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
    $row_rsSearch = mysql_fetch_assoc($rsSearch);
    $totalRows_rsSearch = mysql_num_rows($rsSearch);
    
    if($totalRows_rsSearch != 0) {
    $errors['confirmedaccount'] = "Your account has not yet been confirmed.  Please request a confirmation email.";
    }
    

  12. Hi,

     

    This is the all the code. It is not returning any error messages. It logs in and does everything fine. If you wanted a user to be able to check if their email address is in the table how would you do this? I cant wee why what I am trying to do doesn't work.

     

    
    <?php
         if ($_SESSION['userLoggedIn'])
    
            session_start();
           $_SESSION['userLoggedIn'] = 0;
           $_SESSION['userEmail'] = '';
           $_SESSION['userID'] = '';
    $_SESSION['userfirstname'] = '';
    $_SESSION['usersurname'] = '';
    
           // Reset errors and success messages
           $errors = array();
           $success = array();
    
    
       // Login attempt
       if(isset($_POST['loginSubmit']) && $_POST['loginSubmit'] == 'true')
       {
           $loginEmail = filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL);
           $loginPassword    = trim($_POST['password']);
    
    		$accounty = ('y'); 
    
    
           if(count($errors) === 0)
           {
    $loginPassword = md5($loginPassword);
    $query = 'SELECT * FROM users WHERE email = "' . mysql_real_escape_string($loginEmail) . '" AND password = "' . $loginPassword . '" AND accountconfirmed = "' . $accounty . '"LIMIT 1';
               $result = mysql_query($query);
               if (!$result)
               {
                   die('Invalid query: ' . mysql_error());
               }
    
               if(mysql_num_rows($result) === 1)
               {
                   $row = mysql_fetch_assoc($result);
                   $_SESSION['userLoggedIn'] = 1;
                   $_SESSION['userEmail'] = $loginEmail;
                   $_SESSION['userID'] = $row['id'];
                   $_SESSION['userfirstname'] = $row['firstname'];
    			$_SESSION['usersurname'] = $row['surname'];
    
                   header('Location: /test/board.php');
                   exit;
               } else {
                   $errors['login'] = 'No user was found with the details provided.1.';
               }
           }
       }
       /*
         The rest of your login page code
       */ 
    
     // Reset errors and success messages  
       $errors = array();  
       $success = array();  
       // Login attempt  
       if(isset($_POST['loginSubmit']) && $_POST['loginSubmit'] == 'true'){  
           $loginEmail = trim($_POST['email']);  
           $loginPassword  = trim($_POST['password']);  
    
       }  
    
    
      	if(!isset($loginEmail) || empty($loginEmail)) {   
           $errors['loginEmail'] = "Please enter your email address.";
       }	  
    
    if(!isset($loginPassword) || empty($loginPassword)) { 
           $errors['loginPassword'] = "Please enter your password.";
       }
    
    
    
    $accounty = ('Y'); 
    
    
    		  if(($accounty) != ($row['accountconfirmed'])) {
           $errors['confirmedaccount'] = "Your account has not yet been confirmed.  Please request a confirmation email.";
       } 
    
    			  if(($loginEmail) != ('email@yahoo.com')) {
           $errors['incorrectemail'] = "Your email address is incorrect.";
       } 
    
    	  	 if(($loginPassword) != ($row['password'])) {
           $errors['incorrectpassword'] = "Your password is incorrect.";
       } 
    
    
    
       ?> 
    

  13. Hi,

     

    I am trying scan my table on the login page to detect an email address but I dont know what code I should use to read a row.

     

    If I enter "emailaddress@yahoo.com" in the form it does return the error message. However if enter "hello@yahoo.com" it returns the error message.

     

    			  if(($loginEmail) != ('emailaddress@yahoo.com')) {
           $errors['incorrectemail'] = "Your email address is incorrect.";
       } 
    

     

    However when I try do to the following it is not scanning the table. Can anyone advise how I scan the table to determine if an email address in table?

     

    if(($loginEmail) ($row['email'])) {

    $errors['incorrectemail'] = "Your email address is incorrect.";

    }

    {/code]

  14. Thanks,

     

    I changed that but it has had no affect. I have tried to echo the two ID numbers in different places. The thing is the second set of ID numbers do not echo. I cant understand why though as the third set do echo.

     

    Any suggestions please why this may be?

     

    echo $profileid;
    echo $followerid;
    
    
    if(isset($_POST['followbutton']) && $_POST['followbutton'] == 'true'){
    
    
    
    
    echo $profileid;   	    THIS DOES NOT ECHO
    echo $followerid;           THIS DOES NOT ECHO
    
    
    
    
    
    
           $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();
    
                   }
           }       
    
    
         		echo $profileid;
    echo $followerid; 
    

  15. Hi,

     

    The form starting here. Should I starting it here?

     

       <form action="" method="post">
    <a href="<?php echo $_SERVER['PHP_SELF']; ?>?ID=<?php echo $profileid; ?>"><img src="/images/follow.png"   /></a>
    <input type="hidden" id="followbutton" name="followbutton" value="true">
    </form>
    
    

     

    When I echo 'profileid' and 'followerid' I get the two different ID number which Im expecting but I just cant seem to insert them into the database when the button is pressed.

     

     

  16. Hi,

     

    I am trying to complete a social networking button but I just cant sort one last peice of out. When I remove the following piece of code the social networking button works just by visiting the page.

     

    Does anyone have any suggestions on how I can get this peice of working. To be totally honest I dont even know what its supposed to be doing. The concept is to only run when the button is pressed. Am I making it to complicated?

     

    if(isset($_POST['followbutton']) && $_POST['followbutton'] == 'true'){
    

     

     

    <?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();
    
           }
    }	
    }
    
    
    
    ?>
    
    
    
    
          <?php if($errors['profileid']) print '<div class="invalid">' . $errors['profileid'] . ''; ?>  
    
    
    
    </div>
    <div class="followbuttonbox"> 
    <a href="<?php echo $_SERVER['PHP_SELF']; ?>?ID=<?php echo $profileid; ?>"><img src="/images/follow.png"  id="followbutton"   /></a>
    <input type="hidden" id="followbutton" name="followbutton"  value="true">
    <submit button>
    </form>
    

  17. Hi,

     

    Do I need a form to the link. I cant add a query to the end of the link such as /test/searchoutput.php?search=green-widgets.

     

    So Im a bit confused what the next step is. I have tried Googling but nothing suitable seems to come up.

     

    I have tried "search database with link" etc

×
×
  • 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.