Jump to content
Larry Ullman's Book Forums

margaux

Members
  • Posts

    453
  • Joined

  • Last visited

  • Days Won

    52

Everything posted by margaux

  1. 1. have you set up a user table and are you storing user details? When a user logs in, start a session with his username or id. Then you can check that the session username or id is set before giving him the option to add items to the cart. 2. it sounds like you're not clear on how your site will work. If I remember correctly, the orders table in the Knowledge is Power site is used to record all the transactions that go through PayPay so if you there are any queries you have a record to refer back to without have to go through PayPal to get the info. I'm sure its all documented in the book so you may want to refer to that chapter.
  2. also check the format of the date - Europeans use dd/mm/yy, Americans use mm/dd/yy
  3. Thanks Antonio. I'd created a form for the user to input the number of usernames to create so this will slot in nicely. I have little experience with oop but this will make me get my head round it. Thanks again.
  4. Antonio, this is awesome. You've taught me alot, thank you. A couple of questions: $chars is defined as a string, but used as an array in the penultimate line. so I changed it to $username .= substr($chars,mt_rand(0, strlen($chars)),1); which works unless you think there is a better way. the username, password pairs need to be stored in a d/b as well as displayed on screen. Do I need to do 100 inserts or is there a way to improve performance by doing one batch insert? how would I force the password to contain at least 1 number, 1 lowercase and 1 uppercase letter? Thanks again - really appreciate your help!
  5. It looks like you're getting a mysql error 2 - which means the file can't be opened. For starters check the stored procedure on the database for any extra characters such as ; or /
  6. Thanks Antonio - these are good questions and very helpful suggestions. I need to confirm the requirements but I suspect the username and password are limited to alphanumerics and the usernames have to be unique. Once I get the specifics I'll give your suggestions a go. Thanks again.
  7. I need to generate serveral hundred random usernames and passwords, and store each pair in a table. Presumably the best way is to use a loop? Do you have any recommendations to ensure processing efficiency? Or are pre written functions you would recommend? Thanks.
  8. It would help to have more information. Which queries are failing? Set up your debugging code to display your queries, then you'll be able to see what values are actually being passed to the stored procedures.
  9. Here's what I used which worked. $to = EMAIL; $subject = 'Training requirements submitted'; $header = 'From: ' . $_SESSION['uemail'] . "\r\n"; $content = chunk_split(base64_encode($fileData)); $uniqident = md5(uniqid(time())); $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uniqident."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uniqident."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uniqident."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$fileName."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$fileName."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uniqident."--"; mail ($to, $subject, $message, $header); Any recommendations for learning more about sending and downloading file types as I would like to be able to email attachments of different file types? Thanks.
  10. If I've understood what I've found online so far, I have 2 options: use PEAR addAttachment() - I haven't understood from the PEAR documentation how/where to implement this function (I have installed PEAR). What does "this function can not be called statically" mean? do I call it within the message part of my mail() function? [*]use mail() with the appropriate headers. The file I am attaching is created within the php script that sends the email. Is it a case of applying the correct headers within the mail() function? I found these online $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; Presumably once I've encoded my file using chunk_split function with base64_encode, i'm good to go. The second option may be better for me as I haven't done much oop, but happy to give it a go if I could find some more documentation on it. Thanks for your help with this - I'm trying to solve a specific problem as well as learn more generally for future projects.
  11. yes, as an attachment in an email. Sorry, should have been more specific.
  12. A few questions on sending different file formats 1.How do you send a csv file as an attachment? I've created a csv file so just need to learn how to sendi it. 2. Are there any books/tutorials you would recommend for creating and sending different file formats? Thanks
  13. I have a couple of questions: I need to insert data from a form into several different tables which are linked with foreign keys. If I set up the queries as individual transactions. They work fine on their own but I am trying to link them to use last_insert_id(). I've tried $q = "INSERT INTO fbpages (pub_num, url, likes, talkingAbout, wereHere, noOfAdmins, otherUrl) VALUES ('$pnum', '$url', $l, $ta, $wh, $noa, '$other'); SELECT LAST_INSERT_ID() INTO fbpid; INSERT INTO pubs (pub_num, pubname, manager, email, address1, address2, city, county, postcode, phone, fbpage_id) VALUES ('$pnum', '$pname', '$man', '$pem', '$a1', '$a2', '$city', '$c', '$pc', '$ph', fbpid); SELECT LAST_INSERT_ID() INTO pid; UPDATE users SET firstname='$fn', surname='$sn', pub_id=pid, bdm='$bdm', date_modified=NOW() WHERE id=$uid"; which gives a1064 error 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT LAST_INSERT_ID() INTO fbpid; INSERT INTO pubs (pub_num, pubname, manager,' etc I've got it working by using if (mysqli_query($dbc,$q1)) { $fbpid = mysqli_insert_id($dbc); Is last_insert_id imore efficient? 2. I was thinking of making this a stored procedure as there a number of inserts and updates.If I did use a stored procedure for these transactions how would I get the last_insert_ids into variables/session variables that other pages could access?
  14. I went back to basics and realised that I was confusing the array key and its value. Here's what I ended up with foreach($_POST as $key => $value) { if (preg_match('/skill_item\d{1,2}$/', $key)) { if (filter_var($value, FILTER_VALIDATE_INT, array('min_range' => 1, 'max_range' => 5)) ){ $skills = array(substr($key,8) => $value); } else { $survey_errors[$key] = 'Please select a competency level.'; } } // end if preg_match } //end foreach Further to your previous post, I have read Larry's PHP and MySQL for Dynamic Web Sites and Effortless Ecommerce but need to firm up on them before moving on to Advanced PHP. It's when you apply the concepts and techniques to your own projects that you realise what you've learned (or not!). Thanks for your replies - I'm sure I'll need more help with this project as I progress.
  15. Well I've got the create_form_input function working and have a form with the select drop downs but I don't know how to access the option value. I know I should know this but I'm drawing a blank. here's the form input <td><select name="skill_item4" id="moderation"><option value="0" selected="selected">Select One</option> <option value="1">Very Confident</option> <option value="2">Confident</option> <option value="3">Competent</option> <option value="4">Not Very Competent</option> <option value="5">Not Very Confident</option> </select></td> I want to validate the option to force a selection and store the selection(which I'll call skill_level) along with the skill_item in a table. I've started along these lines foreach($_POST as $key => $value) { if (preg_match('/skill_item\d{1,2}$/', $value) && (filter_var($_POST[how do I access the option value?], FILTER_VALIDATE_INT, array('min_range' => 1)))) { $skills = $_POST[$value]; I was thinking $skills would be an associative array which I could then loop through when I'm doing some other processing. Logically I think I'm on the right track but struggling with the code. Could you help? or if you have a better way of doing it, please let me know. Thanks
  16. I was able to get the create_form_input function working using if (preg_match('/skillLevel\d{1,2}$/', $name)) { but I think your suggestion is a far better approach, thanks Jonathon. I'm a little out of my depth here so will probably be back soon with more questions!
  17. I've tried several approaches with arrays and wildcards to access these select fields. Currently I'm playing around with using a create_form_input function to create the form as follows if ($type == 'select') { if ($name == 'skillLevel%') { $data = array(1 => 'Select One', 'Very Confident', 'Confident', 'Competent', 'Not Very Competent', 'Not Very Confident'); } // end of $type = select if=elseif echo '<select name="' . $name . '" id="' . $label . '"'; if (array_key_exists($name, $errors)) echo 'class="error"'; echo '>'; foreach ($data as $k => $v) { echo "<option value=\"$k\""; if ($value == $k) echo 'selected="selected"'; echo ">$v</option>\n"; } // end foreach echo '</select>'; } Then I was hoping to use substr to get the particular id of the select field and do the necessary processing. However, the % wildcard character is not being recognised and my form is not being created correctly. I get 2 errors - Invalid argument supplied for foreach() and Undefined variable: data. If I include the actual number e.g. skillLevel1, then it works, but there must be a way to use a wildcard? Should I be using regular expressions? Does php have wildcards - I haven't been able to find much online about wildcards. Thanks for any suggestions.
  18. Yes - I have been told that it is possible to configure localhost (are you using xamp or mamp?) to use https, but I have not had the time to look into it. If you find out how to do so, perhaps you could share how to do so?
  19. Thanks Jonathon, could you be more specific? I was thinking along those lines. I can use a foreach loop to get the score for each option selected and add that score to the total score. but I'm not clear on how to get the option value - $_POST['skillLevel']['option']?
  20. I have a form with 20 select fields, each with 5 option values (1-5). For each field I need to get its option value, look up its score in a table, add the score to a total as well as insert all 20 option values into another table along with the other data from the form. I'm thinking array, but not sure how to extract the option value. all the select fields have the same name, but different ids e.g. <td><label for="moderation">Moderation</label></td> <td><select name="skillLevel" id="moderation"><option value="1">Select One</option> <option value="2">Very Confident</option> <option value="3">Confident</option> <option value="4">Competent</option> <option value="5">Not Very Competent</option> <option value="6">Not Very Confident</option> </select></td> The fields all have the same name as I'm using a function to create the form. What would be the best way to program this and how do I access the option value? Thanks for any suggestions.
  21. I'm using something very similar to this function to create a form, passing 4 arguments function create_form_input($name, $type, $errors, $label) I was under the impression that the last argument could be optional. I am using it to set an id for the select fields in my forms but do not need it for the text fields. <td><label for="moderation">Moderation</label></td> <td><?php create_form_input('skillLevel', 'select', $survey_errors, 'moderation')?></td> When I run the script, I get an error message for every field which has not passed the 4th argument - 'missing argument 4 for create_form_input(). Are all arguments mandatory, or how do I make it optional?
  22. I need a table to hold a range of decimals and their corresponding meaning e.g. 0.00-4.99 = poor 5.00-9.99 = average 10.00-14.99 = good above 15.00 = excellent what would be the best way to set up this table?
  23. Thanks for replying. I can't give this alot of time as I've won a paying(!) contract, but just to be clear for when I can revisit... the postcodes data that I downloaded only provides the first 4 characters so the data is not getting truncated. In the venues table that I've created, I store an 8 character postcode as I need the full postcode for other purposes. For the distance calculation I need to get the latitude and longitude provided by the downloaded table so perhaps the like = 'string%' option is the way to go. Will try it.
  24. Antonio, thanks for replying: I'll try changing the column types so they're both the same type e.g. varchar(8) but I'm wondering if the problem is stemming from the downloaded data being a maximum of 4 characters e.g. AB10 or S6, whilst I need the full postcode and am storing it as 8 characters e.g. AB10 5AU or S6 6JE. Is there a way with mysqli to isolate the characters in the latter type column to just S6 or AB10? In the second query I tried using SUBSTR but if the field is S6 6JE, the comparison will be on S6 6 and that won't work. I have tested in phpmyadmin and the result is as I explained above. The locations are returned but all with the same distance. The formula I'm using is the one Larry used in his zip codes example. Also I believe I've tested step by step as I've echo'ed out various variables which are correct and I've echo'ed the results of the first query and that also is correct. Are there other tests I could try?
×
×
  • Create New...