Jump to content
Larry Ullman's Book Forums

Necuima

Members
  • Posts

    359
  • Joined

  • Last visited

  • Days Won

    7

Everything posted by Necuima

  1. Hi Larry, Sorry, I should have included the following: My current environment is: . Windows 7 Home Premium 64 bit . Internet Explorer 10 . Firefox 22.0 . Dreamweaver CS5 as the text editor . Xampplite 1.7.3 which comprises: .. Apache 2.2.14 .. PHP 5.3.1 .. MySQL 5.1.41 .. PHPMyadmin 3.2.4 WAMP seems to offer both 32 bit and 64 bit options but Bitnami seems to offer easy options to add say Wordpress. etc.. XAMPP seems to offer an included upgrade facility. I am a bit unclear as to Apache and MySQL which I understand run as services. Will these need to be uninstalled first before installing the newer versions? Again, I'll appreciate any advice and I'm looking forward to doing the exercises in my new book :-) Cheers from Oz, Necuima.
  2. Hi, I have just bought this book and would like to use current versions of PHP, MySQL etc. My current localhost environment is via XAMPPLITE 1.7.3 which has been stable and met all my needs so far. XAMPPLITE 1.7.3 comprises: .. Apache 2.2.14 .. PHP 5.3.1 .. MySQL 5.1.41 .. PHPMyadmin 3.2.4 But I am tempted to upgrade to more current versions of the localhost environment. Can you recommend either WAMP or the full XAMPP or BitNami? As I have data in current MySQL database tables, will I need to do anything special (apart from backups) to make sure I don't lose them? Any advice will be appreciated. Cheers from Oz, Necuima.
  3. Thank you both for your advice - I will do as you both suggest. I forgot to mention that I also always use Larry's 'escape-data' process. Cheers from Oz.
  4. Hi, Today someone tried to inject some invalid data into a contacts database table. The data fields are just VARCHARs. Fortunately I had enough checks in there to prevent the insertion. But I hastily put together the following PHP data checks to try and strengthen the defences. Are they sufficient? Is there a better way? Note: there are no particularly sensitive data in this database but I'd like to prevent any 'bad' data being put into the database table. function test_for_invalid_data($data) { // the following are 'needle in haystack' tests - stristr does a case-insensitive check if ((stristr($data, 'href') === FALSE) && (stristr($data, 'http') === FALSE) && (stristr($data, '<a') === FALSE) && (stristr($data, 'link') === FALSE) && (stristr($data, 'url') === FALSE) && (stristr($data, '</a') === FALSE)) { // 'needle' strings not found - good! return TRUE; } else return FALSE; } Any advice will be most appreciated. Necuima.
  5. After playing around with this, it only works for numbers that fit into the numeric data types used. If you put in a too-large number, the result is garbage!
  6. I was interested to format the loan amount when the result of the mortgage repayment calculation is displayed and I came across this code (which I modified a little). And thanks to the author whose name I don't know. It takes a value in a double and returns a string formatted for currency with two decimal places. Thought I'd post it for what it's worth. #include <string> std::string formatCurrency(double dv) { const std::string radix = "."; const std::string thousands = ","; const std::string unit = "$"; unsigned long v = (unsigned long) ((dv * 100.0) + .5); std::string fmt,digit; int i = -2; // number of decimal places - DO NOT CHANGE!! do { if(i == 0) { fmt = radix + fmt; } if((i > 0) && (!(i % 3))) { fmt = thousands + fmt; } digit = (v % 10) + '0'; fmt = digit + fmt; v /= 10; i++; } while((v) || (i < 1)); std::string rv; rv = unit + fmt; return rv; } Cheers from Oz.
  7. Hi, I came across this post which might help : http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice Cheers
  8. Found it!! Somehow 'compatibility view' was clicked in the tools drop-down box. As soon as I unclicked that, everything returned to normal. Is it OK to leave this post here in case someone else encounters the same problem? Thanks, Necuima.
  9. It seems that I am needing help a bit lately and I hope that I am not over-doing it! Suddenly, for no reason that I can ascertain, images displayed in an HTML table, which is generated by PHP, are ignoring the associated CSS parameters, but only in IE9 and IE10. Works perfectly in Firefox. I am assuming that there is an error somewhere in the CSS which causes IE browsers to ignore those parameters, but so far I have been unable to find the error. Here's a bit of the code: echo "<tr> <td align='left'><input type=\"checkbox\" name=\"checked_trans[$key]\" value='$woa_name' /></td> <td align='left'> $gal_name</td> <td align='left'> $woa_name</td> <td align='left' class='table_icon'><img src='$icon_file_name'></td> <td align='left' class='woa_image'><img src='$woa_file_name'></td> </tr>"; and here's the CSS: .admin_table td, .admin_table th { border: 1px purple solid; font-size: 75%; vertical-align: top; } .admin_table tr { color: black; } .table_icon img { width: 40%; } .woa_image img { width: 50%; } The problem is that the 'woa_image' is not scaling to fit the width of the table column. The image is 1100px wide and scales to 50% of the table column width in Firefox, but does not scale at all in either IE9 or IE10. Can anyone advise where I am going wrong? And why this suddenly may have started? Any help will be most appreciated. Necuima.
  10. Hi HartleySan, Terrific - FYI I implemented the src filename extension in PHP rather than JavaScript and it works fine. The extension was only needed for the image that had been changed so I did not apply the extension to the file names of the other images to avoid cluttering up the cache area. Many thanks for the guidance. Cheers from Oz, Necuima.
  11. Hi Christopher, I had a similar problem a couple of years ago - my local host is via XAMPPLITE. I don't know about a MAC, but for windows you can just download and install 'fake sendmail' from www.glob.com.au and follow the instructions. After installing it, you have to adjust the sendmail.ini parameters to your environment. It worked fine for me. I hope that there is a MAC version. Cheers from Oz, Necuima.
  12. I fear that I have mis-led you and also that I am not understanding your advice. Let me try and be a bit clearer - both script A and B are basically PHP scripts with JavaScript 'pieces'. Both use Larrys' PHP redux approach. Script A displays jpg images based on a database table. The data are jpg images, the file names of which are in the database. The jpg image files are on the server. A user can then select an image for changing. Once selected script A sends the key of the database record to script B. Script B displays the image pointed to by that database table row and allows the user to select a replacement image. Larry's file move/upload logic is employed. The name of the jpg image is not changed thus there are no changes required to the database table itself. Once the replacement jpg image has been uploaded to the server file system, control is returned to script A which again displays the images pointed to by the database table records allowing the user to select another image for changing, if they need to. The problem that I have been having is that after control is returned to script A, the changed image does not display unless F5 refresh is pushed or the page is refreshed. I do not understand how AJAX can overcome this - can you please help me understand? If I was not clear in my earlier posts, please accept my apologies. Many thanks in anticipation.
  13. Yes, I have used AJAX quite often and understand what to do to use it. But even if I did use AJAX in this situation, after control is returned to script B after the file update, I want to go back to script A to re-list the (now updated) data which is pointed to from the database table. There is a JavaScript method - window.location.reload(true) which would do what I want, but it seems that I cannot change the URL before I use it. (I tried your suggestion by adding a hash to the relocate in script B to relocate back to script A. After the document is ready in script A, I can remove the hash OK, but when I then use the window.location.reload(true) it uses the URL with the hash still in place which of course just causes a loop). It seems that I just have to press F5 after script A reloads!! Script B does not do a database upload - it just loads an image file onto the server, replacing the image file already there and it does not change its name. But thanks again for your suggestions - they are much appreciated. Cheers from Oz.
  14. Hi HartleySan, Thanks as always for getting back to me. I have a script, let's call it script A which allows the user to select a database item for updating and then, once the user has selected an item for updating, A calls script B which enables the user to do the actual updating. Once script B has done its stuff, it calls script A. The problem is that when script B calls script A after the database update, script A still shows the data as it was before the update. So I was trying to force script A to refresh thus showing the updated data. If you manually force a screen refresh after A has loaded, all is well. Your advice will be appreciated. Thanks, and Cheers from Oz, Necuima.
  15. Hi, I am hoping that someone can advise me how to force a simple page refresh when a new script loads. I have tried: $(document).ready(function() { adjust_wrapper_size(); // to stop it from being too big! //adjust_sidebar_font_size(); // to simulate scalable text font window.location.href = window.location.href; }); // end document ready function within <script type="text/JavaScript"> but it just goes into a loop. Is there a way to force the window.location.href to fire only once? Thanks in anticipation for any advice. Cheers, Necuima
  16. Hi HartleySan, Yes, thanks for the tip. What was confusing me was that I had three 'alert' displays in the stage_2_processing function and they were displaying in the reverse order than I was expecting! I seem to recall that I had come across this once before and was never able to figure out why the alerts were displaying in the reverse order. But display in the reverse order they do, but the code actually executes in the correct, sequential order! In the end I discovered that the 'bug' in the function was unrelated to the asynchronicity of the loader.loadBytes - embarrassingly I had a simple spelling error!! Many thanks for your assistance. Cheers from Oz.
  17. I am wondering if someone can tell me how to force a wait till an asynchronous process finishes. Following is the code that I'm having trouble with: private function stage_1_processing(): void { var inStream:FileStream = new FileStream(); inStream.open(filein, FileMode.READ); var ba:ByteArray = new ByteArray(); inStream.readBytes(ba); inStream.close(); //Transform byteArray to bitmapdata loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, stage_2_processing); loader.loadBytes(ba); // this is an asynchronous operation!! } private function stage_2_processing(evt:Event): void { trace("Entering stage 2 processing"); var content:* = loader.content; var bigBMD:BitmapData = new BitmapData(content.width,content.height,true,0x00000000); bigBMD.draw(content,null,null,null,null,true); ...... I want to force the program to wait until the loader.loadBytes process is finished before continuing on to the stage_2_processing function. It seems to 'fall through' to the stage_2_processing logic before the asynchronous loader.loadBytes process is finished. Any assistance/guidance will be much appreciated. Cheers from Oz.
  18. Hi Larry, Thanks for the advice - I will add the mysql_close as I'd like to have all the scripts totally correct. Re the connection problem, since I changed the host name to the IP address form, it has worked perfectly. But I still don't understand why the previous form, which was just 'localhost' failed intermittently. Do you have any insights? And thanks again, Cheers from Oz.
  19. I did more Google searching and came across this advice: "An 11001 error means that the name you provided for a server in the client connection cannot be resolved to an IP address because DNS entries for that host name cannot be found. Try using the appropriate (internal or external) IP address for the server in the client connection string instead of the name". So I am trying my internal IP address plus the :3306 port number suffix instead of 'localhost' (in the mysql_connect) - so far so good but I'll post more info after more tests. But if anyone can give me some guidance on my 3 questions above, I'll be very happy to receive it. Thanks, Necuima.
  20. Hi HartleySan, Thanks for getting back to me, but as I mentioned in my post, I can't use the mysqli functions because the production hosting company does not support them. I would certainly use them if I could! Cheers from Oz.
  21. I am wondering if someone can help me with an intermittent database connection problem that I have started to experience. My environment is: . Windows 7 Home Premium 64 bit . Internet Explorer 10 . Firefox 22.0 . Dreamweaver MX2004 as the text editor . Xampplite 1.7.3 which comprises: .. Apache 2.2.14 .. PHP 5.3.1 .. MySQL 5.1.41 The problem occurs intermittently in both IE10 and Firefox, so appears not to be related to the browser. The message that I get is (and I stress that I don't always get it): Warning - mysql_connect() [function MySQL-connect]: Unknown MySQL server host 'localhost' (11001) with a reference to the PHP line of code. This is immediately followed by Fatal error Unknown MySQL server host 'localhost' (11001) with a reference to the same PHP line of code. My connection code is: $dbc = mysql_connect($local_hostname_xx, $local_username_xx, $local_password_xx) or trigger_error(mysql_error(),E_USER_ERROR); I am using the PHP mysql functionality as the production system does not support the mysqli functionality. If I have a look at the database with HeidiSQL (which provides MySQL admin-like functionality) the database and its data are all there. Can you also provide some specific guidance re the following: 1) I have a lot of PHP scripts that enable an administrator to update many aspects of the database tables. Most use Larry's PHP redux technique. In each script I require_once the php connection code followed immediately by the mysql_select_db statement. Should I be using 'require' rather than 'require_once'? 2) The database connection code does not use a persistent mysql_connect - should I be using a persistent connection i.e., mysql_pconnect function instead? 3) I do not close the database connection in the PHP scripts - should I? I have been using similar code for years without a problem. The problem seems to have started when I was experimenting with 'require' and 'require_once' to include the database connection code. I was also experimenting with mysql_connect versus mysql_pconnect in the connection code itself. Any advice will be most appreciated and thank you in anticipation. Best regards, Necuima.
  22. Hi HartleySan, I do not have an action value at all in my form. Some time ago Larry advised to not use that when doing a redux - apparently it defaults to the current script URL and maybe that is why the GET/key is still there from the first call? Thanks again for your interest and advice. Cheers from Oz.
  23. Hi, I have a script that works OK but I'm not sure if it's by design or by accident. On pages 91 through 94, Larry advises on how to use PHP redux, a technique that I use often. Here's my scenario: I have a PHP script, let's call it script one, that calls PHP script 2 and passes a key value to it. I test for a key value as the first thing in script 2 via 'if (isset($GET['key']))' and retrieve its value. This works fine. Then script 2 uses that key value to populate a form with values from a database select. The user is able to change any of the values in the form. Script 2 then calls itself via PHP redux. Now this is the part that I don't quite understand. The form is method=POST and that same key value is included in the form via an input type=hidden, a name of 'key', and the value via a PHP echo. But the test for isset($GET['key']) still works and retrieves the correct value for key. But the form is POST? On the URL for the redux-called script two I can see the '?key=key-value suffix. Can someone please help me understand this? Thank you in anticipation.
  24. Thanks margaux and HartleySan, Point about addressing noted! Cheers from Oz, necuima.
×
×
  • Create New...