Jump to content

fredyap1234

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

fredyap1234's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi guys, I'm reviewing a piece of small web application and the current application does not have any error / exception handling capability. If there is any error, it would simply show an error message followed by die;. I'm planning to implement a simple exception handling class to handle the errors. What I'm thinking is a simple redirect when an error is being caught together with an error code that correspond to an error message in a simple flat text file. The error page will then show an error message that corresponds to the code. Here's what I have so far. Would appreciate if the PHP experts here would give simple pointers to enhance it. <?php class MyException extends Exception {} try { throw new MyException("error.php"); } catch (MyException $e) { $file = $e->getMessage(); header("Location: $file?e=1"); } ?> This is what I have on my error.php page <?php $errorcode = $_GET['e']; function getErrorMessage($errorcode) { $errors = file("english.txt"); foreach ($errors as $error) { list ($key,$value) = explode(",",$error,2); $errorArray[$key] = $value; } return $errorArray[$errorcode]; } echo "Test <br />"; echo getMessageMap($errorcode); ?> As you can see here, exception class would redirect user to error.php if an error is caught together with a GET variable on the URL. On error.php page, it would GET the error code and then run it through a function to get the error message of the corresponding error code and then echos it out. Was wondering if this is a good practice? My ultimate goal here is to avoid displaying the error message itself on private includes file. Thank you in advance for your suggestions.
  2. Hi guys, I have a form and in this form is a long drop down list which is called category. Problem is that this drop down list is somewhat long and I felt that users may take a long time to scroll and read through each category before they pick one. Previously, I used a text box to get the category from users before saving it into database. But however, there is a consistency issue. For example, a user may specify category as "jack and jill" while others may specify it as "jack & jill". (One use the word 'and', while the other used the ampersand symbol.) As such it is not very consistent and I have switched to using drop down list. But over time, the category drop down list grew in size and it's somewhat annoying to go through the whole list to pick a category from the drop down. So I would like to ask you guys for opinion if there are other alternative for long drop down list? I'm thinking of alternatives like autocomplete, etc. What do you guys think of it? Thanks in advance.
  3. Hi guys, I'm a beginning self learner in PHP and I'm looking for a solution to one of my problem. I've got a book from A-press recently for beginner and I'm trying out some of the tutorials in it. For now my php project have a class and there's an object that accesses the class' method. $n->showname(); However, I would like to assign this to a variable and perhaps push it into an array. This is how I did it. $name = $n->showname(); This is not working of course and you guys are probably laughing at me now. So is there any other solutions for this if I were to insist on placing it into a variable? Is it a good practice? Don't get me wrong guys, I'm not expecting an easy spoon-fed answer. Perhaps a good hint would be more than helpful. Thanks in advance guys. Fred
×
×
  • 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.