Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,537
  • Joined

  • Days Won

    192

Everything posted by mac_gyver

  1. does that mean that the thread you posted on the forum a little over two hours ago no longer needs help? if so, please post a reply in it and mark it as solved/answered so that forum members don't waste their time reading it. as to the problem in this thread. you haven't shown the javascript/jquery code that's attaching the events, but this is a common problem, and it's likely that you will need to use the .on() method, with the second parameter being the selector(s) you want to attach the event to. see the inormation about 'delegated events' at the following link - http://api.jquery.com/on/#direct-and-delegated-events
  2. upon further review (i stopped looking the first time when i discovered the OP wasn't operating on the value correctly), the only thing to OP should be doing in this code is running the INSERT query. the user_name column and the email column should be set up as unique indexes, to prevent duplicate values in those columns. the INSERT query will fail with a duplicate key error (you can look up what error number this is and then check what error number is returned when the query fails) if either the user_name or the email already exist in the table. you should also be hashing the password using the php password_hash() function and store the hashed password in the database table.
  3. @cl0482, there is something wrong with almost everything you have shown us about your database table design, your code, and your statement of what you are trying to do. programming requires a clear definition of what exactly the code is going to do, before you write any code. ignoring that you shouldn't even be inputting a credit card number * and that you shouldn't be storing things like subscription/order data in the users table, your code requires a $_SESSION['username'] value (you should actually be storing the user_id in the session variable) in order to do anything. this implies that the current visitor must already be registered and logged in. this would require there to already be a row for the current visitor in your users database table. to alter the value in the `sub` column for an existing row, you would use an UPDATE query, not an INSERT query. your form would also only have the necessary fields for the subscription data. all the other fields for the user 'registration' data don't belong. * if you need a realistic and safe example of some data to add/update for a user, do something like a date of birth. edit: the following post contains a recommend layout for your code on the page - http://forums.phpfreaks.com/topic/297824-database-issues-and-working/?do=findComment&comment=1519095 following this will group together like things, which will eliminate duplication, and separate the different concerns in the code.
  4. the syntax for a function call would be validateForm() the syntax you current have would be interpreted as a reference to a defined constant and if you had php's error_reporting set to E_ALL and display_errors set to ON, you would be getting an error to help point out the problem.
  5. the chained select script you are using has a 'remote' version that uses ajax to retrieve the data. see the example at the site you posted a link to.
  6. there's nothing in the query that's using any date/time functions, on a column or otherwise. the LITERAL date value (a string in this case) that's being supplied in/to the sql query statement (as part of the sql syntax or via a prepared query parameter) is evaluated by the database engine and converted into a DATE value for the comparison.
  7. ^^^^ literal mysql date/datetime/timestamp values in a query can use any punctuation character as a separator or none at all. the literal values shown are valid and will be parsed to a mysql date value.
  8. your code, on each page of a website, must check if the current visitor is logged in and what if any permissions they have for the duration of the request for that page.
  9. since you didn't share what result you are actually getting, we have no idea which of the many possible things could be wrong. what output did you get and if it's not obvious from looking at it what's wrong with it, tell us what the output should have been. next, we have no idea what the paging class code is, so we have no idea if you are using it correctly. however, it would seem that calling methods like $page->selectQuery(); and $sales = $page->fetchQuery();, before you have set up the paging information is probably wrong. edit: also, processing the form's start_date and end_data values is not mutually exclusive from processing the pagination page number. you should not have the pagination logic, in the first section of code, inside of that particular else {} statement. you should not be putting external data directly into the sql query statement. if this paging class doesn't support using prepared queries, you will need to validate that any external data is exactly and only of the expected format and use the escape string function, from whatever php database extension this paging classing is using, on the data before putting it into the sql query statement. lastly, your form should use method='get', since the dates are determining what will be gotten/displayed on the page. the pagination links should also include any existing $_GET data, so that things like the start_date and end_data will be propagated between page requests. the easiest way of building links is to use http_build_query() for the query-string part of the link.
  10. the mysqli result object returned by a select query ISN'T the data from the query. you would need to test the num_rows property of that object to find how many rows the query matched.
  11. the error is because you are reusing the loop control variable, $result, inside the loop. specifically in the line that when you comment it out, the loop runs. the update query returns a Boolean true when the update query runs without any errors. since you are not using the result from the update query that you are assigning to that variable, why are you even assigning it to a variable? also, mysqli_error(....) requires the database connection link as a parameters. if either of your queries would fail for some reason, you would just be getting another error due to the incorrect usage of the mysqli_error() statement. you should actually be using exceptions to handle query errors and avoid using all the or die() logic in your code. your main code will only deal with error free execution of the database statements.
  12. ^^^^ i have a similar recommendation. before you worry about modifying how this code does something or have someone in a help forum look at it to try to help you with what it is doing, you need to greatly simplify it and update it - 1) use the PDO database extension. 2) use css to style elements. 3) don't suppress errors (if those fetch statement were producing errors, it means that your queries are failing due to a problem with the database connection, database table, or the query syntax.) edit: 3b) only fetch the data you need/use the simplest syntax that accomplishes a task (KISS - keep it simple...). you are just using associative data from the query, just use a fetch statement that retrieves the data in that format. your current code is fetching both numerical and associative data, which is the default for the statement you are using AND you are also supplying the optional parameter telling it to fetch exactly what the default is. 4) don't loop to retrieve query results when there's only one row. there's only one place in this code where the query can match more than one row. that's the only place where there should be a loop. 5) separate your database 'business' logic from your 'presentation' logic. this will also help you avoid trying to run queries inside the presentation logic, who's responsibility is to produce output. 6) don't run queries inside of loops and DRY (Don't Repeat Yourself). the main part of that repetitive logic can all be replaced with simple code. there won't be a TON of related products for any selected product. just run one JOINed query to get all the related product information at once and retrieve it into an array. if there's more than 4 results, shuffle the array, then split off the first 4 entries. then, just loop over the 4 random entries or the original data, in the case where there were 4 or less results. you would produce the final output in this loop. edit: 7) the input to this code is an id. you should make sure it was supplied before trying to use it.
  13. i hope you mean your web host. your isp wouldn't have anything to do with web hosting. you also should be learning and developing php code on a local development system, not an a live server at a web host. those two settings may be set somewhere to those two values, but hey are not in effect. in both of your threads you would have been getting php errors that would help you find the problems, but you are not getting the errors or they are being hidden somehow.
  14. your current javascript code isn't doing anything when there's a failure of the php code to send a response back, which is more than likely what's happening, due to a fatal run-time error. the extra layer due to the ajax is just hindering any learning/development of the core code. you need to get this working without the ajax first, then simply add/enable a general purpose event listener/ajax form submitter to switch to using ajax. your html form markup should be the same regardless of using ajax and it can and should work even if javascript is turned off.
  15. you have a couple of incorrect $_POST index names. if you had php's error_reporting set to E_ALL and display_errors set to ON you would be getting some undefined index errors alerting you to which ones.
  16. you have an extra comma, right near where the error message is calling your attention to. and as already mentioned, why are you using a prepared query, but still putting (external) data directly into the sql statement?
  17. you need to have php's error_reporting set to E_ALL and display_errors set to ON in the php.ini on your development system, so that php will help you by reporting and displaying all the errors that it detects. you will save a TON of time. edit - lol, which you were already told you needed to do in your last thread. for your first problem, you will be getting undefined array index errors, since the name of your <select > form field is - 'players' you should also be using a method='get' form since the form is determining what will be gotten/displayed on the page. for your second problem, you have a variable name mismatch, between what you are storing the result from the query in and what you are using in your loop, that php would also be giving you errors for. p.s. - the forum's bbcode tags are - and can be applied by selecting the code and hitting the <> menu button.
  18. not sure what your definition of a project is, but you can probably solve this by using a different session name for each independent project.
  19. if the $state variable is undefined at the line 504+ code, either it has been unset() at some point or there's a variable scope problem. is the line 504+ code inside of a function definition or is it being included into the page using a URL instead of a file system path?
  20. if you are at the point of needing someone to tell you where to put lines of code, you are not ready to be doing this. we are not here to spoon-feed you with each piece of information, and where to put it in your code, that you need to know in order to do this. you need to read up on some basic php information. start with the php.net documentation, 'Getting Started' section and at least the 'Basic syntax' through 'Functions', 'Errors', and 'Predefined Variables' sub-sections of the 'Language Reference' section. as to the validation section of your php code, you should use an array to hold the validation error messages, then at the end of the validation section, if there are no errors, the array will be empty, use the submitted form data in the rest of the code. if there are validation errors, you would display them, along with re-displaying the form.
  21. you are outputting all the product information inside of one <form></form>, so only the values from the last set of same-name form fields 'wins'. wouldn't you want to output the information for each product in it's own form, so that when you submit any one form, the only thing that gets submitted is the data for the product that you want?
  22. when you insert new item(s) starting at position number x, all current items having a position number > x would need to have their position number UPDATEed to be their current value + the number of items that are being inserted. an insert of new data would involve an UPDATE for the position number field for some of the current items, followed by an INSERT for the new data with it's now vacated position number(s).
  23. either the query is failing or the data being submitted doesn't match any row(s) or is being updated to the same value it started with and the UPDATE query doesn't affect any row(s). it would take seeing how you were checking/displaying/logging errors, since the method being used may not have been effective, since you are using ajax to submit the data. you should ALWAYS have error handling in your code and for development, display any errors, and when on a live server, log any errors. your code should also be testing if the UPDATE query actually changed each row. the php database extension you are using will have an 'affected rows/row count' method you can use to do this. you haven't stated what exactly isn't working. are none of the row(s) being updated? are only some of the rows being updated and if so, which ones? are the rows being updated with the wrong values? you also haven't stated how you know it isn't working. what method/tool are you using to look at/view the result, since, there may be something wrong with the method (showing cached values as an example.) another possibility is that the data contains white-space characters, which print_r() won't directly show. you should use var_dump() instead, since it will give the length of the data. i suspect, that the problem will be ultimately due to using a get request and that the browser/client-side code is making two requests to your page. there is a ton of information to be found, on any subject, just by searching the web for it.
  24. for file_get_contents() to work with a url, the allow_url_fopen setting must be ON and since you are using the https protocol, the openssl extension must be present and enabled. you should be getting php errors associated with either of these things, if you have php's error_reporting set to E_ALL and either display_errors set to ON or log_errors set to ON.
  25. you need to tell use about the times it doesn't work and tell us exactly what part of it doesn't work and how you know it doesn't work. is the submitted data correct or not when it doesn't work? are there query errors when it doesn't work? do you have error checking for the query? you should also be using a POST request to send the data to the server (so that just making a get request for the page cannot mess up your data) and you should be using a prepared query to supply the external data to your sql query statement.
×
×
  • 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.