Jump to content

ckrudelux

Members
  • Content Count

    565
  • Joined

  • Last visited

Everything posted by ckrudelux

  1. Php is on the server side and can only send data to the client. If you want to delay output or make anything after the page has been loaded javascript is the language to use. It runs on the client side and can manipulate the page after loading
  2. Yeah, since in your example you have a string witch both have text content and data content. You will have to seperate the two part some how. Either by having them in two different variables, remove parts of the string or to split it. There are several ways to do this. $txt = 'A long string'; $datastr = '1,2,3,4,5'; echo $txt . $datastr; explode(',',$datastr);
  3. Say what? php requires a dilimiter then exploding if you have a long.string you will need to extract the data portion before exploding the string into an array $txt = 'A long string 1,2,3,4,5'; explode(',', $txt); outputs an array like this: ['A long string 1', '2', '3', '4', '5'] You can use functions like substr to extract the string protion you need before you use explode to remove unwanted text.
  4. Hm, looked at my own files and noticed that I have this in the top. Does it solve the issue? I think I gave up trying to find what was wrong and just tried this and left it like that. <?php error_reporting(E_ALL); ini_set("display_errors", "on");
  5. Maybe it's an error reporting level. My code doesn't halt if I echo something that doesn't exist. If I rember correctly I think I had some similar issue until I change the error reporting level. This is also a neat trick in php 7 like isset but without all the extra work echo $var ?? 'default value';
  6. Nothing wrong with the code above (Just not so reusable). To think of is: that user input don't go raw in the SQL query (mysqli or PDO makes that easy) and not outputting raw user input/data to the browser by using for example htmlentities function.
  7. ckrudelux

    System shop

    We won't do the work, but we can guide you and help you with finding out where the problems are. I'm guessing cause you didn't post any code. You don't have any PHP knowledge so start to read about PHP and how that works. You should be able to figure out by your own how to build what you want after that. If you have an issue related to your code or coding practice we are here to help. Good luck
  8. In php you get the URI params by the $_GET variable. In your case you would use $_GET['model'] in php to get the value of model value.
  9. If it's something simple why not just simply make PHP draw a image that looks like the HTML output. If you want take a screenshot of the whole site, it's going to be a different story, might be web services you can use. To capture the screen you could make a bash script taking a screen shot of the server entering the site.
  10. ckrudelux

    System shop

    Try writing in English and people might be more interested in helping out with what ever problem your are facing.
  11. You should use htmlentities before displaying it on the page, not before you add it to the database. The database needs escaping so it won't interfer with your query.
  12. @ means that it suppress any error triggered by that expression. https://www.php.net/manual/en/language.operators.errorcontrol.php
  13. ckrudelux

    Php Exceptions

    To answer my own question remember the namespace. This will make things work much smoother
  14. ckrudelux

    Php Exceptions

    Should it matter from there I catch an exception? This works and catches the PDO exception from users $dice = new Dice(); try { $dice->create('Controller'); }catch(Exception $e){ } Try to catch the exception in the controller wont work class Controller { public function __construct(Users $users){ try{ $users->create('username','password'); }catch(Exception $e){ } } }
  15. How would I unset a cookie with an unknown path? What I'm trying to do is to automate the task of removing the session if nothing is stored in the session variable. But I'm trying to implement so that I could use different sessions in different folders which makes the path more or less unknown. I know this might not be a good way of doing it but still I'm curious to know.
  16. I been thinking for a long time about how to treat DB with PHP in a good way. I get stuck at if I should have a method creating the tables the class needs or I just create the table manually then I would need the class in a project. So I started to search a bit on the topic and got some articles about data mappers which uses a class to do the bidding between the program and the database. Article: http://www.slideshare.net/vlucas/building-data-mapper-php5-presentation Still I feel like I haven't found any good answers to my question on how the DB should be implement, maybe I just thi
  17. Oh.. should have thought about that.. thank you very much
  18. This is the exact code but it should be the same as the example. private function updateChildren(Menu $menu){ if(count($menu->getItems())){ if($insert = DB::PDO()->prepare("INSERT INTO `menu` (`label`,`path`,`parent`) VALUES (:label, :path, '". intval($menu->getID()) ."')") && $update = DB::PDO()->prepare("UPDATE `menu` SET `label`=:label, `path`=:path WHERE id=:id")){ foreach($menu->getItems() as $item){ if($item->getID()){ if($update->execute(array("label"=>$item->getLabel(),"path"=>$item->getPath(),"id"=>$item->getID()))){ $this->up
  19. PHP is a server side language and can not interact with the html.You can look at it like php is writing you a html file and then sends it to the browser. What you do is you create an other php file which disblays the description of your insect <tr> <td><a href="descriptionpage.php?insect=<?php echo $row['insect_id']?>">Description</a></td></tr> You can retive the insect key with this variable on you description page: $_GET['insect']
  20. <?php $pdo = new PDO(...);$insert = $pdo->prepare(...);$update = $pdo->prepare(...); $items = array(...); foreach($items as $item) if($item->id) $update->execute(...); else $insert->execute(...); The value of $insert becomes TRUE while $update becomes a PDOStatement object.Why doesn't both of them become a PDOStatement?
  21. My late second post. Have been away visiting my grand parents.I've been looking into my collection class and came up with a method making it possible to extend my SQL query. So then extending my collection class I can setup my query from the constructor using the methods: addTables, addColumns, addConditions, setColumnID and setObjectName all of these are protected methods and are only for setting up the query. This would look something like this then extending the collection class public function __construct(){ $this->addTables("`table1`"); $this->addColumns("`table1`.*"); $this->se
  22. ckrudelux

    Project Blog

    IntroductionSo I finally decide to have a go with this idea of having a project blog I'm really bad at this sort of thing and often find my self working for hours not writing a single line of comment to my code.. I don't find it necessary cause my naming often tells what it does so I don't see the point typing out the same thing the name says. But maybe I just lake the guide lines of typing comments.. read once that if you have to think twice about what a code you written does you need a comment for it. I will be doing a MVC pattern system. I've already started with this project so the first p
  23. ckrudelux

    OOP and MYSQL

    Might have done some over thinking on how I wanted things to look like while still wanting a new point of view. I had a look at the PDO again and yes it might suite the need I'm looking for. I just couldn't place it in my thoughts and it felt wrong. Thanks for the answers I got
  24. ckrudelux

    OOP and MYSQL

    CollectPerson is storing the Person object just look in the while loop and you will see the assigning of the object to the persons property. I haven't used PDO cause I never used it before I don't really know why I should either. I understand that I could use any database I want with the same function but that isn't really needed for me at this point. Auto escaping sure it's a good thing but I could simply write my own instead of loading the hole PDO class.
  25. ckrudelux

    OOP and MYSQL

    Yes that is kind of what I do now but I fetch the array from the object collecting the result so I know that I made the query for it. I would still need to validate the data (Just haven't thought about it yet). But at least I could be sure the data is from table a and not b or isn't made up. I know it still could be over written but then it would be on purpose and not by sending the wrong array into the mix. I just feel is something else I missed something simpler I haven't thought of.
×
×
  • Create New...