Jump to content

hansford

Members
  • Posts

    562
  • Joined

  • Last visited

  • Days Won

    4

Posts posted by hansford

  1. You are only calling a static method of the class. In order to call the constructor you need to create an object of the class.

    use foo as foo;
    
    //\foo\foo_bar::foo();
    $foo = new \foo\foo_bar();
    $foo::foo();
    
    class foo_bar {
    
    	function __construct() {
    
    		$this->foobar();
    
    	}
    
    	public static function foo() {
    
    		print('This is foo');
    
    	}
    
    	public function foobar() {
    
    		print('<br />This is foobar');
    
    	}
    
    }
    
    
  2. Looking over the code....

     

    If $_GET['id'] is not set, then none of the variables are going to be defined.

    $row is defined twice and only the second definition counts.

    Put in some echo's to see what is going on along the code path.

            $row=mysqli_fetch_assoc($result);    
                
            $run = mysqli_query($conn,$sql);    
                
            $row=mysqli_fetch_array($run);
    
  3. $output = array(
    'data'=>array(
    '500020315'=>array(
    'members'=>array(
    array('account_name'=>'zebra'),
    array('account_name'=>'gazelle'),
    array('account_name'=>'chiken'),
    array('account_name'=>'antelope')
    ))));
    
    
    usort($output['data']['500020315']['members'],function($a, $b) {
    
        $c = $a['account_name'];
        $d = $b['account_name'];
    
        if($c == $d) return 0;
        else if($c > $d) return 1;
        else return -1;
    });
    

     


  4.  

    "cleaning the URL",Totally and in a nut shell:

    1.You must use rawurlencode() for parts that come before "?" 

    2.Use urlencode for all GET parameters (values that come after each "=")(POST parameters are automatically encoded).

    3.Use htmlspecialchars for HTML tag parameters and HTML text content


    <?php
    $url_page = 'example/page/url.php';
    //page the link will request
    $text = 'this is a simple string';
    $id = '4334%3434';
    $linktext = "<Clickit> & you will see it";
    //text of the link, with HTML unfriendly characters
    ?>
    <?php
    // this gives you a clean link to use
    $url = "http://localhost/";
    $url .= rawurlencode($url_page);
    $url .= "?text=" . urlencode($text);
    $url .= "&id=" . urlencode($id);

    // htmlspecialchars escapes any html that
    // might do bad things to your html page
    ?>
    <a href="<?php echo htmlspecialchars($url); ?>">
    <?php echo htmlspecialchars($linktext); ?>
    </a>
  5.  

    @hansford, I changed the data type to BLOB, however, it stores the file as kind of binary file (see attached image please).

     

    That is what it's suppose to do. It's a database, not a file system. In order to convert it back into a file, you need to write that data to a file with the proper file extension of whatever it used to be before you placed it in the database.


  6. define('br','<br />');

    $lists = array(
    array('id'=>'g','total'=>33,'goal'=>100),
    array('id'=>'c','total'=>20,'goal'=>50),
    array('id'=>'e','total'=>3,'goal'=>5));

    $mid_array = array();

    $highest_id = '';
    $i = 0;

    foreach($lists as $list)
    {
    $id = $list['id'];
    $total = $list['total'];
    $goal = $list['goal'];
    $percent = ($total / $goal) * 100;

    $mid_array[$i]['id'] = $id;
    $mid_array[$i]['percent'] = $percent;
    $i++;
    }

    usort($mid_array, function($a, $b){

    $c = $a['percent'];
    $d = $b['percent'];

    if($c == $d) { return 0; }
    if($c < $d) { return 1; }

    return -1;
    });

    foreach($mid_array as $arg)
    {
    echo $arg['id'] . ' ' . $arg['percent'] . '%' . br;
    }
  7. My Opinions:

    When you bunch up your code like that it makes it difficult to follow and see where errors may be occurring.

    I would enclose conditional statements within braces. Less prone to errors as what happens if you decide to add an additional statement.

    If a function or variable name is more than one word long...each successive word should start with a capital letter or an underscore should be used between words for clarity.

    function checkTitle( $title )
    {
        if(strlen($title) > 55)
        {
            return getMsg('Title Is Too Long');
        }
    
        if(! preg_match('/[a-z]/', $title))
        {
            return getMsg('Title Is All Caps');
        }
    }
    
  8. To get it back into array format you could do something like so:

    $path = 'path to file goes here';
    
    $fp = @fopen($path, 'rb');
    
    if($fp === false)
    {
        echo 'failed to create/open csv file';
        exit;
    }
    $start = true;
    $headers = array();
    $multi = array();
    
    while(($data = fgetcsv($fp,4095)) !== false)
    {
        if($start)
        {
           $headers = array_values($data);
           $start = false;
           continue;
        }
        // combine headers with data array to form associative array
        $multi[] = array_combine($headers, $data);
    }
    
    print_r($multi);
    
  9. I knew I was missing stuff. The code is very difficult to follow.

       if (strlen)($password)) > 20) {    // if (strlen($password) > 20)
                            $error[] 'Username is too long';
                    }
                   
                    $login = login($username, $password);
                    if login ==== false) {   // if (login === false)
                            $errors[] = "That username or password is incorrect. Please try again.";
    
                    } else if {  // No conditional statement.  should be only else and not else if
                            $_Session['user_id'] = $login;  //as mentioned $_SESSION['user_id'] = $login;
                            header('Location: index.php');
                            edit();
                    }
    
  10. This part of the code is not going to work.

       if (strlen)($password)) > 20) {    // if (strlen($password) > 20)
                            $error[] 'Username is too long';
                    }
                   
                    $login = login($username, $password);
                    if login ==== false) {   // if (login === false)
                            $errors[] = "That username or password is incorrect. Please try again.";
                    } else if {
                            $_Session['user_id'] = $login;
                            header('Location: index.php');
                            edit();
                    }
    
  11. I would be checking this part of the code based on some known username, password and status of both Y and N.

    echo out the value of $row['active'];

    Personally, I wouldn't use a character for this column to compare. I would use a Boolean value of 1 or 0;

    if ($result) { // If uname and password match
    		while($row = mysqli_fetch_assoc($query)) {
    			if ($row['active'] == 'N') { // Account is not active
    				echo "<p>Your account has not been activated! Please check your email inbox.</p><br />";		
    			} else if ($row['active'] == 'Y') { // Account is active
    				$_SESSION['uname'] = $_POST['uname'];
    				header("Location: /profile");		
    			}
    
×
×
  • 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.