Jump to content
Larry Ullman's Book Forums

chop

Members
  • Posts

    192
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by chop

  1. FYI: some research on this shows that one possibility is to use a php class called fpdf to generate a .pdf file which can then be printed with more reliability when using different browsers and printers. http://www.fpdf.org/
  2. Yes I was using a table and some css code that I found but nothing quite lines up and different browsers can throw it way off.
  3. After some looking around, I've not been able to print a mysql query of name,address to a sheet of Avery labels. After coming close in Firefox, more tweaking (the css) didn't get me much closer. When I tried it in Safari, it was off by a mile. This makes me think that it's just not the way it's done -hello. Exporting the data base from php admin and then bringing it up in Excel works but it's not practical to have a client try that. Any help appreciated....
  4. I'm wondering how the "isset" conditional is accessed if I delete all the $_POST vars. I suppose their must be a buffer that holds onto them for the purpose of resending the data when the refresh is pressed?? I thought that maybe a redirect would clear everything but that didn't work either. I can try the cookie method and see how that works. hanks
  5. I am working on an unusual website, one that uses jquery and is horizontally scrolling with each "page" of the site displayed as a separate "panel". This means that the entire website exists as "index.php" The very last panel is the Contact page. I have set up a simple php mailer to wrap and send information on Name, Email, Comment ... the usual. Everything works fine except if the user clicks on "refresh" button on the browser in which case the email, with all the same information, is sent again. It doesn't matter what panel you're on, the email will be sent. At the very top of the Body section, I have: if (isset($_POST['submitted']) && isset($_POST['sendEmail']) ) { where "$_POST['sendEmail'])" is in a hidden field. I also have: $_POST = array(); after the email is sent to clear the POST array... I thought this would handle the problem! But the information is still there and will repeat if the Refresh is pressed!. How do I clear the information so the Refresh information is cleared? What is the best thing to do here?
  6. I guess I've been working with ASSOC arrays too long. It seems that the entire results of the SELECT is given within a single array $row[0]. I was thinking that the 3 results were equal to 3 separate rows so that it would be stored in $row[0], $row[1],$row[2]. But it's not, it's all a single row of results.. right? Hmmm, okay, you have my permission to change my "Advanced Member" status to "Advanced Dementia".
  7. Here is a script that I typed into php MyAdmin: SELECT M.media_name FROM media as M INNER JOIN member_media as J on J.mediaID = M.mediaID WHERE J.maaMemberId = 209 The number of rows it returns is 3 Here is the php version: $q = "SELECT M.media_name FROM media as M INNER JOIN member_media as J on J.mediaID = M.mediaID WHERE J.maaMemberId = 209"; $r = @mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $row = mysqli_fetch_array ($r, MYSQLI_NUM); echo $row[0]; echo $row[1]; echo $row[2]; exit(); The only result is $row[0] which is a correct result (matches first row in first example) The other 2 rows give "Undefined offset"
  8. Thank you. I thought that might be the case but never really knew for sure. It was a problem because, even with no errors turned on, I was getting the UPDATE query printed to the screen along with my own nebulous "system error" warning under the condition that mysqli_num_rows($r) != 1 So, no problem, I just take care of it in the validation. thanks again
  9. When changing a user password, I noticed that my UPDATE query (below) will not work if the user types in the same password as exists in the database. Otherwise it works okay. I don't know why. $q = "UPDATE ".DBTABLE." SET pass=SHA1('$np') WHERE maaMembersID = ".$id; when $np is the same as the old password, this does not work.
  10. I'm from the 'good ol days' of computing when "out of MEM error" wasn't uncommon on my Apple (orTRS-80) computer screen. So when I hear about "freeing up memory" I shudder a bit of what might happen if I don't do it religiously. Anyway, thanks to all the posts I have enough understanding of how it works to make my own decisions about it. thanks as always
  11. I tend to leave the connection open after the SELECT figuring there will be an UPDATE soon to follow. The query usually involves very little data so I wasn't sure if I was being anal in "closing" and "freeing" all the time. Also I didn't know if there was any kind of security risk involved. But if the connection is closed automatically, as you say, at the end of script execution, then what is the point in ever "closing" it via script (i.e. what constitutes a persistent connection). The DB is opened, the form populated, then the DB is closed until the UPDATE comes along. Then it is closed automatically after the UPDATE. Do I understand this correctly?
  12. I've never been clear about when these two functions need to be called and (if they are never called) when $dbc is closed automatically and when the result of a query is "freed" automatically. My example is this: I have a php page that has a form. The first thing that is done is to fill it in with default data from the database via a SELECT. From here, the data can be edited and then saved. 1. Should I "mysqli_close($dbc);" AFTER the "Select" query and BEFORE the form is validated and then "UPDATED" or is it okay to leave it alone and just close it after the form has been "UPDATED"? And what about "free_Result". Should this always be done along with the "close" function or does it only matter according to how mach data is being read from the DB? 2. Is the database closed and the result freed when a different .php page is accessed? I've never run into trouble doing or not doing these but I think I'd like to know the SOP. thanks
  13. Thank you. I did get it to work through some trial and error as follows: $q = "select COUNT(*) FROM ".DBTABLE." WHERE current_member ='Yes'"; $r = mysqli_query ($dbc, $q); $row = mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; I took out the AS clause and added (*) to count and made the array NUM instead of ASSOC The following still does NOT work. I'm not sure why (using ASSOC): $q = "select COUNT(*) FROM ".DBTABLE." AS YAK WHERE current_member ='Yes'"; $r = mysqli_query ($dbc, $q); $row = mysqli_fetch_array ($r, MYSQLI_ASSOC); $records = $row['YAK']; echo '<br /><h1>There are '.$records.' members in the MAA</h1>';
  14. I just can't get this to work: $q = "SELECT COUNT('current_member') AS 'current_member_count' FROM ".DBTABLE. "WHERE current_member = 'Yes'"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_ASSOC); $records = $row['current_member_count']; echo '<br /><h1>There are '.$records.' members in the MAA</h1>'; //An error occurred in script '/ApacheServer/ApacheDocRoot/phpPNEdevelopment/Gill/member_list.php' on line 20: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given// If I take off the . "WHERE current_member = 'Yes'" everything works fine. thanks, chop
  15. I had looked at it before but didn't get how the array items would get trimmed as in "array_map('trim', $_POST)". So I tried to integrate "array_map" into the "array_walk_recursive()" formula and overcomplicated things. However, I discovered that the array items do get trimmed anyway -though I don't know how unless it's just part of array_walk_recursive().?? So, thanks for bearing with me. I am no longer getting the "Warning: trim() expects parameter 1 to be string,..." which was my main concern.
  16. When I do this: $trimmed= array_walk_recursive($_POST); $trimmed = array_map('trim', $trimmed);// thought I'd need this to do the actual trimming or this: $trimmed= array_walk_recursive($_POST); The fields don't validate--
  17. I'm not sure that I want a recursive procedure to be applied to $trimmed array (though I'm not sure). I just want to get the "$trimmed = array_map('trim', $_POST);" to ignore the array variable media[] that is defined in the checkbox input field: <input type="checkbox" name="media[]" value="acrylic" /> I'll deal with it myself in the $_POST['media'] array form.
  18. Part 2 of this question is: I get the error "Warning: trim() expects parameter 1 to be string, array given in /ApacheServer/ApacheDocRoot/phpPNEdevelopment/Gill/maaRegistrationForm.php on line 124" ... but it doesn't cause any problems in the running of the script, it will continue. Is it proper to ignore the error and then handle the $_POST[media] array in whatever way I want? Or should no script be considered "good code" as long as there is an error "at large" no matter if it is benign?
  19. As in Larry's PHP book PHP 6 and MySQL 5, I have been using: $trimmed = array_map('trim', $_POST); to put all the $_POST[] data into an array. But there's a problem now that I'm using the checkbox input field as set to input an array like this: <label> <input type="checkbox" name="media[]" value="acrylic" /> acrylic </label> The array_map doesn't handle $_POST[] arrays I could make each of the checkbox inputs with unique names like so: <input type="checkbox" name="acrylic" value="acrylic" /> But an array seems in order here. What should I do??
  20. I understand, makes sense now. I knew my syntax was incorrect but wasn't getting an error. This worked for Me; $mediaArray=$_POST['media']; echo $mediaArray[0]; //works fine $_POST['media'][0]; // works as well thank you
  21. Looks like an easy question here but I just don't see it.. getting old: Why doesn't this work: if (isset($_POST['submitted'])) { // Handle the form // Trim all the incoming data: $trimmed = array_map('trim', $_POST); echo "The media is ".$_POST['media[0]']; [color=#ff0000]// THIS COMES UP WITH NO VALUE: "The media is "[/color] exit(); // CHECK BOX INPUTS WITHIN FORM <p>* check all that apply but at least one of the following:</p> <p> <label> <input type="checkbox" [color=#ff0000]name="media[]"[/color] value="acrylic" id="" />[color=#ff0000]// this is the first in the list[/color] acrylic</label> <br /> <label> <input type="checkbox" name="media[]" value="checkbox" id="" /> Checkbox</label> <br /> <label> <input type="checkbox" name="media[]" value="charcoal" id="" /> note that "print_r($_POST['media']);" works fine and prints the whole array
  22. Good point. To answer this post: I deleted all the files on the remote once again and uploaded them once again. This time, however, I picked only the files I needed to have there rather than make a mirror. It worked fine. So, all I know is that there was a file there that shouldn'thave been there rather than there being a missing file. Wish I had something more definitive for you.
  23. I figured out the answer to this question but I couldn't figure how to delete the post. SO, I guess that's my updated question.. how to delete a post. I went to edit but didn't see that option. thanks
  24. I am getting this as an error when running a php script: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/corner19/public_html/editText.php:1) in /home/corner19/public_html/editText.php on line 3 The catch is that everything works fine on my local server but not on the remote server. To be sure, I deleted all the files from the remote and made a mirror of it from my local. Is there a difference (in terms of headers) whenn working locally than on a remote server? Here are the first few lines of editText.php: <?php # Script 9.4 - #4 session_start(); // This script retrieves all the records from a table. // This version paginates the query results.[/b] [b]//ini_set('display_errors', 1);// displaying errors = true //error_reporting(E_ALL);// show all types of errors $page_title = 'View your Images'; include ('includes/header.html'); require_once (CONNECTION); thank you
  25. Can anyone suggest a good IDE for php for both a Mac and a PC? thanks, chop
×
×
  • Create New...