-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
AJAX working on PHP5.2.10 but not on 5.2.9
PFMaBiSmAd replied to sirfragalot's topic in Javascript Help
6) Examine the php change log to see if anything that was changed or fixed in 5.2.10 is being used/mis-used by your code. -
AJAX working on PHP5.2.10 but not on 5.2.9
PFMaBiSmAd replied to sirfragalot's topic in Javascript Help
1) Do you have php's error_reporting set to E_ALL and log_errors set to ON so that all the php detected errors will be logged to the error log file? 2) Browse directly to the same URL that the AJAX is requesting and see if the .php script outputs the expected result. If you are sending post data, make a HTML form to test with that submits the same data that the AJAX is doing and see if the .php script works as expected. 3) Are the php.ini settings the same, and you have actually confirmed that they are, for the 5.2.9 that does work and the 5.2.10 that does not? Are all the local php.ini/.htaccess files exactly the same? Are both those php versions running the same way under the web server, both as CGI's or both as server modules? 4) Are you using a session that is accessed both by the main page or content on the main page (images/media files) and by the AJAX requested page? The session data file could be locked and the AJAX requested pages are hanging waiting for the session_start statement to complete. 5) Posting the relevant code needed to duplicate the problem would let someone directly see what exactly it is doing that could be causing the problem. -
The browser is probably requesting the page twice, once with $_POST data and once without. There are several reasons why different browsers do this, some within your control (url rewriting, redirecting to the same page,...) and some outside your control (which browser is being used and which add-on's it has.) Are you not validating that a form was submitted and that $_POST['replytext'] is not empty?
-
Form validation not producing the error messages when it should
PFMaBiSmAd replied to sabinmash's topic in PHP Coding Help
I recommend starting with the following code (please read the comments in it because this is not complete code) - <?php $link_register = 1; // I'll assume you use this variable? include("header.php"); function parsePhone($phone) { $phone = trim($phone); if($phone=='') { return $phone; } //Strip out non numbers $phone = preg_replace("#[^\d]#", '', $phone); if (strlen($phone)!=10) { return false; } else { return $phone; } } function trim_deep(&$item){ // used by array_walk_recursive to trim all elements of an array, w/sub arrays,... $item = trim($item); } //determine if the form was submitted if ($_SERVER['REQUEST_METHOD'] == 'POST') { //array to hold error messages $errors = array(); array_walk_recursive($_POST, 'trim_deep'); // trim all elements of the $_POST array (the result is put back into the $_POST array) // required text fields - firstname, lastname, phone1, phone2, phone3, email, street, city, state // optional text fields - middleinitial // The array keys are the form field name, the array values are the legend/name to display in the error message. $required = array('firstname'=>'First Name', 'lastname'=>'Last Name', 'phone1'=>'Area Code', 'phone2'=>'Phone Number', 'phone3'=>'Phone Number', 'email'=>'Email', 'street'=>'Street Address', 'city'=>'City', 'state'=>'State'); foreach($required as $key=>$value){ if($_POST[$key] ==''){ $errors[] = "$value is empty!"; } // do any other common filtering/validation on the required fields here... } // do any filtering/validation on the optional text fields here... // if middleinitial is present, filter it as needed // do any validation of the category (array) field here (in case someone didn't use the form to submit it) // if at least one category choice is required, perform that check here... // do any validation of the gender field here (in case someone didn't select one or didn't use the form to submit it) // check if one of the other radio choice was picked... // do specific filtering/validation of the phone number here... if(!empty($_POST['phone1']) && !empty($_POST['phone2']) && !empty($_POST['phone3'])){ // only if all three parts are not empty $phone = parsePhone($_POST['phone1'].$_POST['phone2'].$_POST['phone3']); if ($phone === false){ $errors[] = "You must enter a 10 digit phone number."; } } // do specific filtering/validation of the email here... if(!empty($_POST['email'])){ // only if not empty /*Statement below as a whole says " if email validation is false..." filter_var(Value to filter, The ID of the filter to apply.) Filters a variable with a specified filter*/ if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === FALSE) { $errors[] = 'Please enter a valid email address!'; } } // other filtering/validation tests here... // all filtering/validation done at this point. // if there are no errors, use the data. if(empty($errors)){ // do something with the submitted data here... echo "The form data was successfully submitted"; } } // end of the form processing code ?> ... the remainder of your code on the page ... -
Form validation not producing the error messages when it should
PFMaBiSmAd replied to sabinmash's topic in PHP Coding Help
So, the conditional action="" form code (question in a different thread in the forum) got added to this code. When the page is first requested, there are no errors and the logic that determines the action= says to use the confirmation.php page. Until you get your form and the form validation code finished and working the way you want, don't do anything like that yet. Just use an empty action="" attribute to get the form to submit to the same page. As to the validation code - 1) You should be developing and debugging php code with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php will help you by reporting and displaying all the errors it detects. You would be getting an error at the trim() statement for the $_POST['category'] because an array is being submitted. Since it is an array, which no one here knew prior to your reply above, it needs different handling and you wouldn't use trim on it directly. 2) You should not lump together all the tests for 'empty' fields (the current code actually doesn't test for empty values) and output one generic error message. You should individually validate each field and output a unique error message telling the visitor exactly what is wrong with each value (i.e. LastName is empty, No category chosen, ...) This will both help make the final produce better and it will tell you where your current problem is. -
^^^ That logic is wrong. If there is already a row (booked), mysql_num_rows will give 1 (one). You would need to test == 1 for a booked condition. != 1 is a not booked condition.
-
The php code is either using $_REQUEST (instead of $_POST) or it has register_globals turned on, both of which should be avoided. For either case, it also means that the code is not testing if the (any) form was submitted before using any of the submitted data. Edit: The site is also using basic HTTP authentication (the first popup login box) and I would guess is likely rewriting or redirecting the URL to supply it with a URL something like http://username:password@kadio.co.uk:2095
-
What is wrong with htmlspecialchars Not working
PFMaBiSmAd replied to manalnor's topic in PHP Coding Help
Did you do a 'view source' of the page in your browser? -
Another mysql_affected_rows error on update query
PFMaBiSmAd replied to rick.emmet's topic in PHP Coding Help
In programming, there's no need to guess. All the basic information can be found in the documentation. -
The following will give you a 'directory' number (starts at zero) - $x = intval($ID/1000); 0 (0-999) 1 (1000-1999) 2 (2000-2999) ...
-
You should (almost) never execute queries inside of loops. Assuming that you want to - 1) Remove any words that are in historer_excludewords 2) Add any new words to historer_words 3) Get the id of the words The following would be close to what your logic should be doing - <?php $words = $uniqueWords; // get a copy of the words (in case the original in $uniqueWords is used later) $find = array_map('quote_smart',$words); // apply function to each element of the array // eliminate excluded words $query = "SELECT word FROM historer_excludewords WHERE word IN('".implode("','",$find)."')"; $result = mysql_query($query); $found = array(); while($row = mysql_fetch_assoc($result)){ $found[] = $row['word']; } $words = array_diff($words,$found); // remove any excluded words // insert any 'new' words. assumes that the word column is an index. the IGNORE keyword will ignore duplicate key errors for words that are already present. $insert = array_map('quote_smart',$words); // quote the remaining words $query = "INSERT IGNORE INTO historer_words (word) VALUES ('".implode("'),('",$insert)."')"; mysql_query($query); // get the id for each new/existing word $query = "SELECT id,word FROM historer_words WHERE word IN('".implode("','",$insert)."')"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ // your code to get the id for each word from the $uniqueWords array that is (new or existing) in the historer_words table }
-
Also, there's no point in using LIMIT 1. All that does is consume more processor cycles parsing the sql and applying the limit to a single row in the result set.
-
PHP Form action works in firefox but not chrome
PFMaBiSmAd replied to sabinmash's topic in PHP Coding Help
The logic - !empty($errors) implies that if there are errors, goto the confirmation.php page. That's backwards. If empty($errors) should goto the confirmation.php page. It's likely that your error checking logic IS working in Chrome and not working in Firefox (assuming the code you did post is the actual logic you are using.) You would need to troubleshoot why your $errors value is not ! empty in Firefox. -
You should not access any of the form data until you have confirmed that a form has been submitted, typically by checking if $_SERVER['REQUEST_METHOD'] == 'POST'
-
Another mysql_affected_rows error on update query
PFMaBiSmAd replied to rick.emmet's topic in PHP Coding Help
You are using the correct function. You are passing it the wrong parameter. -
query was empty and login form just keeps looping
PFMaBiSmAd replied to spike-spiegel's topic in PHP Coding Help
There's at least 6 8 different things that your code could be doing that works on one server, but not another - 1) short_open_tags are not enabled 2) the session start could be failing due to a configuration problem with the session save path 3) the session start could be failing due to the BOM being output and output buffering being off in the php.ini 4) the session.cookie_path setting is not set to match all paths of the domain and you are switching paths 5) same as #4 but for the session.cookie_domain and the host-name/subdomain switching 6) one or both include statements are failing because the file is not present or at the proper path 7) the code in one or both include statement is failing or failing to make a database connection register_globals are off (I see at least two scaler program variables that look like they are from $_POST variables.) Edit: DON'T turn register_globals on if they are off, fix any code that relies on them being on. You need to troubleshoot what your code is actually doing or not doing on the server where it does not work. BTW - code that uses php's lazy-way short-cuts - short open tags, output_buffering, register_globals, ... is not portable between different server configurations and you often won't have the ability or simply should not to turn the necessary settings on, so it is always best to develop code on a system that has all those short-cut settings turned off. P.S. Is there some reason why the session_start() statement is commented out in the code you posted? That alone could be causing some of the problems or if you were getting an error at that statement, you would need to fix whatever is causing that error. -
If you post an example of what you are trying to produce, I'm sure someone can help you. Your post above doesn't exactly show what you have and what you are trying to achieve.
-
query was empty and login form just keeps looping
PFMaBiSmAd replied to spike-spiegel's topic in PHP Coding Help
There's nothing in the posted code that can produce a "Query was empty" error or message. That error occurs when you use either an empty variable or an empty string "" as the parameter in a mysql_query() statement. -
You need to post your actual code that reproduces the problem.
-
If you do a 'view source' in your browser of the page where you displaying the result, does it have all the HTML that you entered in the form?
-
Also, what does a 'view source' in your browser of the blank page show?
-
Another mysql_affected_rows error on update query
PFMaBiSmAd replied to rick.emmet's topic in PHP Coding Help
The parameter that mysqli_affected_rows() takes is NOT a result resource. It is the mysqli link resource. -
Cookie Help (Actually got code this time)
PFMaBiSmAd replied to RaythMistwalker's topic in PHP Coding Help
Something on line 1 of style.php is sending output to the browser, which prevents the header/cookie from working. I'll guess you either have a blank line, some css, or a BOM (Byte Order Mark) character. See this sticky post for information on this popular error - http://www.phpfreaks.com/forums/index.php?topic=37442.0 -
installing Apcahie, MySQL & PHP (Neary there)
PFMaBiSmAd replied to otuatail's topic in PHP Installation and Configuration
Here is another issue with the php package you tried. nts stands for non thread safe, meaning it cannot be used in a multi-threaded web server configuration (i.e. cannot be used as a server module. Can only be used as a CGI application.) -
installing Apcahie, MySQL & PHP (Neary there)
PFMaBiSmAd replied to otuatail's topic in PHP Installation and Configuration
The latest php windows binary is NOT compatible with the Apache windows binary when running php as an Apache Module. You would either need to install the latest php as a CGI application or obtain a windows binary build of Apache that is compatible for use with php as an Apache Module (you can get such a build of Apache at http://www.apachelounge.com/download/ ) Edit: From the php.net page where you got the php package -