Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Well, then I would assume that the elseif() condition is not resulting in true elseif ((select($page) == 'city')){ How are you defining $page. Although, based on the code I can see I think you really need to start over on the page logic.
-
Yes, you do appear to be passing the right value. But, you need to reference the value using $_GET['id'] - you do not have that anywhere in your code. I already gave you a suggestion on how you can use the POST value first if it is set then optionally the GET value if it is set. The reason you are getting a blank page is because you are still tryign to use $_POST['id']. Sine that value is not set on the pages loaded via the pagination links your query has a where clause of state_id='' So, you are getting no results because you have no records where the ID is an empty string.
-
You are making no sense. Why do you set the value of $state_id using this $state_id = $_POST['state_id']; . . . when you NEVER use it?! Later in you code you overwrite the value of $state_id withint he while() loop, so the original value never gets used. But, that is beside the point of what you are trying to accomplish. As I stated previously, you are uing the value of $_POST['id'] to filter your query results, then you add that value to the query string for the pagination links using id='.$id.' But, just as above you never use those value. You need to be using $_GET['id'] to get the value in the query string. And, no where in your code do I see anything referencing that
-
No, that is not what I am saying. I did not read your code line for line trying to decipher every little detail. But, you say the 'id' and 'state_id' are the same value, so why do you have these two lines? $id = $_POST['id']; $state_id = $_POST['state_id']; Again, I didn't look at all of your code in detail, but it looks as if you never use that variable $state_id from THAT defined variable. You do overwrite the variable $state_id, but you never use it with the defined value from $_POST['state_id'] so it seems that is completely useless. So, if 'id' is the only value you need, then you have a workable solution to add the value to the pagination links. But, you still have the problem that you never use the value! You only attempt to use $_POST['id'] (from the form submission) and you never use $_GET['id']. So you simply need to use some logic along the line of 1.) If user passed id in POST data use that 2. Else If user passed id in GET data use that 3. Else don't use id Example code if(isset($_POST['id']) { $id = intval($_POST['id']); } elseif(isset($_GET['id']) { $id = intval($_GET['id']); } else { $id = false; }
-
Your problem is that when the user selects the search criteria it is sent via POST data, but then when the user selects another page you are losing that data. It looks like you have two values passed in the POST data 'id' and 'state_id'. And, it appears you area appending the 'id' to the pagination links, but not the 'state_id' value. but, even so, there is nothing in your code to use the 'id' passed in the URL. So, you need to make sure you maintain the search criteria when you use the pagination links. You can either put both variables on the query string or you can store them in SESSION/COOKIE data. There are benefits and drawbacks to the different methods. But, whichever method you use you will need to make sure you actually use the values. So, first check if the values were passed via POST - if so, use them. If not, then check if they are available in the alternative method GET/SESSION/COOKIE - and use them if they are set there.
-
A better choice would be to use ON DUPLICATE KEY and just do the INSERT query. That way you only need one query.
-
Retrieving contents from a page that you're probably not meant to
Psycho replied to manix's topic in PHP Coding Help
Right, but the question was not about whether he could "use" any of the content. It was with respect to scraping the site - which is specifically forbidden per their terms of use. -
I think I already explained that. You need to generate the timestamp in the PHP code when you query the database and then send that timestamp back to the AJAX with any updated messages. Then the JavaScript should send that timestamp back on the next trip so the PHP code only gets new messages.
-
Retrieving contents from a page that you're probably not meant to
Psycho replied to manix's topic in PHP Coding Help
LOL, your lawyers, yeah right. But, it depends on what you mean by "layout". If you write your own code from scratch that has the same layout as another site with respect to location/size of content areas and such, then no, it is not a copyright infringement. But, what I meant by copying the layout was copying the source code (HTML/CSS) and then using that for your own content. Whatever the case, what the OP is trying to do IS in violation of the terms of service for IMDB - period. -
You shouldn't expect us to sift through your files trying to find the problem. You need to post the relevant code and explain what variable is specific to the problem and show how it is used.
-
Retrieving contents from a page that you're probably not meant to
Psycho replied to manix's topic in PHP Coding Help
Yes, they absolutely do have a copyright on the layout of their site. They do not, however, own the rights to the information. But, they have every right from allowing you to copy the content from their site. They have taken time and resources to put together the information they provide. Why should someone simply be able to copy all the information from their site without having to put in the time and effort? But, be advised, you may also have issues with displaying any artwork from a movie. -
removing duplicate entries in a 2 dimensional array
Psycho replied to Yure's topic in PHP Coding Help
Well, explain what you want to do and I'll provide assistance -
Form validation not producing the error messages when it should
Psycho replied to sabinmash's topic in PHP Coding Help
You aren't using the function as intended. But, that is partially my fault. When I created the function I initially intended it to be used to simply "parse" the phone number, but halfway through I decided a different approach was better. The function should really be called validPhone(). As I stated earlier, if the function finds that the phone is not valid it returns false - otherwise it returns the numeric string. You used the function like this parsePhone($phone); That doesn't do anything to the variable $phone - you would need to assign the return value of the function to a variable $phone = parsePhone($phone); Now, $phone will be false if the passed value cannot be parsed into a valid 10 digit number, else it returns the 10 character string of numeric digits. -
Form validation not producing the error messages when it should
Psycho replied to sabinmash's topic in PHP Coding Help
I thought I already explained that. It takes the input, strips out all non-numeric characters and then tests if the result is 7 or 10 characters. If not, it returns false, if yes it returns the stripped value (i.e. the numeric digits.). You state If the value is stored as a single value then how is it a "requirement" to be three fields? Not that I care. I see many application that require the user to enter the three parts separately. I just think it is lazy since it is not difficult to allow the user to enter the data into a single field and validate it appropriately. Personally, I hate that type of UI. It is so much easier to enter a single field and enter my phone number rather than entering three digits, press tab, enter another three digits, press tab, then enter the last four. But, that is just my opinion. So, based on your needs, you could concatenate the value before calling the function and remove the check for 7 digits. -
removing duplicate entries in a 2 dimensional array
Psycho replied to Yure's topic in PHP Coding Help
OK, here are some ideas on what I would do. Create the function and create an empty output array. Then loop over each element in the input array. For each element in the array, check if there is a duplicate in the output array. If yes, skip to the next element (i.e. do nothing). however, if the entry doesn't exist in the output array - then add it. So, you will likely need nested foreach() loops - one for the input array, then another inside that to check the value against what is in the output. -
removing duplicate entries in a 2 dimensional array
Psycho replied to Yure's topic in PHP Coding Help
You know, I just looked at the comments in the code. It is obvious you need to create a function (you're even given the function name to use) then it should be obvious you need to iterate through the array [use foreach()] and do a comparison on the name fields. I can understand if you get stuck, but you haven't even started with the easy stuff - well, at least you haven't shown any code to that effect. -
removing duplicate entries in a 2 dimensional array
Psycho replied to Yure's topic in PHP Coding Help
Ok, what error messages are you getting? I don't get any error messages - but I also don't get the results you are after. Because it is not the function you want to use. It would have been my first choice too and I probably would have tried it without reading the entire manual description for the function. But, as soon as it doesn't work, you should probably check the manual for any optional parameters, notes, etc. If you had, you would have seen this So, you need a different approach. What functions/logic/approaches have you been covering? The assignments your instructor gives you usually requires something from what has been covered recently. -
Form validation not producing the error messages when it should
Psycho replied to sabinmash's topic in PHP Coding Help
If you wish you can certainly reject values that are not completely numeric. But, that is not very user friendly. But, that is a decision YOU need to make based upon your needs and requirements. Not sure what you are doing there. I see no logical reason to try to validate three different phone numbers as a concatenated value. I made some assumptions in the changes I made. For example I made the first phone number required, but not the other three. Again, from a user stand-point that just doesn't make sense. Many people do not have three phone numbers. The function simply strips out all non-numeric digits then tests if there are 7 or 10 digits. If no, then false is returned (i.e. not a valid phone number). However, if the value did contain just 7 or 10 digits then a string of just the numeric digits is returned. This line $phone = preg_replace("#[^\d]#", '', $phone); is what strips out the non-numeric digits. The \d represents numeric characters and the ^ means (is not). So, the function replaces any characters that are not digits with an empty character and then returns the result. -
removing duplicate entries in a 2 dimensional array
Psycho replied to Yure's topic in PHP Coding Help
Have you looked at the manual and the functions available for arrays? http://www.php.net/manual/en/ref.array.php There are a lot of array functions and it can be daunting, but if you took 5 minutes just to look at the available functions you should find ones that you could use. EDIT: After thinking about this I can think of many different solutions. If you want help at least come up with something (an idea, a scrap of code, etc) to offer. I'm not going to do your homework for you, but I'll "help" you with it. -
The error is self explanatory. You are trying to include progress.php on every iteration of the loop - thus it is trying to redeclare the class. You only need to include() the class ONE TIME. So, you can either move the include() to occur before the loop starts or you cna change it to an include_once() - or both.
-
Retrieving contents from a page that you're probably not meant to
Psycho replied to manix's topic in PHP Coding Help
Well, it is possible, but not legal - at least not for that link. Unless you get their written permission. http://www.imdb.com/help/show_article?conditions -
Form validation not producing the error messages when it should
Psycho replied to sabinmash's topic in PHP Coding Help
You really need to sit back and figure out exactly how you want to validate certain data. Using an all inclusive methodology is not appropriate. For example, what do you consider a valid phone number? With your current logic it can ONLY consist of numeric digits. But, people are accustomed to entering phone numbers in formats such as 123-456-7890, 123.456.789, (13) 456-7890, or even 1-800-GET-BENT. So, you need to determine what makes sense for your application. For most purposes, I would simply check that the values contains 7 or 10 digits in the value and only store the digits. So, the value could contain other characters, but I would check that there are only 7 or 10 digits after stripping out the other characters. Also, create functions for any elaborate functions such as phone numbers - especially if you will need it more than once. Here is a quick rewrite of your original code. That's not to say this is production ready. I did not test it and I would probably make some other changes, but it should give you an idea of a more logical approach. function parsePhone($phone) { $phone = trim($phone); if($phone=='') { return $phone; } //Strip out non numbers $phone = preg_replace("#[^\d]#", '', $phone); if (strlen($phone)!=7 && strlen($phone)!=10) { return false; } else { return $phone; } } //determine if the form was submitted if ($_SERVER['REQUEST_METHOD'] == 'POST') { //array to hold error messages $errors = array(); //Process post value $firstname = isset($_POST['firstname']) ? trim($_POST['firstname'] : false; $middleinitial = isset($_POST['middleinitial']) ? trim($_POST['middleinitial']) : false; $lastname = isset($_POST['lastname']) ? trim($_POST['lastname']) : false; $phone1 = isset($_POST['phone1']) ? trim($_POST['phone1']) : false; $phone2 = isset($_POST['phone2']) ? trim($_POST['phone2']) : false; $phone3 = isset($_POST['phone3']) ? trim($_POST['phone3']) : false; $email = isset($_POST['email']) ? trim($_POST['email']) : false; $address = isset($_POST['address']) ? trim($_POST['address']) : false; $category = isset($_POST['category']) ? trim($_POST['category']) : false; $gender = isset($_POST['gender']) ? trim($_POST['gender']) : false; //Only accept numbers for phone numbers //Do a validation of required fields if (!$firstname || !$lastname || !$phone1 || !$email || !$address || !$category || !$gender) { //append value to errors array (which we will do again and again) $errors[] = "All required fields have not been entered."; } else { //Check that phone numbers (if entered) are 7 or 10 digits? Don't know what your needs are. $phone1 = validPhone($phone1); $phone2 = validPhone($phone2); $phone3 = validPhone($phone3); if ($phone1===false) { $errors[] = "Telephone #1 is not valid"; } if ($phone2===false) { $errors[] = "Telephone #2 is not valid"; } if ($phone3===false) { $errors[] = "Telephone #3 is not valid"; } /*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($email, FILTER_VALIDATE_EMAIL) === FALSE) { $errors[] = 'Please enter a valid email address!'; } elseif (strlen($email) > 50) { //Make this an elseif - don't need to validate length if the format is not valid $errors[] = "Email is too long!"; } } /*this if method allows to list all errors found from the array, by checking if there are any errors int he error array, if so, loop through each one of print it. If there are no errors, print msg.*/ if (!empty($errors)) { foreach ($errors as $error) { echo '<strong>', $error, '</strong><br />'; } } else { echo 'You\'ve been registered!'; } } -
Form validation not producing the error messages when it should
Psycho replied to sabinmash's topic in PHP Coding Help
Hmm, you have some other problems in the logic and I'm working on a rewrite of your code. Per the current logic you are making the middle initial field required. Are you sure you want to do that? Many people have no middle name. Also, this makes no sense: if((strpos($phone1,".") !== false) || (strpos($phone2,".") !== false) || (strpos($phone3,".") !== false)) { $errors[] = 'Age must be a whole number!'; } What does a decimal in the phone numbers have to do with the age! -
Form validation not producing the error messages when it should
Psycho replied to sabinmash's topic in PHP Coding Help
Your problem is the very first if statement and all the isset() conditions: if (isset($_POST['firstname'], $_POST['middleinitial'], $_POST['lastname'], $_POST['phone1'], $_POST['phone2'], $_POST['phone3'], $_POST['email'], $_POST['address'], $_POST['category'], $_POST['gender'])) For radio groups and checkboxes, the fields are only passed in the POST/GET data if an option is checked. Therefore if you have not selected a gender that first if() condition results in false and validation is never done. Besides you should NOT make that first if statement so elaborate. All you WANT to do is know if the form was submitted - do NOT check to see if ALL the fields were submitted. If anything, that would be part of the validation logic. You should simply use if($_SERVER['REQUEST_METHOD']=='POST') -
The code you provided really doesn't tell me anything about how the value is obtained or used. All I see are a bunch of UPDATE queries. I would expect to see a SELECT query to obtain the points value and then store it somewhere that will be available from page load to page load. If you are storing it in the database then you need to be SELECTing it on each page load. So, you can either store the value in the database and extract it on each page load for the user or you can store the value in a SESSION or COOKIE value. Each solution has its benefits and drawbacks.