Jump to content

TrickyInt

Members
  • Posts

    16
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by TrickyInt

  1. I don't know any basic php i really need someone to give me the code ready please. Thanks much appreciated.

     

    Then go ahead and learn it. You will have a hard time finding someone willing to program for you without paying.

    Besides, it's great to know a programming language - and also fun and interesting to learn. ;)

  2. Have you a way to store/save users "cart"?

     

    If not, you could save the ID of the items, in an array, which you save in the users session.

     

    Then you could go through all the ID's in the array, to quickly show everything.

     

    When deleting you could use the array search function, perhaps?

    <?php
    	session_start();
    
    	// Item ID's in cart
    	$_SESSION['cart'] = array('1', '3');
    
    	$cart = $_SESSION['cart'];
    
    	// Add new item to cart
    	array_push($cart, '4') // This adds 4 to the end of array so cart now contains 1, 3 and 4.
    
    	// Remove item
    	if(($key = array_search('3', $cart)) !== false) {
        	unset($cart[$key]);
    	} else {
    		// Not found in cart
    	}
    
    	// Go through all items in cart
    	if(count($cart) > 0) {
    		foreach($cart as $id) {
    			// Do something with the item id..
    		}
    	}
    ?>
    

    I haven't tested the code above, so it's probably either not working, or just bad. But it can give an idea/starting point.

     

    Good luck ;)

  3. Hi!

     

    It's actually pretty easy to be making such, if you know how to make a login/register system.

     

    If you can't/never made a login/register system, then learn it - and then make the other.

     

    2 tutorials:

     

    http://www.sunnytuts.com/article/login-and-registration-with-object-oriented-php-and-pdo - Easy and short. Bad security, but great for starting out.

     

    - Great and advanced tutorial.

  4. Just be aware its not something your going to learn over night. It's a programming language. In fact, I would forget whatever project plans you have for the moment, and just spend a few months at least getting your head around the basics.

     

    http://www.phptherightway.com

     

    Yeah, especially if you have no programming knowledge prior to this. It really makes life easier, when learning new languages.

     

    You would also lack in experience, if learning it so fast. If only one could cope/paste experience... :)

  5. Jacques1:

    The PDO one could also be done like this:

    <?php
    $books_stmt = $database->prepare('
        SELECT
            title
        FROM
            books
        WHERE
            author = ?
            AND EXTRACT(YEAR FROM publication_date) = ?
    ');
    $books_stmt->execute(array($author_id, $publication_year));
    
    foreach ($books_stmt as $book)
    {
        echo html_escape('The title of the book is ' . $book['title']);
    }
    ?>

    I'd go with PDO over MySQLi. I was too using the old Mysql_*, and just started learning PDO 2 weeks ago. I swiched to PDO, afted trying MySQLi.

     

    I found MySQLi to be harder to learn, and with less and worse tutorials.

     

     

    And Jacques01, this: "I think people only do it because the name sounds familiar." is very true. Did that myself ;)

  6. Are you guys joking?

     

    In mathematics, we have this thing called multiplication. PHP can do it, too:

    $_SESSION['cart']['weight'] += $_POST['cartquantity'] * $row['weight'];
    

    But it's not a good idea to add the total weight in the session, anyway. What if the user reduces the quantity? Then you have a lot of trouble getting the exact weight difference and reducing that number again.

     

    Store the quantity and calculate the totals when needed.

     

    Ahaha, yeah, your right.

    I'm tired.

  7. Hey.

     

    Just recently got into developing with PDO and OOP, instead of the old MySQL_*, so I'm pretty new, and have some dumb questions.

     

    Right now I'm taking the first steps into making a blog (Nope, not a blogger - just need something to work on), and i came across a tutorial to create a database class. I have spend a little time on making such a class, and though I got it working just fine, I'm not really sure how useful and necessary it really is. Yeah, of course it saves you a couple of lines, but at the cost of getting used to using the class, instead of just raw PDO.

     

    Here is the class i just quickly made:

    <?php
    	class database {
    		private $host	=	DB_HOST;
    		private $user	=	DB_USER;
    		private $pass	=	DB_PASS;
    		private $dbname	=	DB_NAME;
    		
    		public function __construct() {
    			// Try connection or die.
    			try {
    				$this->db 	= 	new PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->user,$this->pass);
    			} catch(PDOException $e) {
    				die($e);
    			}
    		}
    		
    		public function getColumn($sql, $params) {
    			// Get value of a single row
    			$query	=	$this->db->prepare($sql);
    			$query->execute($params);
    			return $query->fetchColumn();
    		}
    		
    		public function fetch($sql, $params) {
    			// Return fetch
    			$query	=	$this->db->prepare($sql);
    			$query->execute($params);
    			return $query->fetch();
    		}
    		
    		public function update($sql, $params) {
    			// Update
    			$query	=	$this->db->prepare($sql);
    			$query->execute($params);
    		}
    		
    		public function getRows($sql, $params) {
    			// Return number of rows
    			$query	=	$this->db->prepare($sql);
    			$query->execute($params);
    			return($query->rowCount());
    		}
    		
    		public function insert($sql, $params) {
    			// Insert
    			$query	=	$this->db->prepare($sql);
    			$query->execute($params);
    		}
    	}
    	
    ?>
    

    I know it can get way more optimized, advanced and usefull, but it's just a quick example.

     

    Is it just dumb to spend time on a database class, or is it worth the time? Any advice appriciated.

     

     

    Thanks in advande!

  8. You haven't Session_start() on your login.php page, neither on your auth_check.php page - so it cannot access anything from it.

    Maybe you should just add session_start() in your common.php file, if it's included at the top of every other page/file?

     

    Good luck ;)

  9. Your example would be pretty bad, if you just have a while to go through all posts made, and show them on for example your frontpage - then it would both show the new and old version of the post.

     

    You could add a new table, for history posts, or you could add a new column in your existing table, called something like post_history, and then only, on your frontpage, show post where post_history == 0.

  10. Do the print_r() after you have built the array, not every time you add an element.

    while($row=mysql_fetch_assoc($result)){
        $riders[] = $row['rider_name'];
    }
    echo '<pre>', print_r ($riders, 1), '</pre>'; // output is easier to read this way
    

    And you should use mysqli functions, not mysql, or you will soon be in for a lot of rewriting when the mysql functions are no longer available

     

    PDO is also viable. I personally found it easier to learn.

  11. Hello!

     

    Because users aren't able to change session data, i think it is safe enough - but of course, pretty much anything can become even more secure. There is though the risk of session hijacking.

     

    But you could re-check if the user is admin, whenever the user performs a admin only task - like deleting another using or so.

    Something like this:

    <?php
    $query = $db->prepare("SELECT group FROM users WHERE userid = ?");
    $query->execute(array($_SESSION['userid']));
    $r = $query->fetch();
    
    if($r['group'] == 1) {
    echo 'Approved';
    } else {
    echo 'Not admin';
    }
    ?>
    

    Probably not the best code, but it gives you an idea.

    I would run this when performing the admin-only task, and when showing the links, buttons or whatever you have, which links to the page, which performs the action, i would just check whether the $_SESSION['gruoup'] is equal to admin/1.

  12. So you were how old when you made your first website? 7? 6?

     

    Yeah, i think so. Maybe 8. ;)

     

     

    Welcome! It's really great that you're starting this young. And you're also lucky that "nerds" and "geeks" are more popular than they were when I was your age ;)

    Good luck with your coding :)

     

    Thanks you. But is it really young to start programming, at the age of 15?

  13. Hey!

     

    So, i'm gonna introduce myself. Never an easy one? What do say, and what not to. Well, never been good at this, but i'm gonna give i a shot;

     

    So first of, i'm not from America, Canada, or any English speaking country. I'm from Denmark, and while i'm really happy living here, it just suck to not have English as primary language. So first of, this is probably the reason for all the gramma mistakes here - which you by now probably have noticed.

     

    So who am i?

    Well, i'm a 15 year old boy from Denmark, as said. I go to school, and do homework, as kids do. But in my freetime i enjoy spending time on my precious computer, and anything related.

    I've always been defined as a "nerd" by my friends, probably because of my love for math, computer and science.

     

    I created my first website shortly after i learned to read and write, but of course with a WYSIWYG editor. But while this keept me entertained, i did always wan't to do something more. Then i heard about this coding thing, and i wanted to learn it - and so i tried. The first thing i ever really coded by myself, was a homepage for my parent i HTML - which they said were great, but obviously it wasn't.

     

    I keept on having fun coding from back then to now, which haven't really been that much time - so i'm still really a beginner. Now i'm just also a newb at PHP. So i'm still learning, at least i'm trying to do so.

     

    At the moment i'm working on a browser game for me and a couple of friends, which is really fun to make - and i enjoy making it, and i enjoy coding. Coding is great.

     

     

    I'm hoping the dumb questions i, without discussion, am gonna ask, is too stupid.

     

     

    Hoping to see you on the forum,

     

    Kind Regards,
    TrickyInt.

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