-
Posts
5,450 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
error wont send checkbox value to next page
mac_gyver replied to jamesreno20's topic in PHP Coding Help
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. -
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
-
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.
-
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?
-
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.
-
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.
-
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.
-
MySQLi Error 1062 (dealing with multiple duplicate key entries)
mac_gyver replied to terungwa's topic in MySQL Help
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. -
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.
-
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?
-
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?
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
php's error_reporting would probably help track down the problem.
-
what sort of database library functions is your db::getInstance() class using (mysql_, mysqli_, PDO)? the reason i ask is that your code is also using mysql_real_escape_string() and without a mysql_connect() statement, it won't return any result. it would also be throwing a php error if you had php errors being reported and logged/displayed. the reason this works on your development system is that some of the WAMP all in one development packages set up default mysql connection details matching your root database user and would allow a mysql_real_escape_string() function to work, whereas a live server wouldn't be doing such nonsense. you should be escaping string data (or using prepared queries) using a method present in your db::getInstance() class, not using mysql_ functions. edit: i see that in your recent threads on this forum that you are using the PDO database library functions. you would use the PDO quote() method. however, be advised that this adds the single-quote characters around the data, which means that you must remove the single-quotes you have in your existing sql query statement. in cases where you are putting external data into an sql query statement, you should use prepared queries, which will avoid all the problems like this associated with trying to escape/quote string data.
-
@josephbupe, programming help forums are not for getting people to write code for you. they are for getting help with code you are writing. if it's beyond your programming skills to do something that you want, you will need to hire someone to do it for you. if you do have your own programming that you have written and need help with, start your own thread for it. topic locked.
-
you can use fseek() to start reading from a file at a specific location, but you will need to know the location. if all the blocks of data are the same length, you can just create an index (stored in its own file or a database table) of which numbered block corresponds to the date/time of the data, then just do a little math (block number * length of each block) to find the location to fseek() to. if the blocks are variable length, you can create an index (stored in its own file or a database table) of the actual offset that corresponds to the data/time of the data. just get the filesize() of the log file before you write new data to the file. the filesize() value would be the fseek() location for the new block of data. store that in the index with the date/time of the data.
-
extracting an array to individual variables would just create a mess of individual variables, that if you are then planning on using variable-variables to reference, will take three times longer than referencing the data in an array. are you sure that the time taken is in the processing of the data or is it in the query(ies)? have you profiled the code to pin down where the majority of the time is taken? for all we know you are running queries inside of loops on data that is lacking needed indexes or that you are repeatedly opening/closing a database connection. the example data tells us little about the problem. your actual complete code is what is important in terms of helping with a performance problem. the only thing that is apparent from the hinted at code - $placeDataHere['DV_' . $date]['SM_' . $key] = 'KS_' . $value; is that by adding text prefixes to these three variables that ALL the processing is slowed down by the extra code need to reference the data using the synthesized keys. in fact, why are you even storing data it in the $placeDataHere array? just use the $date, $key, and $value directly in the code. since you must retrieve the data from two different database servers, the typical things that would help with the speed would be - 1) only retrieve the data you need (for all we know you are retrieving far more data than gets used.) 2) do as much processing in the sql queries as possible (for all we know the actual processing of values involves data from only one of the servers and could be handled in the query and returned relative to just a key value to be used by the php code to combine it with the data from the second server.) 3) since the processing is likely on a per-user basis, the data in the arrays should be organized per-user (i'm guessing the $key is user related) so that related data is grouped (see item #4.) 4) eliminate actual loops by using array_map()/array_walk() with call-back functions to do the processing (requires that the data be organized in a way the aids processing.) short-answer: you must first find where the time is being taken up at in the code, then address what that portion of the code is doing.
-
<?php= does not exist. <?= would become <?php echo (with a space between the echo and any following value) this isn't an Apache problem. it's a php configuration problem and people using php's lazy-way short-cuts in code they publish for others to use that is not portable between php versions/configurations.
-
the characters being added are BOM (Byte Order Mark) characters, times 3. your posted php code/html don't appear to have them in it, though the process of editing/copy/pasting for the post could have removed the characters. i have never seen a case where a browser added BOM characters to form data values, so it's most likely that your php code/html has them in it, probably due to copy/pasting code from somewhere it was published at with BOM characters as part of it. the code you didn't post was - what code do you have that does anything with $_POST['token'] through to the point where $token gets set? you can narrow down the problem further by using var_dump($_POST) at the start of your processing code; to see if the characters are coming in with the post data or if they are being added by the processing code.