Jump to content

mogosselin

Members
  • Posts

    116
  • Joined

  • Last visited

  • Days Won

    1

mogosselin last won the day on September 23 2014

mogosselin had the most liked content!

Contact Methods

  • Website URL
    http://markonphp.com

Profile Information

  • Gender
    Male
  • Location
    Montreal

mogosselin's Achievements

Newbie

Newbie (1/5)

4

Reputation

  1. If it works perfectly, where is the problem then? What do you have trouble with? You don't know where to start? With just one line of code you can append a line in a file. Checkout: http://php.net/manual/en/function.file-put-contents.php You need to use the FILE_APPEND flag. Like: file_put_contents ("file.dat" , $linetoadd , FILE_APPEND);
  2. What do you mean by 'CRUD' with OOP? Do you mean using PDO? Or you mean learning how to do a CRUD on a DB AND learning OOP at the same time? If it's the last, you should probably break up the learning process. Search for PHP and OOP on Google. Then, search for PDO insert, PDO update, PDO select, etc. If it's the first, simply search for PDO insert, PDO update, etc. I have some tutorials on my site about PDO (simple insert), but not on every CRUD parts.
  3. Are you talking about a Filezilla server or client? Also, the find command returns multiple results, not sure how it would work with a command to open it. It would probably just open the last or the first one? (I'm not a Linux expert). And do you have a graphic interface where you can see the 'stars' where the password should be? If yes, maybe there's a tool that would 'unstar' the password.
  4. What do you use to edit your PHP file? Check the the files the editor creates are encoded in UTF-8. Is UTF-8 your default charset with PHP? Check with phpinfo(); the value default_charset Do you use header('Content-Type: text/html; charset=utf-8'); ? Do you use any string functions on the data before echoing it?
  5. Are you sure $prices and $prices[$i] are arrays? Check with is_array(). This 'illegal string offset' error often happens when someone tries to access a string as if it was an array. You could try something like: if (!is_array($prices)) trigger_error('$prices is NOT an array!', E_USER_ERROR); if (!is_array($prices[$i])) trigger_error('$prices[$i] is NOT an array!', E_USER_ERROR); ... your code here ... You should never 'silence' errors. This is done only by lazy programmers that doesn't care about doing their job correctly. A good programmer should find where the error comes from, understand it and make it disappear by using proper code (except in sore rare occurrences where it's OK to silence an error: a bug that you can't correct from PHP or an external library, which is uncommon).
  6. Tip: you can use the <> icon in the tool bar to post your code, so that it will have syntax highlight and will be easier to read. The first step for you would be to try to achieve the result in pure / hardcoded HTML first. Try to do this, then try to apply it to your PHP code.
  7. It's hard to help you without 'real' data or at least, really knowing what you want to do. So far, I understand that: You have 2 different databases You have 1 table about a user in DB1? And a second table about all the users in DB2? Than, something gives you an array in an array in an array... The parts that are missing to help you: What's the structure of the tables in DB1 and DB2 that you're trying to query? What is the information you're trying to get from the DB? What's the actual code that produce this array you posted in the first message? And what's the format in which you're trying to display the data? (show an example of a desired result)? Or what are you trying to do with the data in the arrays? What's your 'process' you're talking about? If you can answer those questions, it'll be way easier to help you
  8. Like @requinix said, you can check if the line you added in the .htaccess is present in the HTTP header when you call the files. To do that, use the tab 'Network' in Google Chromes' Developer tools (or other developer tools on other browsers). The HTTP header is something that you don't 'see' when you look at a web page, but it is always present when you ask for a web page.
  9. Another way to put it... When the user clicks on a link (or a button) to see their message, you're going to issue a request to output this message. Something like: SELECT * from Message WHERE id=3 ... or whatever. Then, right after you did this request, do another one that will update this row: UPDATE message SET read=true WHERE id=3 There's also something called a 'Trigger' in MySQL... so you could do it directly on the database and you wouldn't need any code, but this doesn't work with a SELECT (insert, delete and update only). So, there's no way to know if a row has been read except to update something right after you've read it.
  10. Hi! There's a 'code' button in the toolbar where you wrote your post. You can edit your post and paste your code in the little box that will appear. Your code will be much more easier to read. Now, it's kinda hard to see, and I'm not talking about that green font there
  11. It seems to me like you're fairly new to PHP and you're trying to do something with Joomla? If you don't understand the error messages and you're 'playing' with Joomla, it's normal that you're lost... Also, if you copy a piece of code and put it there in the hope that it'll work (without understanding how it works), well... the changes are that it won't work All the code that you copied from the timezone thing isn't necessary. You just need something like: date_default_timezone_set('America/Los_Angeles'); You should choose the timezone of your PHP server from the list here: http://php.net/manual/en/timezones.php Don't just write 'Los_Angeles' if your server isn't in the same timezone, you'll end up with weird results. All the rest of the code in the example is just meant to check if the timezone you set in your code is the same as in your INI settings. When I say "ini settings", it means your PHP configurations. Do you know where your php.ini file is and what it contains? For the other error message, it's similar to the popular 'Headers already sent' error. The 'Header' is something that your server will send to the browser requesting the page. But, the header needs to be first, before any content is sent. And, the header contains cookies (and cookies are used to manage sessions). So, if you send content to the browser (like with a echo "hello", or a blank space, etc.), and then you try to add a cookie, it won't work. The header was already sent... If you want a detailed explanation on how this work, I already wrote a post about it (it's not the exact same error, but it's similar). That being said, why are you using Joomla? Can't you just start with plain PHP and do a simple 'contact form' or any other simple application? It would be, IMO, a better way to start with PHP.
  12. Also, depending on the number of users you want to send emails to, you should check the possibility to use an external newsletter service. You'll need to pay for it, but it will be more reliable. If you send a lot of email from a single web mail server, you could get 'banned' from gmail, yahoo, etc... And some of your emails could end up in the spam directory more easily than if you use a mailing service. Just my 2 cents
  13. For the Google API, I think that for the free version you need to display Google Map on your page to query their API with that kind of request. But, you can also get it with HTML5: http://diveintohtml5.info/geolocation.html Which will probably require some Ajax on your part because it's on the client side. And, the user will need to approve the geolocation request (depending on his settings).
  14. If I would translate the error message to 'human error message': You tried to call the method 'GET' on a variable... Normally, when you call a method with ->, it's for an object. But you tried to call it on a variable that is not an object. It's hard to tell because your code isn't complete, but it probably comes from this line: $check = $this->_dddd->get(.......) It's the only place where you have a 'get'... My guess would be that _dddd is still null. And since 'null' is not an object and you try to call GET like if it was, that's probably why you get that error.
  15. The error you get has to do with this code: $stmt = $handler->prepare('INSERT INTO calendar_event (title,short_desc,full_desc,date) VALUES (:title, :short_desc, :full_desc, :date)') ; $stmt->execute(array( ':title' => $title, ':short_desc' => $short_desc, ':ful_desc' => $full_desc, ':date' => date('Y-m-d') )); More specifically, the 'placeholders' like :title, :short_desc, etc... When you try to bind the parameters of your query with actual values, PDO/PHP will throw an error at you if you don't have the right amount of 'parameters' to replace the placeholders. For example, if you have a query like: 'SELECT * FROM user WHERE username = :username and title = :title' and you try to bind the parameters like this: $stmt->execute(array( ':title' => $title )) PHP won't be happy, because the :username is not there. It will then throw you this error: Invalid parameter number: number of bound variables does not match number of tokens Same thing if you make a mistake while typing your placehodlers VS the name that you pass in the array. If for the same request I would do: $stmt->execute(array( ':title' => $title, ':usernameWithATypo' => $username )) Notice how ':usernameWithATypo' is not the same as the ':username' we had in our query.... If you do this, PHP won't be happy and will throw you a similar error message: Invalid parameter number: parameter was not defined in We could argue that the 'Invalid parameter number' isn't technically OK, because we sent the right amount of parameters expected, only one that wasn't correctly spelled... but still, that's the error that PHP will throw. As for catching the errors that PDO sends, it's true that it's not a good practice. What you want to do in your 'live' website, is to display a nice error page to your users. To do this, you can use the method 'set_exception_handler' - Also, here's a post I wrote about it if you're interested to know more. So, in summary, you probably don't need the 'try catch' for PDO exception and you can just let them 'bubble up'. And, if you specify a function with set_exception_handler', this function will be called each time an exception is raised and not catch. Which makes it way easier
×
×
  • 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.