Jump to content
Larry Ullman's Book Forums

chop

Members
  • Posts

    192
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by chop

  1. I'm still working on this issue but closing in on a solution now. I think the only thing I need to know is the proper syntax for a redirect while sending a variable in the header. For instance, this works: header( 'Location: http://localhost:8888/sites_in_progress/PNE_development/edit_image.php?id=151' ) ; But the value 151 is contained in a variable $image_id I've tried several combinations of single and double quotes and it isn't working. How do I send the value of $image_id instead of "151" itself. My life will be complete if I can get that to work.... at least for the moment. thank you
  2. I tried using output buffering but, if I remember correctly, I then got some undefined variables that I needed for the next page such as image id number and a couple other things. These had either been retrieved by GET I believe (might have been sending them in a header) or a POST Anyway, the ob didn't work when I put the ob at the beginning and then flushed it at the end of my code (because of what I described). My big mistake was to put multiple forms on the same page... everything got complex because of the amount of code. Good thing I use Dreamweaver at least, that let's me hide giant blocks. It might be a matter of rearranging my code. I'll probably take my own advice and go over the whole thing and clean it up. I should do that anyway about now. It's not really a life endangering glitch, but if you have any suggestions, I'll give it a try. thanks, chop
  3. An error occurred in script '/ApacheServer/ApacheDocRoot/sites_in_progress/PNE_development/edit_image.php' on line 791: Cannot modify header information - headers already sent by (output started at /ApacheServer/ApacheDocRoot/sites_in_progress/PNE_development/includes/header.html:6) Date/Time: 3-20-2016 12:32:00 Error message above line 791: header('Location: '.$_SERVER['PHP_SELF']); Line 791 comes right after the query update The following is at the very beginning of the page. You'll notice it has a session include (yours) and an include that loads the <head> information <?php require_once('includes/sessionInfo.php'); require ('includes/config.inc.php'); //require('includes/reports_functions.php'); // ALWAYS SEND THE IMAGE ID TO THIS PAGE ON SUBMIT $page_title = 'Edit'; // create state array $states_arr = array('SS'=>"Select State",'AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona",'AR'=>"Arkansas",'CA'=>"California",'CO'=>"Colorado",'CT'=>"Connecticut",'DE'=>"Delaware",'DC'=>"D.O.Columbia",'FL'=>"Florida",'GA'=>"Georgia",'HI'=>"Hawaii",'ID'=>"Idaho",'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas",'KY'=>"Kentucky",'LA'=>"Louisiana",'ME'=>"Maine",'MD'=>"Maryland", 'MA'=>"Massachusetts",'MI'=>"Michigan",'MN'=>"Minnesota",'MS'=>"Mississippi",'MO'=>"Missouri",'MT'=>"Montana",'NE'=>"Nebraska",'NV'=>"Nevada",'NH'=>"New Hampshire",'NJ'=>"New Jersey",'NM'=>"New Mexico",'NY'=>"New York",'NC'=>"North Carolina",'ND'=>"North Dakota",'OH'=>"Ohio",'OK'=>"Oklahoma", 'OR'=>"Oregon",'PA'=>"Pennsylvania",'RI'=>"Rhode Island",'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas",'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'WV'=>"West Virginia",'WI'=>"Wisconsin",'WY'=>"Wyoming"); include ('includes/header.html'); This is the <head></head> information that gets loaded in the script above: <!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><?php echo $page_title; ?></title> <?php require_once('includes/CMSassets.html'); ?> </head> I assume that the "headers already loaded" error has to do with one or both of the "includes" loaded at the beginning. I just don't know how to get around it. thanks
  4. Well, apparently it's more complicated. I am getting a "headers already sent "warning. I start a session near the top of my code and I also send headers early on. I tried using ob_on (and flush at the end of the code) but then I don't get some necessary $GET variables. First 4 lines of code: <?php ob_start(); require_once('includes/sessionInfo.php'); require ('includes/config.inc.php'); include ('includes/header.html'); ... put ob_flush here </body> I put the header() right after a successful db update. But, as I said, headers have already been sent. $q = "INSERT INTO ".OTHERSALES." (image_id, prints_amt, cards_amt, other_amt, prints_cost, cards_cost, other_cost, prints_income, cards_income, other_income, os_comment, os_date_sold, os_date_added) VALUES ('$image_id', '$prints_amt','$cards_amt','$other_amt','$prints_cost','$cards_cost','$other_cost','$prints_income','$cards_income', '$other_income', '$os_comment', '$os_date_sold', NOW() )"; $r = @mysqli_query ($dbc, $q); // Run the query. // ----- update the modification date in the users database update_user_table($dbc); $add_post_alert=true; // ----- END update header('Location: '.$_SERVER['PHP_SELF']); } else //----- Report the errors. ------- { echo '<h4 class="warning">The following need to be corrected:</h4> <p class="error">'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; Is it a matter of proper placement of ob_start / (flush), header(), $GET variables, session() to make it work? Previously, I had a user warning not to use the refresh button but it seems clunky and they don't always read anyway. Where this is a matter of an MYSQL INSERT, it is of special importance as it means a new row of stuff that is repeated, increasing all the totals. What to do?
  5. I was thinking that redirects always have to be at the top of the page. But maybe I should put it right after it updates the database? Another idea: I have 5 separate forms all on the same page and each with their own SUBMIT button. What if each of these forms were to go to a sort of "Thank You" page with a link to go back to the forms page if desired. Would that do it?
  6. But if I have the header(), then an exit() right after it at the top of the page, how will the page ever load the first time, before the edit is made and then submitted. Won't it always exit()?
  7. I am using a redirect as you prescribed but can't get it to work properly on my localhost (it works okay on the remote server). I put it at the top of my page saved as edit_image.php <?php header( 'Location: http://localhost:8888/sites_in_progress/PNE_development/edit_image.php' ) ; require_once('includes/sessionInfo.php'); require ('includes/config.inc.php'); Perhaps the syntax is incorrect? I get the following error msg: The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies. Cookies are not disabled thanks
  8. Way more information than you probably want. But alas, it's free. I read this book in its entirety (but not always in order). The book is now held together with Gorilla tape and rubber cement and some of the pages are wrinkled as the result of it being left out in a thunderstorm. I started inventing projects on my own. When the projects needed code similar to that in Larry's book (such as a user database and login system), I'd simply paste Larry's code in where appropriate. I would modify the styles and layout, make it look different. Easy, fun stuff because you start with something that already works.. Then I decided I wanted t begin to create a website for fine artists where they could upload images of their paintings, along with information about each image: title, dimensions, medium etc.. This was a good project in itself to learn php and mySQL. Then I said, okay, now the artist has to have a way to change the information about each piece, so I developed an editing module so they could do that too (another .php page). Once I got this far I thought it was about time to sketch all of what I thought I wanted to do out on paper... just to see where I might be going with it. Each time, I'd use as much of Larry's code as possible and simply modify it as needed. In this way I would emulate his programming style and techniques knowing that I'm not doing something completely wrong that I'd later regret. This went on for 5 years. Today I have a small business making websites for artists. It's quite sophisticated. Small chunks of the code are completely my own, other parts are modified Larry code, and some remain totally Larry code. But I never changed Larry's overall structural design techniques. I incorporated them into everything I did. I find that, today, I write very little code from scratch, starting with a blank page. A lot of what I've done (including a content management system) comes from Larry and non-Larry sources as well. For instance, I found a free HTML editor that I could stick in the middle of my code and my clients now use it to change the text of their web pages. I would never have been able to write it myself. Go to Larry's forums or Google the web and find useful chunks of php, html and css code. Every time you look at what someone else has done you understand more and get better at what you do. "My" product, as it stands today, probably has about 30 different authors. It's a mongrel but works great. That's the way it works. You take their stuff, add your 2 cents, post it somewhere, and then you become a contributing author to the projects of 100 other people. Main Lessons: 1.Take ideas and code gratefully from others whom are offering it. 2. Give back what you are able . 3. Be absolutely consistent with your programming. For example, when you decide on a way to name variables, do it that way all the time. Same goes with db queries and just about everything else. 4. When you think you're done writing code because it's working correctly, go over it again in about a month and see if you still understand it or if you should put in more documentation, line things up better or streamline the code a little better. Tweaking never seems to end. 6. When you run into something you can't get your head around and it's late at night. Go to bed and don't worry about it. After a good 8 hour sleep it will still be there but look VERY different. 7. You will eventually get hooked on a project that interests you. That project will turn into a smaller piece of a larger project. It will be like making Lego bricks that clip together. There's a lot of satisfaction when you've created a small structure out of about 5 Lego bricks that actually works. It does something useful. But don't forget that, after you've made a couple of bricks, step back and take a look at where you're headed because it gets really complicated and you'll get lost. Use an old fashion pencil and pad of paper to sketch out ideas using circles and arrows and questions marks etc. Do it away from the computer in a comfy chair while listening to Chopin's Nocturne (my choice). 8. MOST IMPORTANT: Get away from the computer, the forums, everything for an extended time every so often. Do something as opposite programming as you can think of. Go for long walks in the woods. Sit on a rock in the sun and fall asleep. Or go fishing. Talk with other people whom are not programmers. If you don't do this now and then, you will get dull and you will age more quickly. Everything well done will come about through a balance of opposites. "All work and no play, makes Jack a dull boy." --Stephen King, The Shining
  9. I worked on this until my brain hurt. I went to bed and slept 12 hours then looked at the code again and immediately came up with a simpler design that works well. So I guess the correct answer was to get some sleep. I appreciate the reply, however. thanks...
  10. As many times as the browser refresh button is pressed, form data will continually be sent. True the browser warns you about this but that doesn't solve the problem. The numbers are added to the previous numbers. What is the best way to prevent a user from refreshing while they are still on the same form page? I put warnings of my own near the submit but... I'm not very confident in people even reading it. "Your computer may catch fire if you hit your browser's refresh"
  11. I want a link so a user can "Bail" out at this point in the script though the variable $image_id must be sent if the link is clicked. This works, as a constant: <a href="edit_image.php?id=151" target="_self">BAIL</a> I've tried many different configurations but can't get it to append as a variable an therefore my GET[] doesn't get it on the other end. None of these work: <?php $image_id="151"; ?> <a href="edit_image.php?id=.$image_id." target="_self">BAIL</a> <a href="edit_image.php?id=$image_id" target="_self">BAIL</a> <a href="edit_image.php?id=.'$image_id'." target="_self">BAIL</a> <a href="edit_image.php?id='.$image_id.' " target="_self">BAIL</a> thanks for assistance
  12. I have an array $overview() which consists of a list of column header names. I have a variable $report_type which contains the name "overview" When the form is submitted I need to access the values in $overview() when given $report_type in_array ($sort, '$'.$report_type) I want to find out if $sort is in the array $overview. I tried the above but get the error that a string was given in the second parameter instead of an array. again: $report_type="overview" which contains a list of column names which I am checking to see if it contains the value in $sort. thanks
  13. I'm not sure if you've gotten to the page which explains ho to use "includes" but I think when you do you'll understand why the footer is separate. You will use "includes" a lot in your programming for information that appears on multiple pages. This way you don't have to edit many pages if you want to change it. Larry's books often answer your questions -within a few pages- after they make you think of them. It's sometimes good to hang on to them for a while and you'll soon see that the mystery is resolved. That's part of what makes learning exciting and what makes for good teaching. Glad you've come back to this subject and to hear you're excited about it.
  14. Great. And, yes, I will never have to add <optiion> values to this. Aside from this... I wish you could see the condition of my copy of PHP6 and MySQL 5. I have used it so much over the years it is disintegrating in my hands despite two applications of rubber cement and duct tape to the binding. I have gotten so much out of it. It sits on my desk, a programming bible , with thickening dog ears and dozens of multi-colored plastic tabs sticking out its fore edge shouting exclamations like "retrieving query results" ,"stick forms", "send values to a script" ... It has even survived exposure to a violent thunderstorm and 3 days under the July sun drying. A great value in my programming arsenal which, when it finally slips through my fingers as pulp dust, I will not hesitate to purchase once again. thanks for all that, chop
  15. Thank you. I had a feeling there was something there that I hadn't understood. I'm not sure "where" that result set is that gets pointed to so it creates a bit of a void in my "grokking" it. That's okay though, I can accept that as part of the mystery and see that "mysqli_fetch_array" is the way (and only way) to access it wherever it's hiding out. I think I'll try passing the dates in the URL contained in the <th> tags, then do the query again... if I understand you correctly. thanks again
  16. Assuming I have made this query: $q = "SELECT c_frame + c_glass + c_materials + c_fees + c_commissions + c_other AS total_cost, image_title, sold, price, b_sell_price, print_available, DATE_FORMAT(date_created, '%Y-%m-%d') AS dc, DATE_FORMAT(date_added, '%Y-%m-%d') AS da, DATE_FORMAT(b_date_sold, '%Y-%m-%d') AS ds FROM art WHERE ($date_col_name >= '$begin_date') AND ($date_col_name <= '$end_date') ORDER BY $order_by" $r = @mysqli_query ($dbc, $q); If I save the value of $r so it is available after re-sending the page from the server, can I then resort the query differently than the original sort rather than making the same query again? I have column headings in my table that look like this: <th><a href="overview.php?sort=image_title">Title</a></th> (so the data can be resorted) However the original query (above) has selected data according to a date range. I would like to keep the exact results from the original query and sort it according to the column specified in the <th></th>. I hope I am being clear.
  17. I came up with this for a sticky select (seems to work okay) but am curious if there is a simpler way. There will never be any more than 3 date options <select name="date_cats" style="font-size:smaller"> <option value="Select Date Type" >Select Date Type</option> <option value="Date Sold" <?php if(isset($_POST['date_cats'])&& $_POST['date_cats']=="Date Sold") echo 'selected="selected"'; ?> >Date Sold</option> <option value="Date Added" <?php if(isset($_POST['date_cats'])&& $_POST['date_cats']=="Date Added") echo 'selected="selected"'; ?> >Date Added</option> <option value="Date Created"<?php if(isset($_POST['date_cats'])&& $_POST['date_cats']=="Date Created") echo 'selected="selected"'; ?> >Date Created</option> </select>
  18. A float is a number with a decimal point in it or one expressed in exponential notation. So when numbers get really small (or really big) like 123456789484848484884884 then, if you echo this, it would become: 1.23456789485E+23 which means that you move the decimal point 23 places to the right to get an approximation of the original number. Approximation because you'll notice that it has been rounded off at the ...484 to ...485 If by normal numbers you mean integers, integers do not have a decimal point though one is assumed to be at the far right.
  19. Here's the code $title="MYTITLE"; $image_id=5; // Make the update database query: $q = "UPDATE ".DBTABLE." SET image_title='$title', available='$available', height='$height', width = '$width', framed ='$framed', matted='$matted', media= '$media', price= '$price', comment = '$comment', hold = '$hold', sold = '$sold', print_available = '$printAvailable', date_created = '$date_created', additional = '$additional' WHERE image_id=$image_id LIMIT 1"; $r = @mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1){ echo "The number of rows affectd is 1"; } else {echo "There were no rows affected"; } The result is always that there are no rows affected I am positive about the following: 1. the db table column names are all correct 2. there is an image_id in the table whose value is 5 3. the table name DBTABLE is correct Therefore the image_title should be updated. But it doesn't Furthermore, I get not error messages. Just that no rows were affected. caveat: I've been away from mysql for a while so this could be a really dumb thing.
  20. Are you actually storing images is a table or are you storing image URLs? If you are storing images (as blob data) it might be appropriate to ask here about the wisdom of this. From what I've researched it is not advisable as it is too taxing on the performance of the dB. So, if you are redesigning anyway, try keeping the images in your file system and reference by URL. This is as much a question as a suggestion because I know there may be reasons "backing up?" for keeping images in a table. OR It could be that my information is simply outdated by now.
  21. If your looking for something that gives you all the essentials along with phenomenal support - they actually list an 800 number for tech support and a real person actually answers the phone within about a minute. I've been with them as a "reseller" (I host all my client sites there) for about 6 years. siteground.com
  22. Larry, I have the Kindle edition of PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)Sep 23, 2011 by Larry Ullman In it you mention briefly (or allude to) a 5th edition. I'd like to go back to paper. I miss the highlighting, scribbling in the margins, thumbing through the pages and sticking plastic tabs on them. And, I like the weight and feel of it as it begins to soften with wear. Eventually, it becomes a trusted friend. Oh, and it's quite nice for all I learn from it! Can we expect number 5 soon? thanks, Gary (aka chop)
×
×
  • Create New...