Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,369
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. in actuality, once you have the necessary database tables set up, the only thing you need to do differently in any cart code to accomplish what i suggested is to change the queries that operate on the data. the following is a little different from what i described above (which is why you should work out the details yourself, rather than follow along with what someone quickly writes out in a post somewhere on the web.) instead of having a query that updates a row to subtract the quantity in your products table, you would instead insert a new row into a different table (such as a cart/order_details table), with the item id and the quantity that was ordered (if you store the cart in a database table, instead of a session, this step isn't needed since the item id/quantity would already be in a database table.) any query that needs to get the current quantity, instead of reading the row(s) from your products table, would take the quantity on hand and subtract the SUM() of the quantity from this new table. if you do an advanced search on the forum for 'cart' and my user name, you should find a lot previously written information about this. in fact, see the second half of the post at the following link -- http://forums.phpfreaks.com/topic/286051-php-shopping-cart-and-quantity-help/?hl=%2Bcart&do=findComment&comment=1468275 and i added the forum's bbcode tags around your posted code above, as that may have been a reason no one bothered to look at the code to offer any specific help with it.
  2. prepared queries aren't just about security. $variable = "Mc'Gyver"; results in broken sql syntax and an error.
  3. the main point of using a prepared query is to bind data into the syntax of the query. the syntax of the query, less the data, is what is being prepared. the data values are actually supplied and inserted when the query is ran, so that there's no possibility of sql injection. by putting a variable holding raw data into the sql query statement, you have side-stepped the process, and allowed sql injection. @deathbeam, putting a variable directly into the query being prepared, in itself, doesn't cause any type of error. in the php context, the sql statement is only a php string that is being built.
  4. sorry for this, but we are not here to find or to give you things you need or want, because we don't know the requirements of your assignment or what your skill level is. that's NOT a suggestion to post your requirements. the only person here who can find what you are looking for is you. we can help you with specific questions you have once you have attempted to do this and have actual code and symptoms or errors you can post or if you have a specific question about how to do some part, again after you have attempted to figure it out first.
  5. the code is doing exactly what it was written to do. if you want it to produce different specific data, you will have to write the query and code that does what you want. if you want to graph one bar for each/any month, with the total for that month, you will have to produce data that does that. [month name,total for that month],[another month name, total for that month], ... you should do this in the query, like the example that Psycho posted (modified for a total and $type you are actually doing), which if you are going to do this in general for any range of dates, would be the best place. to get the month name, you would either convert the 9 to the name in your php code or you can use the mysql MONTHNAME() function in the query. edit: in addition to what others have mentioned, i recommend that you use table alias names in your query to reduce the clutter and make it easier to read and easier to write in the first place.
  6. just because an update query runs without any errors, doesn't mean that it actually updated the row, if the WHERE clause if false. you should also be testing if the number of rows updated is greater then zero. to debug the problem of why the update query isn't updating the data, have you echoed the $query variable so that you know it contains what you expect?
  7. see the sticky/pinned post for this forum - http://forums.phpfreaks.com/topic/150979-this-board-is-not-a-code-repository/ php help forums are not for finding or giving you code that you want or need. we are here for helping with actual code problems. topic locked.
  8. you are also going to need to ask specific question(s). just posting a list of requirements, isn't asking a question, but it is a fine start at a request for quote to hire and pay someone to do this for you. we are here to answer specific questions that you have, after you have made an attempt at solving your programming problem.
  9. one of the most likely reasons for session variables not working when redirecting all over the place is that the redirects are switching back and forth between having and not having the www. on the url, because by default, a session will only match the variation of the url where it was set.
  10. given that you are using the DISTINCT keyword, i doubt there are exact duplicate rows. i suspect you mean that the job information exists in each set of rows for any job_id. if that's the case, that's how joined queries work. if that's not the case, you would need to post the result you are getting. however, that query is not what was suggested. you either need to separate queries, one for jobs and messages and the second for jobs and quotes OR if as has already been stated, if the columns you are selecting for messages and quotes are similar in meaning (because the UNION query will use the column names from the first query in the UNION), you can write one query that combines these two queries as a UNION query.
  11. the short answer is to treat your inventory as a deposit/debit account, where you have a row for each transaction. each row contains all the who, what, when, where, and why information about the transaction. when inventory is added (including the initial quantity), you insert a row with a positive quantity (deposit). when inventory is added to a 'cart' and the person go to the checkout stage, you would you add a row to the database table for each item in the cart, listing a negative quantity (debit), but with a status value that indicates is has been 'ordered'. when the item is actually pulled and shipped, the status for each item would be changed to 'shipped'. to get the current quantity of any item(s), you would simply run a query that sums up the positive and negative quantities for each item id/item number.
  12. @Richard_Grant, is_int and is_string test the type of a variable, not what's in a variable, and by definition all $_POST data are string variables, no matter what's in them.
  13. posting a sql dump of just your table definition, would help someone to recreate/debug the problem.
  14. it's likely that your new-lines in the csv file doesn't match $lineseparator = "\n"; where/how is the csv being produced and are you editing it at any point, where your editor could be modifying the new-lines?
  15. have you ever successfully sent an email from the server where this is running? does your web host have any smtp authentication or other requirements to send email? there may be a mail server that accepted the email from the php mail() function and didn't return an error to php, but that mail server may not have any intention, or ability, of actually sending the email to the recipient or it may not even be the correct mail server to use at your web hosting. it's also possible that the dns records where the domain in your From: address is hosted at are either nonexistent or miss-configured such that the receiving mail server cannot determine if the sending mail server is authorized to send the email, in which case the receiving mail server may simply discard the email. is the From: address an actual working mail box, so that any bounce/error messages from the receiving mail server would have a place to go and can be viewed? and while the From: address should get used as the Return-path: address for bounce messages, you can specifically include a Return-path: in the header. edit: also, which email address are you not receiving at, the To: address that you are entering in the form (and have you confirmed that the form is posting a value to the code), or the Bcc: address that's in your code or both?
  16. that's not correct jazzman. the posted code is escaping/casting each data value as it is building the string being put into each array element. each array element is one complete value section of the query - (1, 'a string', 2.34) (with the surrounding ()). the implode is just combining all the array elements into the VALUES section of a multi-value insert query. any escaped data in the array elements will still be escaped in the resulting sql statement. you cannot escape any of that afterwards since that would change the quotes that are part of the sql syntax. if there was a string data value - this contains a ' in it, the posted code will produce - (1, 'this contains a \' in it' ,2.34) your suggestion to apply the escape function after or as part of the implode would produce - (1, \'this contains a \' in it\', 2.34), which is not correct. the posted code produces the following actual sql query statement for some test data - INSERT INTO order_line_items (order_id, company_id, item, unit, unit_cost, quantity, tax, total) VALUES (0, 0, '123', 'this contains a \' in it', 0.00, 1, 1.00, 2.22), (0, 0, '456', 'this contains a \' in it', 0.00, 2, 2.00, 4.44) the only problem with the posted code, outside of any typo's, may be that the $item value is likely an id, not a string.
  17. $_SERVER["REQUEST_URI"] contains the path/file and also includes the url query string.
  18. this is the same error you had in your first thread on this forum. are you learning from your experience so that you don't repeat the same problems? you also used the mysqli database functions in your second thread on this forum. why now go backwards using the msyql functions?
  19. that would be two separate queries or a carefully crafted UNION of two LEFT JOIN queries.
  20. the while(){} loop in your code is - a) incomplete, it is only echoing the first line. you should always use opening and closing { } in conditional statements. b) it's unlikely that you have a column named value1, value2.. if your purpose is to loop over any/all columns that the query selected, you would do just that. $row is an array. use a foreach(){} loop to loop over and echo each element in the array.
  21. programming is an exact science. the values you are producing in your <option > tags are not just the table name, they contain html <br> tags as part of the value. when you echo <br> tags to a browser what do you see? white-space, specifically a new-line. people with thousands of posts and years of experience wouldn't have told you that the form has a problem if it didn't.
  22. we can only help you if we know what errors you are getting and what the corresponding code is.
  23. and please use the forum's bbcode tags (the edit form's <> button) around code when posting it in the forum.
  24. if the relationship is between jobs and quotes and jobs and messages and there is no relationship between quotes and messages, then you actually need two queries (unless the columns you want to retrieve from quotes and messages happen to correspond exactly so that you could use a UNION query.)
  25. the error message contains the database name and the table name to give you as much information about the problem as possible. that the database name is part of the error message is not the problem. the problem is you are supplying a table name that either doesn't exist or has some white-space as part of it or has a capitalization problem (and you are on an operating system that is case-sensitive.) that you are not posting actual information makes it hard to help you, especially since you don't understand the information you are seeing in front of you. i recommend that you post the code producing your form, since you likely have a problem in the code that's providing the value that's being submitted.
×
×
  • 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.