Jump to content
Larry Ullman's Book Forums

Christopher Bergin

Members
  • Posts

    90
  • Joined

  • Last visited

Everything posted by Christopher Bergin

  1. at some point, I will use a local setup to develop but right now, I'm just going through the exercises and for the most part, I don't encounter environment related issues. My Mac is 10 years old so I was planning to purchase a new one before installing the server setup. Hopefully by this spring.
  2. In chapter 3, I couldn't seem to get the exercise to work successfully when trying to invoke a MySQL stored function. I received a syntax error on line 1 even though I copy and pasted the author's script. I use a hosting site to complete the exercises and the version of MySQL that they support is 5.0.91-log and myPHPAdmin version 2.8.0.1. I can only interact directly with the database through myPHPAdmin. When I contacted the customer support at the hosting service, they tersely replied that they don't support stored procedures through myPHPAdmin. Has anyone heard of this limitation?
  3. thank you both. Hartley was right, I failed to include quotes in my query. I'll have to go back and review what constitutes a string and what constitutes a variable.
  4. I was trying to modify the database queries in exercise 3.1 that created and destroyed sessions. The author uses the sprintf function to invoke his queries. I tried to use a standard query and I'm receiving 'header already sent' errors. the query used in book appears like this: $q = sprintf('SELECT data FROM sessions WHERE id="%s"', mysqli_real_escape_string($sdbc, $sid)); the query I was attempting to use was: $q= 'SELECT data FROM sessions WHERE id= $sid'; the book: $q = sprintf('REPLACE INTO sessions (id, data) VALUES ("%s", "%s")', mysqli_real_escape_string($sdbc, $sid), mysqli_real_escape_string($sdbc, $data)); mine: $q= 'REPLACE INTO sessions (id, data) VALUES ($sid, $data)'; the error I'm receiving is the following: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /hermes/bosweb/web108/b1084/ipg.cjbergincom/PHP test/db_sessions.inc.php:18) in /hermes/bosweb/web108/b1084/ipg.cjbergincom/PHP test/db_sessions.inc.php on line 91 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web108/b1084/ipg.cjbergincom/PHP test/db_sessions.inc.php:18) in /hermes/bosweb/web108/b1084/ipg.cjbergincom/PHP test/db_sessions.inc.php on line 91 line 91 is the session_start command. line 18 is a conditional statement in the read_session function... function read_session($sid) { global $sdbc; // Query the database: //$q = sprintf('SELECT data FROM sessions WHERE id="%s"', mysqli_real_escape_string($sdbc, $sid)); $q= 'SELECT data FROM sessions WHERE id= $sid'; $r = mysqli_query($sdbc, $q); // Retrieve the results: if (mysqli_num_rows($r) == 1) { list($data) = mysqli_fetch_array($r, MYSQLI_NUM); // Return the data: return $data; } else { // Return an empty string. return ''; } } // End of read_session() function. If it helps to present the entire script, let me know.
  5. I had a syntax error that evaded the parser... ajax.setRequestHeader('Content-Type', 'application/x.www-form-urlencoded');
  6. actually, I had caught that as well. Since you brought it up, the code from the book contains the ID discrepancies in the contact.html page and the contact.js page. It took me an hour to find it. Just an FYI. Anyway, I'm still working on it. I'll get back to you if I find a solution.
  7. well, I was able to go to the site and copy the code. The syntax was pretty much correct, the problem was the input type I was using. After some testing using different input methods and inline JS events, it seems the widget only responds to input type of text.
  8. Am I approaching this correctly? I'm trying to produce a datepicker widget but it's not working. Here is the code: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <h1>This is a JQuery test of it's plug-ins</h1> <a href='' id= 'dateInput'><p id= 'pickOne'>Please select a date</p></a> <script src= 'utilities/jquery-1.8.3.js'></script> <script src= 'utilities/jquery-ui-1.9.2.custom.min.js'></script> <script src= 'utilities/jquery.ui.datepicker.js'></script> <script type= 'text/javascript'>$('#dateInput').onclick(function(){$('#pickOne').datepicker();})</script> </body> </html>
  9. The mail does not get sent, I'm not receiving values for my PHP variables but the return message IS echoed back. For instance, I tried to see if the $body variable was receiving a value: echo 'the value of body is...' . $body; but all I receive is the value of body is... so the PHP variables are not receiving values. When I remove the JS function and submit the form directly from the HTML page, the mail gets sent to it's destination.
  10. I went through the exercise for creating a simple form which, in theory, would be handled using an Ajax script that submits the form to a PHP script for mailing, and that in turn would confirm the success of the submission and reply back to the Ajax script. The mail process on the PHP side was omitted for the exercise but I decided to try to get it to work. I'm having a difficult time establishing values in the PHP script. I'll try and provide just the pertinent code without losing the focus of my question; // Add an event handler to the form's submission: document.getElementById('theForm').onsubmit = function() { // Create the data: var fields = ['name', 'email', 'comments']; var data = []; // Empty array. for (var i = 0, count = fields.length; i < count; i++) { data.push(encodeURIComponent(fields) + '=' + encodeURIComponent(document.getElementById(fields).value)); } // Open the request: ajax.open('POST', 'resources/contact.php', true); ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // Send the request: ajax.send(data.join('&')); return false; }; // End of onsubmit function. as you can see, the values are appended to a string as name=value pairs and sent to the PHP script. I'm trying to isolate these values on the PHP side and include them in a mail. Do I have to parse the string and obtain the values that way or does PHP perform that automatically? <?php $body= $_POST['Comments']; echo 'the value of body is...' . $body; $email= $_POST['email']; mail($email, 'Contact Form Submission', $body); echo 'The message has been sent.'; ?>
  11. Is the disable property available for all form elements? Also, when manipulating the DOM, such as appending nodes and such, I noticed that the source code does not get revised.
  12. thanks Hartley, I'm going to play around with that. That answers my questions.
  13. The events.js exercise in Chapter8 uses a nodeName property of the (e) object and I'm not sure where it comes from. Is this a user-defined property? function reportEvent(e) { 'use strict'; // Get the event object: if (typeof e == 'undefined') e = window.event; // Get the event target: var target = e.target || e.srcElement; // Establish the output message: var msg = target.nodeName + ': ' + e.type + '\n'; // Add the output to the textarea: U.$('output').value += msg; } // End of reportEvent() function. Also, in the same exercise, a setHandler function is created that determines the events to listen for. The utility function addEvent, to add an event is called. The addEvent function takes 3 arguments, the object, the type of event for the object and a supporting function call as the third argument. function setHandlers() { 'use strict'; // List of possible events: var events = ['mouseover', 'mouseout', 'click', 'keypress', 'blur']; // Add or remove event handlers accordingly: for (var i = 0, count = events.length; i < count; i++) { var checkbox = U.$(events); // Get the element. if (checkbox.checked) { // Is it checked? U.addEvent(document, events, reportEvent); } else { U.removeEvent(document, events, reportEvent); } My question is this: the document object is passed as the argument and I was wondering why the form object could not be passed since all the elements fall within the domain of the form. I tried this and it doesn't seem to work. Chris
  14. Thanks once again HartleySan. I copied the variable declaration that you prescribed and it worked brilliantly. Also, your explanation regarding functions being assigned to object properties helps clarify my understanding of the topic. On to Chapter 8. Chris
  15. In one of the examples in Chapter 7, Larry includes a rather verbose variable declaration in the script words.js: // Sort the words: var sorted = words.map(function(value) { return value.toLowerCase(); }).sort(); He mentions that iterating the variable assignment into discrete steps may be easier to understand which is the approach that I took. So the code would translate to something like this: var sorted= words.map(changeToLowerCase); //invoke changeToLowerCase function sorted= sorted.sort(); setText('output', sorted.join(', ')); //function call to output words My problem was when I attempted to declare the variable changeToLowerCase as a function definition, the interpreter didn't like it. I had to define it as a separate function to get the script to work. I'm wondering if I may have misunderstood this idea. var changeToLowerCase(value) {return value.toLowerCase();} Also, in this chapter, the following is used: window.onload= init; It's explained that the function definition is the proper assignment, not the function call. I'm having a hard time wrapping my head around this idea. I don't understand how the two differ. Anyway, I tried using window.onload= init(); and it seemed to work. Chris
  16. duly noted. Thanks for the response HartleySan. Chris
  17. I'm wondering why variables that are declared at the beginning of a function are assigned the form elements and not their corresponding values. For instance... // Get a reference to the form elements: var type = document.getElementById('type'); var years = document.getElementById('years'); the program would then go on to check conditions... // Convert the year to a number: if (years && years.value) { years = parseInt(years.value, 10); } // Check for valid data: if (type && type.value && years && (years > 0) ) would the following revision be as efficacious? var type = document.getElementById('type').value; var years = document.getElementById('years').value; Chris
  18. I want to thank Larry for presenting an engaging talk to the Boston PHP group. The talk covered the essentials of becoming a web developer. All the points mentioned had relevance to me because I'm just starting out. The venue was at the Microsoft NERD Center in Cambridge Ma. and visiting for the first time, I was quite impressed. Everything about the event was wonderful and I even received one of his books for attending. Larry, you may dismiss the idea of a degree in English studies but I wonder if your books would be appreciated today if you hadn't had the background. I enjoyed meeting and talking with you and I thank you again for being genuinely personable and helpful. Chris Bergin
  19. I'm just getting started and I realize that submitting a form to a PHP script for processing will not be preempted by Javascript code if there are errors in that code. What causes the Javascript, when coded properly, to intercept a form submission before it gets sent to the server? Also, can anyone recommend a good instructional video for Firebug training?
  20. I noticed that some examples in the last chapter included If Conditionals that check the status of an array value: if (isset($_SESSION['cart'][$pid])) I tried to include this language in a For Loop but was rudely rebuffed by the interpreter: foreach ($_SESSION['cart'][$pid] as $index) just wondering.
  21. I'm almost done with the book. In the last chapter( Chapter 19), a start_session command is included in the header file which, if I understand this correctly, will start a new session each time a new page with the header included is visited. How is session data maintained if a new session is started? In Chapter 12, the session is initiated in a single login page and maintained throughout the site until the visitor logs out.
  22. thanks for the tips. I guess I got spoiled learning from the books on this site because they invite the reader to engage in examples and I find that I absorb more knowledge when I can practice it. What I'm looking for is a book that uses the same approach. I have the Programmer To Programmer book for Wordpress and I'll eventually go back to it, but it is mostly a description of the architecture. I'd like something in between to get me to that point. I'll definitely consider the book that you mentioned Rob.
  23. Hi Larry, I wanted to know if you could recommend a good instruction book on Wordpress. One that introduces the reader to the application but also discusses the underlying code that a new programmer such as myself could appreciate. I already purchased one book but it's a little too technical for me at this point in my development. Thanks, Chris Bergin
  24. I recently joined a web development meetup group to network and expose myself to current developments in the field. Boy, was I overwhelmed at my first meeting. The speakers at the meeting introduced us to a stack architecture that they feel is brilliant: backbone.js http://backbonejs.org/, http://nodejs.org/ and couch.db http://couchdb.apache.org/ all using Amazon cloud services. Anyone familiar with these technologies?
×
×
  • Create New...