Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,354
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. that's because the purpose of that query is to get a unique list of city names, to produce the select/option list, that is used as a filter for the actual data retrieval query. that query isn't the one that retrieves the matching data and it isn't where the limit term belongs.
  2. what URL did you enter in your browser's address bar for that page? if you are doing this on a localhost development system, it should have been something like - http:/localhost/yourpage.php
  3. programming help forums are not here to fix your's or other people's code for them. do you have a specific programming question or a specific problem or error that you need help with? we can only really help you when you post just the relevant section of code you need help with, along with any errors or symptoms you got from that code. also, we can really only help you with one issue at a time, that you have isolated out of the complete code. expecting someone, on a general programming help forum, who are not the author of the application in question, to be up to speed with or to go through a complete application in order to help you, is beyond the scope of what you should expect.
  4. back to your original problem, where are you trying to save this text input to? a database? a text file? and what errors are you getting?
  5. the constant() function that will let you dynamically get the value of any constant given a string containing the constant name, which you can dynamically produce. however, it sounds like you need to use an array to hold your related values (the actual values could be defined constants), where you can use the array index to access the correct element/entry.
  6. you already have a thread for this problem and if you had looked where you originally posted it you would see a link to where it was moved. topic locked.
  7. while it is true you are using a PostgreSQL database, the problems you are having are related to the php code and the html you are producing from that php code. moving thread to the php coding help forum section.
  8. i went through your code and have the following lists of don't and do suggestions - don't - don't loop over all $_POST data. a hacker can feed your code 100's or 1000's of $_POST variables. you should have an internal list of expected fields (your $rows array) and loop over this list, checking the corresponding input value. don't use the @ error suppressor in code. rather than suppress errors, which makes troubleshooting harder, find a way of programming that doesn't regularly throw php errors that you would be tempted to suppress. don't use extract() in your code, especially on external data since this will let a hacker set any php variable to the value he wants, not just the variables you expect. don't use preg_match() just to test which field you are operating on. don't repeat the same code (your preg_match() format tests) when the only thing that is different between each block of code are the data values. you can expand your array holding the form field definitions to include the preg_match() pattern and what error text to use for each field. don't use variable-variables unless absolutely necessary. in your case, you already have the existing data values in an array. simply use the values from that array. don't repeat yourself - DRY. you have code and data that's being repeated on the page (the include for the form and arrays of submitted form data). you should re-factor your logic to use just one instance of any code and data. don't use $_SERVER['PHP_SELF'], without passing it through htmlentities(). in some versions of php this includes the query string that was used to request your page, allowing cross site scripting. you can use an blank action='' attribute to submit a form to the same page. do - initialize array variables before use. this will make testing those arrays easier, since you won't need to suppress php errors when the array hasn't been assigned any entries perform as many validation tests as possible each time the form is submitted. your current code requires that all required fields be non-empty before doing any of the other validation tests. for a field that has a value, you should validate it and output all the possible validation errors at once. use your internal list of form fields (expanded to include a required/optional control value) to control the required field check so that you don't need to hard-code out any optional fields. put static code/values outside of loops. your current definition of the preg_match strings are inside of a loop, wasting time each pass through the loop. the optional first name field, when it is non-empty, should be validated to insure it contains only expected characters. the include file with your form should only include code block(s) needed for the form, not the entire html markup for the page. your current code is outputting the error $message before the <html> tag, resulting in an invalid html page. your main page should be where the main html for the page is at. variable names should indicate the purpose of the variable. your $rows array, that defines the form fields, should be named something like $form_definition or similar. use htmlentities() when echoing external data back onto a web page to prevent cross site scripting and to prevent an special html characters in the values from breaking the html on the page use css to style elements, not inline styling (your error messages.) the first/default choice in your state option list should not be one of the valid choices so that you can detect when a state hasn't been selected
  9. since this is all one page, all you really need to accomplish is outputting a selected="selected" attribute (valid for all modern html/xhtml versions) inside the correct <option ...> tag when you are building the option list. you would do this by testing whatever variable holds the submitted form value for the <select > menu. if that variable exists and is equal to the current $abbr value, you would output the selected="selected" attribute.
  10. we can only help you when you provide actual information, since we are not sitting there with you. what exact url were you entering in your browser's address bar that resulted in the 404 error?
  11. you can and should test the combinations you want to try on a localhost development system. you would only put the final tested changes onto the live server once you know they work and only if you have a known good backup of all your existing files and database tables from the live server, should you need to restore them if something does go wrong. php5.4 did finally remove a number of the problematic php features that would require code dependent on the features to be rewritten to both function at all and be properly secured. the things that have been changed in php over time can be found in the php.net documentation migration appendixes.
  12. there's two problems with your logic. 1) the - if($entry != 'part0' || $entry !='part1') should be - if($entry != 'part0' && $entry !='part1') using negative logic requires that you negate the || too. i.e. if($entry == 'part0' || $entry =='part1') {do something if either one} becomes if($entry != 'part0' && $entry !='part1') {do something if NOT either one} OR you could just use (not)in_array - if(!in_array($entry, array('part0','part1')) {do something if NOT either one} 2) the rmdir() statement needs the $dir_path in it too, unless the directory being removed is relative to the current script. if php's error_reporting/display_errors are actually on, you should be getting errors from the current code when it tires to remove a directory that it cannot find due to no knowing the path.
  13. what code have you tried? we can really only help you with your code after you have actually made an attempt. php was originally created to do exactly what you are trying, process form data. there are probably two million examples posted on the web and a few 10's of thousands of books published on this subject for you to find and read to learn the basics. for the php mysql database library functions, you should be using prepared queries with either the PDO (preferred) or mysqli_ functions, because the msyql_ functions are obsolete.
  14. that's because the query fails at the first duplicate key value encountered and doesn't attempt to process any of the other values. to do what you are asking will require that you to run a SELECT query first to see if any matching data already exists. you could also only insert the first unique field, with null values for the others, then run update queries to add the other unique field(s), one at at time.
  15. use var_dump() on the values, as that would also show the length, in case there's some non-printing/white-space characters as part of the data.
  16. you always have to debug what your code and data are doing in order to find out where the problem is at. i can list a dozen+ different things that would cause your script produce the result it is. do you have php's error_reporting set to E_ALL and either display_errors or log_errors set to ON and have checked for any resulting php errors? have you determined which values in the if(...) statement are causing the comparison to fail?
  17. ideally, you would store the data in a database, one row for each day/time-range combination and run a query to get the matching program information. lacking a database, you can use an array to hold the data. example code - <?php // define constants for day names to make reading and writing code easier define('SUN',0); define('MON',1); define('TUE',2); define('WED',3); define('THU',4); define('FRI',5); define('SAT',6); // extract common information (i.e. DRY - Don't Repeat Yourself) $path = '/images/shows/'; // data - days (one/array), start (inclusive), end (exclusive), img $a[] = array(SUN,0,1,'MensHealth'); //1 $a[] = array(SUN,1,2,'AlanTaylor'); //1 $a[] = array(SUN,2,5,'HughHewitt'); //1 (used later w/different hours) $a[] = array(range(SUN,SAT),5,10,'RedEyeRadio'); //7 $a[] = array(SUN,10,11,'MomTalk'); //1 $a[] = array(SUN,11,12,'GoodParenting'); //1 $a[] = array(SUN,12,14,'PetShow'); //1 $a[] = array(SUN,14,15,'GardenRebel'); //1 $a[] = array(SUN,15,16,'WorkingMother'); //1 $a[] = array(SUN,16,17,'WhatsCooking'); //1 $a[] = array(SUN,17,18,'HomeWizards'); //1 $a[] = array(SUN,18,19,'DougStephan'); //1 $a[] = array(SUN,19,20,'Finance'); //1 $a[] = array(SUN,20,21,'PopularScience'); //1 $a[] = array(SUN,21,22,'ABCRadio'); //1 $a[] = array(SUN,22,24,'Medicine'); //1 $a[] = array(MON,0,3,'ArmedAmerica'); //1 $a[] = array(MON,3,5,'HughHewitt'); //1 $a[] = array(range(MON,FRI),10,13,'BobRick'); //5 $a[] = array(range(MON,FRI),13,16,'DougStephan'); //5 $a[] = array(range(MON,FRI),16,19,'MariluHenner'); //5 $a[] = array(range(MON,FRI),19,20,'DebbieNigro'); //5 $a[] = array(range(MON,FRI),20,22,'DaveRamsey'); //5 $a[] = array(range(MON,FRI),22,24,'JoyBrowne'); //5 $a[] = array(range(TUE,SAT),0,1,'ShannonJoy'); //5 $a[] = array(range(TUE,SAT),1,2,'BillNojay'); //5 $a[] = array(range(TUE,SAT),2,5,'DennisPrager'); //5 $a[] = array(SAT,10,12,'HaidtReport'); //1 $a[] = array(SAT,12,13,'ABCNews'); //1 $a[] = array(SAT,13,16,'GarySullivan'); //1 $a[] = array(SAT,16,18,'PopularTech'); //1 $a[] = array(SAT,18,19,'WhatWorks'); //1 $a[] = array(SAT,19,21,'JillMoney'); //1 $a[] = array(SAT,21,23,'YouManual'); //1 $a[] = array(SAT,23,24,'MadeAmerica'); //1 $h = date('G'); //set variable $h to the hour of the day. $d = date('w'); //set variable $d to the day of the week. // find the image that matches the day/hr $img = ''; foreach($a as $e){ if(((is_array($e[0]) && in_array($d,$e[0])) || (!is_array($e[0]) && $d == $e[0])) && $h >= $e[1] && $h < $e[2] ){ $img = $e[3]; break; } } if($img == ''){ echo 'no matching program found'; } else { ?> <img src="<?php echo $path.$img.'.png'; ?>"> <?php } edit: don't you already have this information stored in a data structure someplace? how do you display the full schedule?
  18. what does the output from a phpinfo(); statement show for register_globals (the php.ini that you are looking at may not be the one that php is using)? just use $_SERVER['DOCUMENT_ROOT'] in your code and assign it the value in $DOCUMENT_ROOT on your development system. don't assign it any value on the live server. however, that $DOCUMENT_ROOT has a value means that register_globals is likely on (see above to actually check using a phpinfo() statement.) the type of quotes being used in an included file would not matter. there must be something else going on that's causing the problem. you would need to tell us what - "one box hates double quotes - the other has issues with single quotes." actually means in term of symptoms and error along with a sample of the offending code, since computers don't have hate issues with code.
  19. to store the result in an array, that you could then loop over multiple times or loop over once and store the produced output in a php variable - $rows = array(); // array to hold the fetched data while ($row = odbc_fetch_array($res)) ​{ $rows[] = $row; } // use the $rows array any what you want here. you can also use count($rows) to get a count of the number of rows the query matched, that is database neutral.
  20. i'm not sure that the obdc_ database library has a 'seek' function that works universally, that would let you iterate over the same result set more than once, but you should be decoupling your database layer from your presentation layer, by storing the result from the database query in an array for the presentation code to use, that's totally independent of the type of database library functions being used. if you are going to output the exact same content more than once, you would want to produce and store the output in a php variable, then simply echo it wherever you want.
  21. you won't directly know where the problem is at. the error is just being reported at the point in the code where the memory limit was exceeded. you would need to look at what the code was doing up to that point to pin down the problem. this error is most likely due to an initialization problem, i.e. some variable wasn't initialized before/each-time through a loop or similar.
  22. where are you stuck at when you attempted to do any part of this? programming help forums can only help with specific questions or specific errors with code you have written. all you have posted is what you want.
  23. and to get the data from dynamically created form fields, the field name needs to be an array - http://us1.php.net/html#faq.html.arrays so that the data can be processed as an array in the php code.
  24. is the value 1,000 or is it 1000. these are different to a programming language because the , is a stop character that would result in the value 1 being used.
  25. php's error_reporting would probably help track down the problem.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.