Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,350
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. it would take seeing the echo/var_dump() of the $sql statement and seeing the result of a SHOW CREATE TABLE your_table query in order to help you further. you have also implied there may be two separate queries being ran because the debugging output shows two print_r() arrays worth of data - Array ( [0] => 00000 [1] => [2] => ) Array ( [0] => 42S22 [1] => 1054 [2] => Unknown column 'postcode' in 'field list' ). any chance the code is being called twice, the first time it runs a query without error, and the second time, whatever the actual query is, produces an error? and while you are checking the database table definition, make sure you don't have multiple databases and that you are selecting the correct one to run the query against and that you are connecting to the correct database server as well.
  2. this is going to seem like i am giving you a hard time, but how about taking the information you have about the pre-defined values the dropdown menus will submit to your php code (i.e. the input data), then try to write some code that does what you want and produces the WHERE clause you need for the sql query statement? do you even have the search form coded so that you could test to make sure it is submitting the proper values to the php code and so that you could experiment with the php code you are writing to see if it produces the expected result for each of the expected combinations of inputs? i recommend use a method='get' form, since you are telling the page what data to get/display.
  3. other than a mismatched closing </form> tag (there's no opening <form> tag in sight) being output inside of a loop and running queries inside of that same loop, there's nothing obviously wrong. it would help if you did a 'view source' of the page in your browser, on both systems, so that you could tell what the actual html looks like. perhaps some broken html is hiding the results in the source on the page and causing the content to not be displayed. have you validated the resulting html page at validator.w3.org so that you know if the html is all valid? it would also help if you looked in your database table using a tool like phpmyadmin on your live server to conform you actually have the data that you think.
  4. your table holding this information would have a unique composite index (key) for the user_id and provider_id. in addition to the normal table definition, you would have/add this - UNIQUE KEY `some_key_name` (`user_id`,`provider_id`) at the point where you know the user_id and the provider_id in your php code, you would simply run a query to insert that data - INSERT INTO your_table (user_id, provider_id) VALUES ($user_id, $provider_id) assuming you have error checking logic in your code, that's testing if the query returned an error, an error value from that query of 1062 (a duplicate value for the unique index/key), would mean the combined value of user_id/provider_id was already in the table and it wasn't inserted. you can safely ignore this error. any other error value would mean the query failed due to an error that you should find and fix the cause of. if there isn't an error, it means that the combined value wasn't already in the table, but it was inserted by the query.
  5. the problems you are having in this thread are all syntax errors, i.e. grammar, punctuation, spelling... errors. they are not actually programming problems yet, because your code didn't get past the first step php takes of parsing (similar to proofreading) the code to see if it can understand what you wrote and can run it. learning a programming language is pretty much the same as learning a linguistic language, except there are actually fewer rules to learn for a programming language and a programming language must be exact, where as there can be slight errors in the usage of a linguistic language and it can still be understood. when learning a linguistic language, you must first learn and practice the basic grammar, punctuation, spelling,.. before you can hope to be understood by someone else using that language. the same is true of php. you must first learn and practice the basic grammar, punctuation, spelling,.. of the php language before php can understand and run the code you have written. the reason programming help forums don't have sections showing the basic grammar, punctuation, spelling,.. used by php is because these things are already completely covered in the php.net documentation, which is the defining source of all the php language information.
  6. it's not hard at all to debug php code. that you know a specific function is returning a false value, means you have narrowed down the problem to a specific section of code. i in fact gave you a specific debugging suggestion in your previous thread, along with the suggestion to actually have proper error handling logic in your code to get it to tell you when, where, and why it is failing - http://forums.phpfreaks.com/topic/292690-call-to-a-member-function-on-a-non-object/?do=findComment&comment=1497936 and here http://forums.phpfreaks.com/topic/292690-call-to-a-member-function-on-a-non-object/?do=findComment&comment=1497716
  7. when you use ? place holders in the prepared query, you would use numerical indexes in the bindParam() statements. your $stmt->bindParam(':Workout', $YesOrNo); would need to be - $stmt->bindParam(1, $YesOrNo); repeat for parameters, 2, 3, 4, .... here's the relevant php.net documentation -
  8. if you set up the unique composite index, the way i suggested, you don't need to query for anything or loop over anything. you just insert the data. if the client/provider pair doesn't exist, it gets inserted. if it already is in the table, it doesn't get inserted and produces a duplicate index error that you can choose to ignore in your error checking logic.
  9. the point of programming help forums are to help those who are trying to program. we are not here to read through, find, and fix problems in 700+ lines of code that someone else wrote and isn't supporting. if that's what you need, post in the job offers/freelancing forum section. to get help in the forum section you have posted in, you need to narrow down the problem to just the relevant lines of code where the issue is at, make an attempt at solving the problem, then post your attempt along with any symptoms or errors you got from that attempt. supplying a sample of the input data being use by the specific section of code would be helpful as well. edit: for each of the deprecated errors you are getting, the php.net documentation for those functions provides information about the functions that replace the deprecated ones.
  10. i have a suggestion that doesn't require writing out and/or editing a bunch of lines of program logic. use a data driven design - // data arrays: 1st element - start/low (inclusive), 2nd element - end/high (exclusive), 3rd element - value (whatever you need, a literal value, an array, an object...) $d[] = array(0,1,'rgb(195, 218, 236)'); $d[] = array(1,2,'rgb(210, 238, 197)'); $d[] = array(2,3,'rgb(244, 240, 202)'); $d[] = array(3,4,'rgb(244, 223, 202)'); $d[] = array(4,5,'rgb(240, 199, 205)'); $d[] = array(5,21,'rgb(212, 195, 236)'); $magnitude = 4; // an input value for testing $magScale = ''; foreach($d as $e){ if($magnitude >= $e[0] && $magnitude < $e[1]){ $magScale = $e[2]; break; } } if($magScale == ''){ echo "no matching mag scale found"; } else { echo "For magnitude $magnitude, mag scale - $magScale"; }
  11. at the time your code is running and isn't working, $title is likely a string. $title[$i] is iterating over the characters of that string, and $title[$i][0] = is trying to assign a value to a character element of the string as though it is an array. what does using var_dump() show for the contents of $title and what is your code that defines $title? i'm going to guess that this is due to re-usage of a variable that exists in your main code as a string. when you run this included code directly, that variable doesn't exist at all. if so, use a different variable or initialize it to an empty array before the first use in the posted code.
  12. ^^^ this is your goal for the form processing code (after the form has been submitted.) the leave, date, and empId are the only relevant values from the form to use in the form processing code. your form processing code, after if validates the three input values, should take the empId value, retrieve the other necessary values (note: the name should only be in the employee table, you should not store it in the payroll table, just store the empId) from the employee table, perform the calculations you need, then insert the resulting information into the payroll table.
  13. the error typically means that php found the end of a string where it wasn't expecting one. the error message also included a line number to give you a starting point to look at to find the problem. we cannot specifically help you without seeing the code leading up to the point where the error was discovered. if you post about 10 lines of code leading up to and including the line where the error is being reported at, someone can probably help you.
  14. your code is a mess, and i don't mean because it got posted from wherever you pasted it from without newlines showing in it. your database tables are not designed properly (not normalized), resulting in you needed a bunch of extra php code to manipulate the data (the error is in the bunch of php code you wrote.) also, whoever is teaching you to code is making your life harder than necessary, by not teaching you to use meaningful names for the columns in your database tables or for your php variables or teaching you how to build php strings and echo php variables using the simplest syntax needed. look at the following line of code and see if you don't notice a problem with it - echo "".$M1."".$S1."."$N1". ".$H1." ".$K1.""; you have used just about every possible combination of variable, quote, and concatenation dot in that line. i'm guessing you wanted to echo those variables with spaces between each one. all you need to do that is - echo "$M1 $S1 $N1 $H1 $K1"; // use the simplest syntax that works
  15. if by that you mean you are using a second class on top of the PDO class, the problem is likely in the code of that class.
  16. you should NOT use calculated values that come from the browser, as they can be set to anything that anyone wants. any value you calculate and output to the browser should be for display only. the value you actually use on the server should be calculated on the server only, so that no one can manipulate the values. all the other values that you are storing, like basicSalary, should not be the values from the form, but should be the current values from the employee table. lastly, as to the reason your code doesn't work. the $leave variable that you are using in the calculation doesn't have a value until after the form has been submitted. the empty string you are setting it to near the start of your code to prevent undefined variable errors is just hiding the problem.
  17. we can only help you with code problems if you post the relevant code and whatever symptoms or errors you are getting that lead you to believe your code isn't working. P.S. - the code you posted, that's now post #8 in this thread, needs some serious reorganization. you have your form processing code intermixed with your form/html output. the form processing code should all be together and be near the start of your file and it should not have any html markup in it. the code that retrieves data to be output on the page and the code that produces the html should be at the end of your file. the code that is database dependent should store it's result in php variables that the code that produces the html output should use as input data. the code that produces the html output should not have any database specific statements in it. by grouping the form processing code together, it will be easier for you and us to help you with the current task of adding validation logic to it, because you will only need to post just the form processing code.
  18. the correct way of doing this is to INSERT a new row in your reward_points table for each new provider that a client picks. you would also have a unique composite index defined for the user (you should be storing the user id, not the user name) and the provider id. this will enforce uniqueness (i.e. no duplicate user/provider combinations.) to get a count of providers that a client has picked (i.e. the number of reward points), you simply get a COUNT() of the number of rows for any client.
  19. the problem is likely in your php code that's retrieving the data or that's displaying the result. have you ran this query directly against your database, using a tool like phpmyadmin, so that you know if it returns the correct result? because you are grouping by the browser, there's no need for the initial DISTINCT keyword (which removes duplicate rows from the result set), since you will have only one row for each different browser value in the result set.
  20. it's because you copy/pasted some code from a post and the LOGIC behind the wysiwyg editor and just about everything else of the ipb forum software is lacking. to see what your post really is, you must switch to the text mode, the light-switch looking thing on the upper-left-hand side of the post form.
  21. the form field you added that does have a name of SignUpButton, is outside of and after the end of your form, so it is not part of the form data.
  22. no. and in the cases where you do specify a url (that resolves to the ip of the database server), it would be the url of the database server, not the url of a web server. typical urls would be something like mysql1.example.com. if you are having a problem on your hosting connecting to the correct database server for you account, you can find the correct hostname to use from your web host and it is also typically displayed on the page (phpmyadmin) where you created your databases/database tables.
  23. you shouldn't try to use time for this. multiple pieces of data can be inserted in a single second and during the same second that you are trying to retrieve data.. you can have data with the exact same time stamp with rows that were inserted before you run a query to retrieve data, that the query will find, and with rows that were inserted after the retrieval query was ran that you won't find. this is a bug that has plagued things like Vbulletin's forum software for a time (no pun intended) now. also, for the code Alex_ posted above, that's trying to compare the client's time with what's been stored on the server, this isn't reliable since it assumes that the clients time zone is related to (all) the data stored on the server and that the client's exact time (seconds) is synchronized precisely with whatever time source was used when the data was stored. instead, take a lesson from the SMF forum software, where the id (auto-increment database field) of the last retrieved/displayed information is carried in the url's and is used to find any rows inserted since that information was retrieved and displayed (in the case of SMF software, they are doing this to display 'new posts where made since you viewed this thread' and they are also using the thread id to qualify the results to the current thread being viewed in the browser.) this seems similar to what the op stated in the first post, but you must query for rows that have an id greater than the 'last displayed id'. you cannot check for a quantity of rows matching the id value since id's may not be contiguous if rows have been deleted.
  24. if you retrieve the current highest value, increment it, and try to use it, yes there exists the possibility of a race condition causing two ore more concurrent instances of your script to use the same value. you would need to lock the table to insure each value only gets used once. instead, you would use an auto-increment column in the database table, since the database locks the table for you during the INSERT query and will automatically prevent any duplicates from being used. If you need to get the auto-increment value that was just used in an INSERT (or update) query, you can retrieve it via a query or most database libraries have a dedicated function/property to retrieve the value.
  25. your form does not have a form element with the name SignUpButton, so your php code if (isset($_POST['SignUpButton'])) { will never be true. it is recommend that you detect a form field that will always be present in the submitted form data (submit buttons cannot be guaranteed to be present, if you use the enter-key to submit the form (IE and Opera browsers) or use javascript to submit the form.) either test for a non-disabled text/password/textarea field or add a hidden field.
×
×
  • 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.