Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. if someone tries to log in and the entered username/password combination doesn't match, that doesn't mean they haven't registered. what if they miss-typed the value for either field? you would output a generic 'The username/password didn't match' message for this case and let them try to log in again. if the current visitor is not logged in, you would provide a link to the registration page, near the login form, for them to click on if they desire to register. you would this when they register, not when they log in.
  2. you would only allow logged in users to post. your log-in system would store the user id in a session variable. you would both test if the session variable is set before presenting any output needed to post comments and processing any form submission and you would get the user id from the session variable when forming and running the INSERT query to save the posted comment. you would get the product id from the content you are displaying that you are allowing comments to be posted for.
  3. <option ... ></option> tags need value='...' attributes, not id's. i recommend that you write and test one small section of code at a time and only go onto the next section when you have determined that previous section works correctly.
  4. it's not clear what you are asking, since we don't know what your 'business rules' are that determine which query to run or what result you expect. however, i suspect you are asking how can you form and run any arbitrary SELECT query without writing and repeating different variations of the php logic depending on what the query is? if so, you need to write a general purpose query method, that you extend the main database class with, that accepts a built up sql query statement and an optional array of bound input data that corresponds to any place-holders in the sql statement. your main application code would build the sql query statement and the array of bound input data, then just call the general purpose query method when it needs to execute a query. unfortunately, you shouldn't use msyqli to do this, since it will require dynamically binding the input and the output data, which will require either using call_user_func_array() or the reflection class, since you must supply a variable number of parameters to the mysqli bind_param() and bind_result() calls. if you instead use the PDO extension, doing this is simple, straight forward, and will run fun significantly faster than using msyqli based code.
  5. since there was a php syntax error, that means the php.ini where you have placed the error_reporting/display_errors settings likely isn't the one that php is using. you need to make sure that your development system is set up to report and display all errors before you waste any more time on problems.
  6. because, for the example code you are posting, it has a php syntax error in it, and the code never runs. do you 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 it detects? note: for a php syntax error in your main file. you cannot put the error_reporting/display_errors settings into your code since your code never runs in this case to make use of those settings.
  7. there's a whole bunch of things wrong with this code that will prevent anyone from helping with it. some of the problems - 1) global $some_variable; only has meaning when used inside a function, where it shouldn't be used anyway since it leads to bad coding practices and, if this code is inside a function, that's a bad design since a function should only do one small thing. 2) you cannot (successfully) use the ip address to associate a cart with a user. if the user is logged in, you would use the user id. if the user isn't logged in, you would use the session id. 3) to display the contents of the cart, you would run one JOIN'ed query to get the cart and the product details at one time. 4) making the product price an array, then using array sum on an array containing one entry makes no sense. you would also want to take into account the quantity of the item when calculating the total of the cart. calculating the quantity times the running total inside the post method form processing code makes no sense. 5) any post method form processing code should be separate from your html markup and be near the top of your code file. it should also validate the submitted data (what if the value is negative number, what if the value is a zero) and use a prepared query to protect against sql injection. your update query is also missing an important part, which row(s) is it supposed to be updating? after successfully running the post method form processing code, you should do a header() redirect to the same page to cause a get request to re-display the page. 6) you would want to output the existing quantity as the value in the quantity form field so that the user can edit the quantity. 7) you would also process any remove checkboxes in the form processing code. 8 ) the form field for the quantity needs to be an array name and use the product id as the array key and you might as well have the 'remove' checkbox use the product id as the array key instead of as the value. 9) if the cart is empty, you would want to output a message stating so.
  8. your design has some user experience UX problems. by using a select/option menu, the user must first click the select button to see the two choice to pick from and since each week is its own form, only one selection can be submitted at a time. if someone was setting up all 52 weeks, it would take 156 clicks and 52 form submissions and re-displays of the page. if you instead use radio buttons and a single form, the user can go through and select or change any of the week values by simply clicking on the choices and hitting one submit button. that would take only 53 clicks and one form submission to set up all 52 weeks. p.s. you are missing a " in your html markup, probably lost due to the escaping \" going on. you should use single-quotes ' inside of a double-quoted string so that the code is not cluttered up with escape characters.
  9. For the case you have just posted, php's output buffering is turned on in the php.ini or possibly .htaccess file (if php is running as a server module) on your server. You can determine this by looking at the output from a phpinfo() statement.
  10. It sounds like your code also contains output buffering statements. these will have an affect on the OUTPUT of the content to the browser and could cause one instance of a header() to work and the other to not. if that isn't what is causing the current symptom, you will need to post the code that reproduces the symptom and identify which header() statement in it does and which doesn't trigger the error message. also, for the case where you don't get the error message, does the header() redirect work or does the code stay on the same page? it could be that the error is occurring, but the message is being hidden or suppressed.
  11. i would run one JOIN'ed query, then calculate the $result1 value while looping over the rows from that one query. the following query should (untested) work - $query = "SELECT g.Location, g.Date, g.HomeTeam, g.AwayTeam, t1.Teamdata1, t2.Teamdata2 FROM datagmaes g JOIN gamesdata t1 ON g.HomeTeam = t1.Team JOIN gamesdata t2 ON g.AwayTeam = t2.Team"; you should NOT apply number_format() to the Teamdata1 and Teamdata2 values. number_format() is an output function and should only be applied when you display the number, not when calculating or storing data.
  12. textarea's don't have value='...' attributes. you output the existing content in between the <textarea>content goes here</textarea> tags.
  13. firstly, you are not dealing with web links. include/require statements deal with files, i.e, paths and names. what does echoing $_SERVER['DOCUMENT_ROOT'] give? If the server is set up correctly, it will give - /home/youraccount/etc.., i.e. the path to your account's document root folder, and note the leading / which refers to the root of the current disk. you would just append the folder to where the included files are at to this value, not append the entire path to your document root folder again.
  14. i'll give same advice i gave a little over an year ago when you moved from shared to dedicated hosting - http://forums.phpfreaks.com/topic/294527-transfer-my-website-from-shared-hosting-to-dedicated-server/
  15. yes, just about anything is possible in programming, that's why this is called software. if it doesn't do what you want, it can be changed so that it does. however, this code is badly organized, to the point that it would take rewriting and retesting it just to get it to the point where it could be understood and then be modified to work differently. the code should be organized as follows - 1) initialization 2) post method form processing code 3) get method business logic - code that gets/produces data that's needed for the dynamic content on the page 4) get method presentation logic - code that knows how to produce the dynamic output on the page (for simple processing, this can be handled in the html document/template system.) 5) html document/template - produce the html document, or portion this code is responsible for, based on the result from the above sections
  16. there's no (good) reason that an application wouldn't allow any number of users to concurrently visit any page on a site and produce a result specific to the visitor. the code must therefore be doing something wrong, which we cannot tell you without knowing what exactly the code is. code would typically either use session variables or store data in a database using the user's id and any number of different visitors could be accommodated.
  17. assuming you are doing this as a learning exercise - you don't. users/admins to a site don't need to know or care what the database table structure is, so, you don't need to limit what tables (i'm assuming you mean database tables) they have access to and if you are dynamically making database tables to hold the content for each different user/admin, that's not how you would do this. the database tables you have, are what your APPLICATION needs to accomplish it's goal. it's your application code that has access to the database tables. all the content for a Content Management System would be stored in the same database table. controlling who can Create, Update, or Delete record(s) in that table would be handled by the user permission system, based on the user's assigned permissions or assigned role and ownership of the record(s). you should have a (one) user table that holds the unique user information. the user permission system would store its data in a separate set of tables, using the user id from the user's table to associate the assigned permission to the user it goes with. as to a user permission system, do some research on ACL (Access Control List.) in its simplest form, this defines actions that can be performed (create, read, update, delete) and assigns those actions to specific users. by creating groups of actions, you define roles, that you can assign to a user (in addition to any of the specific, overriding, actions), such as an owner(superadmin), admins, authors, members, guests. to limit Create/Update/Delete access to only those records a specific user created/authored, in addition to storing the author's user id in a column in the row of data, there would be a set of defined actions that limit access to the user with the matching user id. to allow an admin to be able to edit anyone's content, there would be a different set of defined actions that ignore the id of the author of the record. initially, to get the permission system started, you would manually store the user id of the person who is the owner/superadmin into the permission system, with a defined action that allows him/her to perform all possible actions. when that user logs in (and re-authenticates when making changes to user permissions), they would be able to, using an appropriately written user interface to the permission system, assign roles and/or specific actions to other users and also create and manage the actions and roles of the permission system. the code for any 'action' on a page would test if the current user has permission to perform that action and if the specific permission requires it, ownership of data, before performing the action.
  18. and if you make an array of the bedspace values, like they had been retrieved from a db table, you can dynamically produce the bedspace select/option menu by looping over the array, without needing to write out and the test and fix all that code and markup. btw - the <select ... value="..."> tag doesn't use a value="..." attribute and the one you are showing in your code should be removed since it doesn't do anything.
  19. there is no 'regex replace' in mysql. the regex pattern match would only let you find the rows containing the data that you need to update. to do this in a query would require that you use string functions to find the position of the start/end of the number in the string, split the string to get the number part, add the amount to the number, then replace the value in the string. you would be better off retrieving the data using php and use preg_replace to modify the data. if this is a regular occurrence, i.e. you set/update the value regularly, the value should be stored separate from the string it is in.
  20. this is the same basic task as in your previous thread - http://forums.phpfreaks.com/topic/301791-looping-results-from-query-and-limit-amount-per-row/ the sql query would join the table to itself to get the category/sub-category information using one query. then, change the $items_per_row = 5 value to 8, and make any changes you need to the html markup that's being produced.
  21. the code in question is now inside a conditional statement if($num_esb > '0'){ ... }. in the original, it was not. it was outside of and after the end of the conditional statement. you need to update the msyql_ statements to something more current. the msyql_ extension has been removed from php and your code won't run at all on current php versions. the PDO extension is the best choice to switch to. while you are making the changes necessary to keep the database code working, you should clean up all the repetitive code and consider using a template to produce the html document. you currently have a "cannot see the forest for the trees problem", which is one reason you missed putting the pagination links in the right place in the changed logic. the file has 670 lines of code, of which there is probably only about 400 lines that are needed.
  22. you would want to store the data in column defined as a decimal data type - http://dev.mysql.com/doc/refman/5.7/en/fixed-point-types.html
  23. actually, i'm wondering if the <script>....</script> can be inside the form. you can move it to after the </form> tag to see. in any case, just telling us that something was not successful is not helpful. what did it do and when you debugged the problem in the browser developer tools/console and in the client side code, what did you find it WAS doing or not doing correctly?
  24. setting php's error_reporting to E_ALL and display_errors to ON (which should already both be set this way in the php.ini on your development system), should help with finding the cause of the problem. does the 'view source' of the page show all the repeated sections of content? maybe there's a broken html comment or tag that's preventing the output from being rendered by the browser. also, does the content, that's after the end of the loop, get displayed?
  25. you need to test the value being returned by the mail() function. if it's a true value, it means that php was at least able to successfully hand the email off to a mail server (doesn't mean that mail server is going to do anything with it or that the receiving mail server will accept it.) if you get a false value, there should be a php error providing information as to why either php or the mail server isn't going to do anything with the email. you can get the last php error information using - error_get_last() (returns an array of information.).
×
×
  • 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.