Jump to content
Larry Ullman's Book Forums

margaux

Members
  • Posts

    453
  • Joined

  • Last visited

  • Days Won

    52

Everything posted by margaux

  1. Presumably users can have many vehicles and enter more than one vehicle in an event and a particular vehicle can be entered into many events so I think you need another table e.g. events which will store the details about the events. Event-entries will store all the vehicles entered into an event. Then you can use a join statement across the tables using an ORDER BY clause on the events table.
  2. I've used codecademy for javascript and would also recommend it. It offers bite size lessons that you can dip in and out of. I'm with you Antonio - I need to write code to learn. That's why I love the review and pursue sections in Larry's books cuz, you can't refer back to the downloaded files.
  3. ahh - this makes sense. Thanks Larry and thanks for another excellent book. Its the first book I've come across that explains the code and the theory behind it rather than just showing the code to perform a specific task. I think I may start believing that I can program with javascript and learn oop.
  4. I don't understand how to use e - so I've created a small form to test my understanding of event handling. The form requires a radio button to be checked. If I submit the form without checking a button the error message appears but then the form appears to be locked and I can't check a button. Firebug stops at this line U.stopDefault(e); which seems correct. Do I need to reset something? HTML <body> <form id="optInForm" method="post" action="optIn.php"> <fieldset><legend>Agree</legend> <label for="yes">Yes </label><input type="radio" name="optIn" value="TRUE" /> <label for="no">No </label><input type="radio" name="optIn" value="FALSE" /> <input type="submit" value="submit" id="submit"/> <input type="hidden" name="submitted" value="TRUE" /> <div id="errMsg"></div> </fieldset> </form> <script type="text/javascript" src="optIn.js"></script> <script type="text/javascript" src="utilities.js"></script> </body> optIn.js function checkForm() { 'use strict'; var optIn = document.getElementsByName('optIn'); var msg = ''; var chosen = null; for (var i=0, il = optIn.length; i<il; i++) { if (optIn[i].checked){ chosen = optIn[i].value; } } if (chosen === null) { msg='Please select Yes or No'; U.setText('errMsg', msg); U.stopDefault(e); } else { return true; } } // end checkForm function window.onload=function(){ 'use strict'; U.addEvent(U.$('optInForm'),'submit', checkForm); }; utilities.js var U = { $: function(id) { 'use strict'; if (typeof id =='string'){ return document.getElementById(id); } }, // end $ method setText: function(id, message) { 'use strict'; if ((typeof id == 'string') && (typeof message == 'string')) { var output = this.$(id); if (!output) return false; if (output.textContent !== undefined) { output.textContent = message; } else { output.innerText = message; } return true; } }, //end setText method addEvent: function(obj, type, fn) { 'use strict'; if (obj && obj.addEventListener) { obj.addEventListener(type, fn, false); } else if (obj && obj.attachEvent) { obj.attachEvent('on' + type, fn); } }, //end addEvent method removeEvent: function(obj, type, fn) { 'use strict'; if (obj && obj.removeEventListener) { obj.removeEventListener(type, fn, false); } else if (obj && obj.detachEvent) { obj.detachEvent('on' + type, fn); } }, //end removeEvent method stopDefault: function(e) { 'use strict'; e = e || window.event; if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } return false; } // end stopDefault method }; // end U class def
  5. You're right to type all the code out as you'll remember it so much better. Whilst these kinds of errors are frustrating, you'll probably never make them again. I always used to forget the second = when making comparisons, now I never do (well almost never!). Include your code between [code] [/code] tags to make it more readable.
  6. once the transaction has completed successfully you can use an update UPDATE product SET stock = stock-1 WHERE prodID=$_GET['prodID']
  7. Hi milo99, you might find it helpful to use a text editor which provides colour coding - you would have found this error in a second. I've heard good things about Netbeans and TextMate which I'm thinking of trying. I use TextWrangler - its free
  8. What are your favourite forums for web development (aside from this one of course!) and why? I like css tricks, webdesignerforum and a wordpress one on LinkdIn.
  9. They should be pointing in the other directions as per the errata page, http://www.larryullm...-design/errata/. Generally its worth checking the errata page if you come across something you think is an error - most have been listed there.
  10. Is anyone going to this next week? I found out about it too late and have to work but it would be good to read a review/comments?
  11. I have a form with 30+ checkboxes which are named sf1, sf2 etc. and they are to be inserted into a table which has a column for each checkbox to store whether it was checked or not (type enum yes or no). I'll be doing various processing with this list of checkboxes and obviously want to use loops. As part of the validation process, I've created an array $sf, which holds the checked (or not) value of each checkbox and looks similar to $sf = array(1=>'yes','no','yes','no','yes','no','yes','no','no','yes','no','yes','no','yes','no','yes','no','yes','no','no','yes','no','yes','no','yes','no','yes','no','yes','no','no','yes','no'); What is the best way to insert this data into the table? I've been playing around with prepared statements in a for loop. $numFields=count($sf); $q="INSERT INTO survey_fields field1 VALUES '$sf[1]'"; $sf_id = mysqli_insert_id($dbc); //for each sf item except the 1st one for (i=2; i <= $numFields; i++) { $q="UPDATE survey_fields SET field$i VALUES ? WHERE id=$sf_id"; $stmt = mysqli_prepare($dbc,$q); mysqli_stmt_bind_param($stmt, 's', $sf[$i]); I"m getting a 1064 error , check the syntax to use near 'field1 VALUES 'yes'' - on the first insert. Is this being rejected because only 1 field is being inserted when there are 33? All the fields except id are set as type enum('yes','no'), NOT NULL - I have also tried setting all the fields (except id) to NULL but that didn't change the result. A couple of other questions: This method whilst it looks neater involves 33 inserts - I could do just one insert, would that be more efficient (though the query looks horrible)? Is a prepared statement useful here, or would a regular statement do just as well?
  12. I can now devote more attention to this project which is taking me out of my comfort zone. If i post my thoughts, perhaps I could get some comments/suggestions that would help me clarify my approach and learn some more efficient methods. Site Summary The original microsite presents a survey(form) to the end user who is asked to rate himself on a number of skills. After validating the form, a total score is calculated and the information is written to 4 tables in the d/b. The user is then presented with a proficiency level based on his score and a form with numerous training options (checkbox list) he can request. On submission of that form, a csv file is emailed to the site owner and a thank you message displayed to the end user who is logged out. End user must log in so there are functions for the site owner to create/view/amend users and to view the contents of the forms. The basis of the project is to present a form to the site owner to insert data about the company that the microsite is being cloned for. On submission of the form, the new site will be created. This means dynamically creating files and a database. Presumably the files from the original site can be re-used and I just need to substitute variables for the data that the owner enters? Database: for the owner who is going to clone the microsite at least 5 times will include these tables - users, site_vars, skill_items, train_options. Database: for each site created which will have these tables - users, branches, surveys, skill_items, skill_scores, prof_levels. the last two tables are look-up tables. The survey table has indices to branches, users and skill_items which make up the full record of each survey completed. Thanks for your feedback.
  13. this was my thought process too and I've put together a script that does that (I may ask you for help turning it into a plugin). But the guy I'm doing for this says it is possible to disable the cookies for the website that the plugin is used in. Not that I want to do this but the only way I can think of is to get document.cookie, parse through it for each occurrence of expires or max age and overwrite it - is that feasible? I was hoping this could be a learning experience for me but this is not the kind of programming I like doing. "Third party cookies" is the name used in the UK and there is a confusion over which types of cookies are allowed. Some say cookies used for online shopping are okay because clicking 'add to cart' is complicitly giving consent. Others say it is for all cookies.
  14. I am not very experienced with javascript so please forgive the basic questions. I know nothing about the website which is going to use this plugin, so how do I get it to not perform operations that involve cookies?
  15. You could try using output buffering. Anything that your scripts or included scripts send to the browser will actually be put in a temporary memory i.e. buffer and only sent to the browser at your behest. The nice thing about buffering is that functions like header and session_start do not get put into the buffer and still work as intended. Look up the functions ob_start(), ob_end_flush() and ob_end_clean().
  16. thanks Larry for your very helpful comments, as always. I'm not sure what you mean by this. Can I put a variable in the config file e.g. define ('BASE_URL', '$baseURL'); I thought defines were used for constants. or would it be better to use a redirect function? I think I'm okay to create the d/b and tables but not sure how to upload/install all the files dynamically. I'll have a search around. Do you know of any good resources?
  17. I appreciate your taking the time to look into the law and to suggest ways around it but I think you're missing the point of my question. I am not trying to get around the law and it doesnt matter what my opinion is - I'm trying to give the client what he wants. He wants me to build a plug in to drop into his websites. On arriving at the site, the visitor is presented with a dialog which explains what cookies are used and why, and asks the user to opt in or opt out. If the visitor opts out, he can still browse around the site but with cookies disabled - how do I dynamically disable the site's cookies? would this be easier to do in php or javascript?
  18. I do this too - its a quick way to determine if your MySQL syntax is correct and if your variables are of the correct data type.
  19. Not sure which forum to post this in so apologies if I've picked the wrong one. I've created a microsite which consists of several forms, inserting the form data to a d/b and emailing a file attachment. It also includes a mini cms to allow the site owner to view various reports and to create users to access the forms. The site owner wants the cms functionality expanded to be able to change some wording, change some images, maybe embed some viedos and define pretty urls. He wants to easily replicate/customise the microsite. In other words, I think the original site is now going to be a template or a theme. A couple of questions: 1. to allow the owner to define the url, do I use the .htaccess file or are there other ways? 2. presumably I will need to dynamically create a new d/b with new tables? 3. it will be the same person administering all the different microsites so it seems a shame to create numerous copies of the mini CMS scripts viewUser, addUser, viewReports scripts. Is it possible to use the same ones and pass a variable which determines the specific microsite being accessed? Is that approach what is referred to as multisite and is it a good way to proceed or is it better to keep each microsite self contained? As always, I am open to suggestions for the best way to achieve this functionality.
  20. You can imagine that the debate over this issue is huge in Europe and as 26 May grows ever closer so the debate and anxiety about compliance increase. Ironically most people don't know about this new law and come 26 May when dialog boxes and warning bars start popping up on sites, those who never knew or cared about cookies may get concerned. My question is not about using or / not using cookies - I do know that information will be stored on the user's machine and the user can disable cookies himself if he chooses. i'm not necessarily looking for ways round the storing of information. The client has several sites that he just wants to drop in a plugin with minimal effort.The plugin will inform the site visitor that cookies are being used - a modal dialog box that asks the visitor to opt in or out. If the site visitor opts in then all is hunky dory and a cookie gets dropped on his machine to not display the dialog box on future visits. If the visitor opts out, well I'm still waiting for the client to decide what he wants to happen. What would you do?
  21. Thanks Edward for starting this discussion and to Jonathan and Antonio for their contributions. I've just started on the David Powers book and so far found it very good. and I now better understand how Antonio's class, UserGenerator works!
  22. Apologies if I have inadvertently miscommunicated the new EU cookie law - it "requires websites to obtain consent from visitors to store or retrieve any information on a computer or any other web connected device, like a smartphone or tablet". The plugin I'm creating will be implemented on several different sites, so I'm considering different options for determining what/if/how many cookies are being used, to ensure the plugin can be implemented easily. The HTML5 local storage option is attractive for new sites but currently many users are still on IE7. Also a lot of sites use cookies for analytics. Anyway - I just bought this book and am looking forward to its arrival. From the comments on this forum, it sounds like it lives up to the standards Larry has set with his other books.
  23. Thanks for the reply. I agree with most of what you write regarding use of cookies... however a new EU cookie law is about to come into effect and certain companies need/want to be seen to comply. I'm actually more comfortable using PHP than JS and I have some experience with setting and using cookies on my own sites but not creating a plug in to detect cookies on another site so any suggestions are much appreciated.
  24. I need to create a modal dialog plugin that enables visitors to opt in to allow cookies. If the user opts out then he can't access the part of the site that uses cookies. If the user opts in, on subsequent visits the opt in box is not displayed. If cookies are not used then the opt in box is not displayed. I think(?) I can do most of this but do not know how to detect if a site uses cookies. I was thinking that I may have to create a front end to allow the website owner to define what cookies the site uses. but is it possible to dynamically detect if a site uses cookies and how would you do so? Also if you have any suggestions re creating this plugin, please post them. Thanks.
×
×
  • Create New...