Jump to content
Larry Ullman's Book Forums

Necuima

Members
  • Posts

    359
  • Joined

  • Last visited

  • Days Won

    7

Everything posted by Necuima

  1. I just kept 'fiddling' and by placing the #include "header.h" directive in front of the #include <iostream> directive in script 12.10 (this.cpp), it worked??? The code now looks like this: // this.cpp - Script 12.10 // Need the header file. #include "header.h" #include <iostream> // Get the external variable. extern unsigned short thatNum; // Create a static variable. static bool printMe = false; int main() { ...etc... and the definition of headerNum is as per the errata guidance - static const unsigned short headerNum = 5; In case anyone else comes across this oddity! Cheers from Oz.
  2. Hi, I am back 'into' the C++ book :-) I tried to get the scripts 12.8, 12.9 and 12.10 to work in my Dev-C++ 5.8.3 IDE but it seems not to take any notice of the pre-processor directives in the header file as I get a compile error 'multiple definitions of headerNum'; specifically that headerNum is first defined in that.cpp with a consequent multiple definition in this.cpp. However, I can get it to work in my MS Visual C++ 2008 IDE but I needed to add #include "stdafx.h" in both this.cpp and that.cpp and also change the definition of headerNum as per the errata for the book. My environment is Windows 7, 64 bit. Could it be that my Dev-C++ IDE somehow ignores or doesn't recognise the C pre-processor directive? Any advice will be most appreciated, and thankyou in anticipation. Cheers from Oz.
  3. If there are no changes to any of the data in the database record, you will get zero affected rows, I'm pretty sure. Cheers.
  4. Hi Larry, Thanks for the reply. The request to PayPal certainly goes via https and it remains there while the customer makes the payment - it's the 'thanks' reply that I'm concerned with - it doesn't seem to have any sensitive data associated with it, and it only causes a "thank you" screen to show. There are no database updates needed in this application/context. The owner will receive an email and the customer will also receive an email from PayPal re the payments, as I understand it. The owner would only expect about half a dozen transactions in total - the payments would be for a course she is running and once that's organised, there won't be any need for the payment feature until she (maybe) runs another course next year. No products get shipped and no subscription type data are involved. I very much appreciate your advice. Cheers.
  5. Hi Larry, Re point 10 on page 159, I've done some more PayPal sandbox testing and have found that the button will accept and function with an HTTP:// URL rather than an HTTPS:// URL. As far as I can see, no 'sensitive' data are being transferred and the website owner does not have a certificate anyway. Further, the ...index.php?p=thanks URL works OK too as per my query above. I am still in testing with the sandbox - can you see any issues re continuing the development without acquiring a certificate and using the HTTP:// URL approach? Thanks in anticipation for your advice. Cheers.
  6. Re 'Creating a Button' on page 157... The following worked for me (PayPal Australia): As per step 1 - log in to the sandbox using the test business account. . click the "Sell" option . Click the "Get Paid on Your Website" option . Add a checkout button and in my case - "create HTML form". PayPal have obviously changed their 'create button' dialogues. Cheers.
  7. Hi Larry, I am trying to adapt your classic PayPal guidance to make a simple one-time payment from a website. First, PayPal seems to have changed its button creating directions as I can't see any "Merchant Services" tab as per your guidance on page 157. In fact I cannot log in at all to the sandbox using the test business account that I set up. The website owner has a production PayPal business account and it was via that that I was able to create the test business and personal accounts as per page 156-157. I was however able to create a production button via "My Selling Tools" and then change the code to direct to the sandbox as per your advice on page 159. However, I have a specific question re point 10 on page 159, re the cancel and thanks URLs. In the website to which I want to add the simple one-off payment capability, I have used your site design as per your PHP Advanced book where all accesses to modules go through the index.php module (page 44 onwards of that book). So can I simply use "HTTPS://www...etc/index.php?p=thanks and ....?p=cancel where they will be redirected to the appropriate thanks and cancel modules? All other accesses to modules go through HTTP://www...etc/index.php(i.e., without the "S" of the required HTTPS for these PayPal redirections)? Sadly I cannot use Stripe for this website owner:-( I do not have a security certificate for this website. Thankyou in anticipation, and Cheers from Oz.
  8. Hi David, You may have already fixed your code but you 'strip_tags' $first_name twice but I can't see where you've done it for $last_name. Cheers.
  9. Hi Larry, Many thanks. If this goes ahead, as mentioned, this will be my first implementation of a payment feature. Once we get an SSL certificate, does this mean that all URLs for the website must be HTTPS, or can just the Stripe URL be HTTPS and the others just normal HTTP? Thanks, and Cheers.
  10. Hi Larry, In the book you mention that you cannot test Paypal's IPN process from localhost (page 169). Are Stripe payments fully testable from localhost? Also, none of my few websites need or use SSL so I have no experience in using HTTPS. It seems that the website owner will need to obtain a certificate, but when I checked the Digicert website there are a number of different types of certificates available. The website that I'm thinking about would have a very low volume of financial transactions in the range $100 - $200 each. Can you please advise what sort of certificate we would need? Many thanks in anticipation.
  11. Hi, it would help a lot if you gave some more information - e.g., is this in response to an AJAX/jQuery callback? If so, here's an example - first the AJAX 'call': submitHandler: function(form) { // will only 'fire' the ajax post if there are no errors var formData = $('#transedit').serialize(); $.post('./edit_trans_xml.php', formData, handleResponse); return false; // So form isn't submitted. } // end submitHandler and now handling the response from the AJAX call: // Function that handles the response from the PHP script (data is in XML format): function handleResponse(data, status) { // Check that the transaction is complete: if (status == 'success') { // First clear any messages that may be there from a previous update $('#ajax_errors').html(''); $('#results').html(''); $('#blockout').html(''); // remove the two commentary lines // Now get the XML data: // First, get any errors and display them: $(data).find('error').each(function() { // $(data).find('error') creates an array (which will hopefully be empty) var dataToDisplay = $(this).text(); $('#ajax_errors').append(dataToDisplay + "<br />").show(); }); // Put any received response in the DOM and make it visible: $(data).find('result').each(function() { // $(data).find('result') creates an array (which hopefully will not be empty) var dataToDisplay = $(this).text(); $('#results').append(dataToDisplay + "<br />").show(); }); } } // End of handleResponse() function. Hope it helps but to give you advice properly, we need to know more about the issue including sample code if appropriate. Cheers.
  12. Hi, can you not check if the user is logged in as an administrator and if they are not, bypass or skip the admin-panel code? Also, I would recommend that you don't call the admin directory 'admin' - it is too easy to identify by someone trying to cause harm. I use a really weird directory name for all my admin code. In several websites that I have written, I keep all the admin stuff totally separate from the normal code even requiring a separate admin login, but that may not be suitable in your site. For what it is worth. Cheers
  13. Further to rob's post, here's an example of setting a radio button depending on a value from a database record. $black = ""; $blue = ""; $red = ""; $green = ""; .................... if ($colourx == "green") $green = 'checked="checked"'; elseif ($colourx == "blue") $blue = 'checked="checked"'; elseif ($colourx == "red") $red = 'checked="checked"'; else $black = 'checked="checked"'; // the default .................... echo <<<EOT <label class="maintext_right v_align_top" for="test">$text_1 </label><textarea name="$id" type="text" rows="5" cols="75" id="$id">$text_2</textarea> <span class='v_align_top maintext'> Colour: <input class="para_radio_inline" type="radio" name="$name" id="black" value="black" $black /><span class="maintext">Black (Default) </span> <input class="para_radio_inline" type="radio" name="$name" id="red" value="red" $red /><span class="maintext">Red </span> <input class="para_radio_inline" type="radio" name="$name" id="blue" value="blue" $blue /><span class="maintext">Blue </span> <input class="para_radio_inline" type="radio" name="$name" id="green" value="green" $green /><span class="maintext">Green</span> </span> EOT; where $colourx is from the retrieved database record. Hope it helps. Cheers from Oz.
  14. OK, here's an example where I've retrieved a day number and a month from a database record: ............. $days = range (1, 31); $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); ........... echo '<select name="day" id="day">'; echo "<option value=$t_day>$t_day</option>"; foreach ($days as $value) { echo "<option value=\"$value\">$value</option>"; } echo '</select> '; echo '<select name="month" id="month">'; echo "<option value=$t_month>$t_month_alpha</option>"; foreach ($months as $key => $value) { echo "<option value=\"$key\">$value</option>"; } echo '</select> '; $t_day is the day number retrieved from the database record, i.e., the day number previously stored from a previous transaction. The 'foreach' then just lists the other day numbers that the user could then select from if they wish to change the day number. After a new day number has been selected (if indeed it was changed) then the database record is updated. Also shown is the PHP for the month drop-down box. $t_month is the numeric month number from the database record retrieval and $t_month_alpha is the spelled-out month from the $months array. The code shown is PHP echoing HTML. When a day-number is selected, I do an in-form validity check via jQuery that that day number is valid for that month - logic not shown. Hope it helps. Cheers from Oz.
  15. Hi, you can certainly use a modified version of your form to pre-fill it with existing data, normally retrieved from the database. Then the user can modify the required data via the form and the program can then use that modified data to update the database. It is a technique that works well. Here's an example (from within a form): <label class="maintext_right v_align_top" for="new_woa_name">Work of Art Name: </label><input name="new_woa_name" type="text" size="60" id="new_woa_name" value="<?php echo $old_woa_name; ?>"> <small><small><i> Change if needed - max length 60 characters.</i></small></small> <div class="small_lineheight clear_left"></div> $old_woa_name is from an MySQL select where that datum is retrieved from a database record. The other code is just formatting and line spacing. Hope it helps. Cheers from Oz. The programming technique is PHP redux as per Larry's book examples.
  16. Hi Larry, I have loaded these 3 scripts into my Dev-C++ IDE and they work just fine. But I don't understand how main.cpp 'knows' about Rational.cpp; there doesn't seem to be any direct reference to it either from main.cpp or Rational.h. Also, I had to add <stdlib.h> to Rational.cpp to cater for the abs (absolute value) bit in the 'normalize' method. Any enlightenment will be most appreciated and thank you in anticipation. Cheers from Oz.
  17. Hi Larry, I have been working through the book and am at script 7.6 - rectangles5.cpp. Because of the constructor, I found that the setSize method is no longer needed as the constructor does the same job. I commented out all references to the setSize method and the application executes correctly in my Dev-C++ IDE. FYI, Cheers from Oz.
  18. Hi Larry, Yes, your comments have helped a lot in my understanding. Thank you!
  19. Hi, when I started working through Larry's PHP and MySQL books a few years ago, I installed IIS on my then Windows XP PC. But I pretty soon switched to XAMPP and upgraded to Windows 7 both of which have worked perfectly for me and all Larry's code has executed properly. For what it's worth. Cheers.
  20. Hi Larry, I am having trouble getting my head around parts of this script. It works fine so no issues there - it's my lack of understanding that's the problem! There are two main areas that I'm having trouble understanding - firstly the declaration and subsequent definition of the 'normalize()' method does not indicate that any values are provided to the method - therefore, is it correct to assume that the method 'knows' about the two object attributes - numerator and denominator? Secondly, I do not understand the 'right hand side' parts of the overloading properly. Is it something like: when, say, the addition operator is invoked, it is passed two objects of type 'Rational', both of which have two attributes, a numerator and a denominator. So the rhs bits refer to the attributes of the second 'Rational' object passed to the addition operator? Now to the subtraction, how does the addition operator know which two 'Rational' objects to add? (Point 5 on page 292). Any clarifying thoughts will be most appreciated and thanks in anticipation. Cheers from Oz.
  21. Probably due to a different IDE. In a separate post I described a problem that I had with exercises 6.2 and 6.3 and the solution that worked for me in my Dev-C++ version 5.8.3 IDE which seems to use the TDM-GCC compiler version 4.8.1, 64 bit, in my environment. However, later on I tried the same exercise 6.2 in an MS Visual C++ 2008 Express Edition IDE and it ran fine as per the script in your book. As per "The King of Siam": 'Tis a puzzlement! Cheers from Oz.
  22. Hi Larry, When I tried to run script 9.5 - rational.cpp, my Dev-C++ IDE gave me an error re lines 131 and 132 (approx.) where abs is used in the normalize method. I had to add #include <stdlib.h> and then everything worked OK. Just FYI. Cheers from Oz.
  23. Hi Larry, Thanks for getting back to me but can you please help me understand why my small code change solved my problem? Is it something to do with the way recursive routines are controlled - I believe that a 'stack' or 'heap' may be involved? Does the 'return' in the recursive call stop that new instigation of the routine from being pushed down a memory construct? Any insights will be most appreciated, and thanks in anticipation. Cheers.
  24. And for the char c = 'D' I had to use: std::cout << "The address of c is " << static_cast<const void *>(&c) << "\n"; // hex ss3 << std::hex << static_cast<const void *>(&c); ss3 >> ul3; std::cout << "The address of c is " << static_cast<unsigned long>(ul3) << std::endl; // decimal Otherwise you don't get the address of the char. Cheers.
×
×
  • Create New...