Jump to content

Drongo_III

Members
  • Posts

    579
  • Joined

  • Last visited

Everything posted by Drongo_III

  1. This should do the job. I got this very nifty regex off someone on here.
  2. Hi Guys Bit of an odd one. I've created a custom 500 error page and my hosting company has told me that they've made the necessary httpd.conf changes. The thing is - how do you simulate a 500 server errror? I've tried throwing an exception but this did nothing. I've also tried breaking a htaccess file but this doesnt display my custom page, which leads me to think that the configuration hasn't been setup properly. But as I'm not sure if this is a valid way to test it I thought I would get some advice. Any helo would be appreciated! Drongo
  3. It would be funny if it wasn't so stupid lol... I will go now and lash myself in the garden to twenty minutes. Sowwy!
  4. Perhaps you can point out where i'm doing it wrong? The below code doesn't work. <!doctype html> <html> <head> <script type="text/javascript"> var mylink; function init(){ mylink = document.getElementById('link1'); alert(mylink.id); myLink.onclick = myFunc; } function myFunc(){ alert('click worked'); } </script> </head> <body onload="init();"> <a href="#" id="link1">Click me</a> </body> </html> But if I replace that init function with a direct call to document.getElement (as per below) it works fine. So I am just trying to understand either what I am doing wrong or whether there is some fundamental precept of javascript i am missing (probable)... function init(){ //mylink = document.getElementById('link1'); //alert(mylink.id); document.getElementById('link1').onclick = myFunc; } And thanks for this mate but this is a different type of event registration. I am trying to work out why the traditional model doesnt seem to work for me
  5. Thanks for that. But it wasn;t so much that I couldnt get the event to work, or that I couldn't register the event in another way. What I was driving at is to try and understand why it works with document.getElementById but not when I simply use a resource (i.e. set a var with document.getElement... and then assign it to the event). Any ideas why that may be?
  6. I may stand corrected here but at least one issue is that you are trying to pass an entire array to your switch statement, which as far as I am aware isn't possible. A switch usually takes a single value to evaluate against. So you might want to do a foreach statement and run the switch in a function that can be called on each iteration.
  7. Hi Guys I have been a jquery junky for a bit too long and neglected much of the raw javascript behind it...hence this simple question. When I try to register an event in the format of : element.onclick = funcName; the only way I can get this to work is with: document.getElementById('elementId').onclick = myFunc; Whereas if I try and give this event a handle (below) it doesn't work at all and I get an 'undefined' error in console even though it plainly is defined. But surely these two statements amount to exactly the same thing? var someElement = document.getElementById('elementId'); someElement.onclick = myFunc; // This doesn't work So what am i missing? Thanks, Drongo
  8. Could anyone help with this one please?
  9. Hello I have a quick question. I want to make a custom 500 error page. I understand this is achieved by tweaking httpd.conf file to direct to a specific file in the event of a 500 error. What I want to know is if I make a html 500 error page should this be located on another server? The logic being that if the server can't render any of the normal pages on a site due to a 500 error why would it be able to render my customer 500 page. Does that make sense? And whats the best practice here? Thanks, Drongo
  10. Worked it out now. Seems you have to declare that the first array level is an array too: var locObj = []; locObj[1] = []; locObj[1]['top'] = 'twinky' alert(locObj[1]['top']); Just thought I would post back in case anyone else gets stuck on something similar. Though why you can't just write it like php is hard to fathom - still that's javascript for ya!
  11. Hi Guys Super simple question. I want to create a multidimensional JS array where I can define the keys. Perhaps my mistake is using similar syntax to php but the following code throws an error in chrome console saying "Uncaught TypeError: Cannot set property 'top' of undefined " Can anyone nudge me in the right direction on this? var locObj = []; locObj[1]['top'] = 200; alert(locObj[1]['top']);
  12. Best way to do it... There are lots of methods for achieving this but all depends on how complex you want to make it. If you need the fields to be draggable or sortable then you may opt for a different option but what follows is a simple example to highlight how easy it is. Just as a quick illustration (and i am typing this directly in so sry if it doesn't work) <form> Country: <input type="text" name="someField" value="WHATEVER" onblur="this.style.border='0px'; setAttribute('readonly','true')" onfocus="this.style.border='1px solid black'; removeAttribute('readonly','0')"> </form>
  13. Your logic should look something like this: if(isset($_POST['email'])) { $to = 'YourEmail@host.com'; $subject = 'Your Subject Line goes here'; $message = $_POST['message']; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); } You can add in additional headers etc. which is all explained here - http://php.net/manual/en/function.mail.php But that should get you started. You probably want a better way of checking if the form has been submitted - i just used $_POST email for an example.
  14. Wouldn't advise using mysql anymore - it's deprecated. Use MySQLI or PDO. Have you tried some debugging. I would suggest some of the following: echo out the crypted password and username after you set them and manually compare them to what you have in your database try tweak your query so you are only selecting the username, then only selecting the password - this might give you some idea of what variable is failing to match
  15. Hi Guys I need to setup a MySQL user account so I can connect (using PHP) both on the server where MySQL resides and remotely from another server (these are load balanced servers). I read a MySQL article here: http://dev.mysql.com/doc/refman/5.1/en/adding-users.html - this seems to suggest in order to do this I would need to setup two user accounts as follows: CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass'; GRANT ALL PRIVILEGES ON MyDB.sometable TO 'monty'@'localhost' CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass'; I am not overly familiar with creating users so apologies for the noob questions about to follow: Is it correct that I need to setup two users with the same username only one as localhost and one with wildcard to be able to use the database locally and remotely ? Rather than use a wildcard would it be more secure to use the remote server's IP - i.e. 'monty'@'SomeIPaddress'? Do I need to grant privileges on the second user - i.e. 'monty'@'%' . Or does this account inherit the same privileges from 'monty'@'localhost'? I would obviously not grant all privileges either but the above is just for simplicity. Is that all I need to do? Thanks Drongo
  16. Hi guys I implemented the code above as per the solution given but I seem to have a strange issue. when I set outlook 2007 to receive plain text email only and perform a test send outlook seems to ignore the plain text version in the email and simply defaults to a plain text version it seems to derive from the html version. has anyone seen this happen before and is to the code or something to do with outlook?
  17. Ahh I see. I need to go do some reading me thinks! Heard of phpmailer but not used it - probably should check these out but I am the worst person for wanting to do it all myself to learn how it works ha! There's a control freak in all of us I guess Anyway thank you very, very much for the help!
  18. You should probably download an ftp program such as filezilla to push files to your server - never used notepad++ for it but I wouldnt trust the results tbh. Also, to my knowledge, you cannot execute php code without a server. If you want to run php code locally you'll need to download something like WAMP server (http://www.wampserver.com/en/) which you can install and run as a server on your computer. This will then let you execute your php scripts. WAMP is insanely easy to install. Hope that helps!
  19. Lachild thank you so much for your response. That fixed it all and now works perfectly. I'm now very happy As you've highlighted the mime type to me the penny kind of drops. So I guess 'multipart/related' might be used for things like attachments? Christian - thanks for the tip. To be honest I was just working from examples on php.net which isn't overly expansive but I guess I'm looking in the wrong place for descriptive info on this. I shall check out RFC article.
  20. This is probably going to centre around two main functions. Firstly file_get_contents (http://www.php.net/manual/en/function.file-get-contents.php) to grab the page data. You can enter a url as the file name. Then you'll want to break out your regular expressions and use a function such as preg match (http://php.net/manual/en/function.preg-match.php). This returns an array of matches.
  21. Hi Guys I am trying to setup an email template that contains both a html and plain text version in one. What follows is a simplified version but what I want to do is simply have both versions in an email template and then run a str_replace which will populate the template's place holders with the relevant data before sending - this is why I want everything in a single file. But before I get to that point I simply need to get the email working - however at present when I run the code below I just get blank output in the email body. If anyone could propose a reason why this is happening it would be appreciated. Incidentally I realise the mime boundary isn't ideal - this is just for testing. <?php $headers = "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/related; boundary=\"boundaryMarker\"\n"; $headers .= "Content-Transfer-Encoding: 7bit\n"; $body = " --boundaryMarker\n Content-Type: text/plain; charset=\"charset=us-ascii\" \n Content-Transfer-Encoding: 7bit\n\n THIS IS PLAIN TEXT EMAIL \n\n --boundaryMarker\n \n\n Content-Type: text/html; charset=ISO-8859-1\n Content-Transfer-Encoding: 7bit\n\n <h1>THIS IS HTML VERSION</h1> \n\n --boundaryMarker--\n "; $to = 'MyEmail@Myemail.com'; $subject = 'This is a test message'; mail($to, $subject, $body, $headers);
  22. Hi Kick Sorry it has taken a while to respond to this. Lets assume that this isn't possible to setup - because I have very limited control over the hardware in this instance. As a way of doing it via php would perhaps ftping the files via php's ftp functions be a possible solution? Any reasons you would advise not using this?
  23. Thanks Jessica You give me too much credit and I can't in fact see from the time stamps what the dates are... However you did give me cause to check what I was doing with the dates and it appears it wasn't the output that was the problem but there was some test code messing up the strtotime conversion earlier in the code. So thank you for prompting me to check that.
  24. Hi Guys Posted on here a few days ago about sorting a multi dimensional array based on date. I thought I had it working but now i realise it doesn't appear to be sorting correctly. Essentially I have an array that is combined from feeds from twitter and facebook. I converted the dates using strtotime and the unsorted array looks like this: print_r($socialMediaArray); ( [0] => Array ( [date] => 1359214851 [message] => some message [from] => twitter ) [1] => Array ( [date] => 1358991499 [message] => some message [from] => twitter ) [2] => Array ( [date] => 1358799273 [message] => some message [from] => twitter ) [3] => Array ( [date] => 1387741833 [message] => some message [from] => twitter ) [4] => Array ( [date] => 1387490401 [message] => some message [from] => twitter ) [5] => Array ( [date] => 1357263343 [message] => some message [from] => facebook ) ) I then ran the following code to try and sort on date order function cmp ($a, $B) { return $a['date'] - $b['date']; } usort($socialMediaArray, "cmp"); // Sort the array by date order. echo "SORTED ARRAY <pre>"; print_r($socialMediaArray); SORTED ARRAY Array ( [0] => Array ( [date] => 1357263343 [message] => some message [from] => facebook ) [1] => Array ( [date] => 1358799273 [message] => some message [from] => twitter ) [2] => Array ( [date] => 1358991499 [message] => some message [from] => twitter ) [3] => Array ( [date] => 1359214851 [message] => some message [from] => twitter ) [4] => Array ( [date] => 1387490401 [message] => some message [from] => twitter ) [5] => Array ( [date] => 1387741833 [message] => some message [from] => twitter ) ) But when I then convert the dates back into something readable it becomes apparent that the dates haven't been sorted correctly as they come out as Fri Jan 04 1:35:43 Mon Jan 21 20:14:33 Thu Jan 24 1:38:19 Sat Jan 26 15:40:51 Thu Dec 19 22:00:01 Thu Dec 19 22:00:01 I'm not overly familiar with using usort, hence why I posted here, so if someone could offer up a possible reason as to why this may be happening it would appreciated. Many thanks, Drongo
  25. Thanks very much guys that worked a treat. I was getting massively confused because I thought I have to pass $a and $b and I couldnt quite see how I would make that dynamic - over complicating it clearly!
×
×
  • 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.