Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,449
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. the actual mysql syntax of your query statement is correct. however, in the php context where it is at, it is throwing a php syntax error due to the use of the initial and final single-quotes around the php string and the single-quotes within the string. it's generally best to use initial and final double-quotes when building a query statement using php - $insert = "INSERT INTO users (name,lname,uname,email,pword) VALUES ('$name','$lname','$uname','$email','$pword')"; several points about the code you posted - 1) if you weren't getting a php parse/syntax error from that code, you need to set php's error_reporting to E_ALL and display_errors to ON in your php.ini on your development system so that php will help you by reporting and displaying all the errors it detects. stop and start your web server to get any changes to the php.ini to take effect. 2) the only part of that code that is inside the if (isset ($_POST['submit'])){ ... } form processing logic is the include_once() statement. you need to move the closing } to the end of the form processing logic so that the form processing logic will only be executed when the form has been submitted. the current code will attempt to form and run the insert query any time it gets requested, even when a form has not been submitted. 3) you need to validate all form data before using it, i.e. you should not even run the insert query unless you know the data you have put into it was an expected value/data type. 4) you should be hashing your passwords to protect your user's information, see this link - http://www.php.net/manual/en/book.password.php (if you are not using the latest version of php that contains the functions mentioned at that link, you can find equivalent user written functions here - https://github.com/ircmaxell/password_compat ). 5) you need to escape all string data being put into a query or use prepared query statements (prepared queries require using mysqli or PDO database functions) to prevent query errors and to prevent sql injection. 6) you need to ALWAYS test your mysql statements for errors. the connect(), select_db(), and query() statements can fail due to errors. your code should test for these (the statements return FALSE values) and you should both prevent the remainder of the code from producing follow-on errors and your code should let you know that an error occured and provide useful infomration about the error. during development, ALL the error information should be displayed to help you. when you put your code on a live server, verbose error information should be logged to help you and you should output some type of informational message to the user to alert them that the web site isn't going to function. 7) lastly, since you are just learning to use database statements. the mysql_ functions are depreciated and should not be used for any new code or any learning. see this link - http://www.php.net/manual/en/mysqlinfo.api.choosing.php
  2. the solution to simplifying the logic needed to manipulate the data will be to correct the design of your database table. database tables should be designed to store data using one row per related data set. just guessing but you likely need three columns (whatever the corresponding/related j, k, and z values are), with 20 rows (or whatever number of actual data sets there are.)
  3. what troubleshooting have you done to find the problem? this thread seems to be concerned with adding/modifying the contents of the cart and displaying the cart. unless you are offering a flat shipping fee, it would take knowing where you are shipping the items to before you can determine the shipping cost. most shopping carts have a 'check out' phase, where you finalize the order and gather (or let someone log in with an existing account, if not already logged in) information about where the order is being shipped to, then you finally let them goto the payment processor page to pay for the items in the order. the code you have shown in this thread for postage, in addition to what i have already stated about it, is nonsense. you set an initial postagerate (15.00), then you get and check the Post_Cost for each item in the cart. if the Post_Cost for an item is lower than the current postagerate, you use the lower value as the current postagerate. if the Post_Cost is equal to or greater than the current postagerate, you set the current postagerate to zero (you also set the postagerate to zero if there is no Post_Cost for an item.) your comments in the postage code are also contradictory. at one point you state - 'decide which postage value is the highest' and in the actual code - 'get the lowest postage rate.' before you can try to fix your postage code, you need to define the logic you want, because it's impossible to write code when you don't know what end result that code is supposed to produce.
  4. the code i posted contains a variable holding the sub-total, in the your original $price variable. your only task would be to display that value where you want it to be at.
  5. the logic (i think) you need would look like - $counter = 1; // for identifying each form $price = 0; // running sub-total $discount_table['SONY'] = 15/100; // add more entries to this table as needed, you would normally store this in a file and include it or use a database table while ($row = mysql_fetch_assoc($result)) { $qty = $row['quantity']; // quantity of this item $price_inc_vat = calcVAT($row['Price_ExVat']); // price including vat for this item // determine discount percentage, if any $i = $row["Prod_Make"]; $percentage = 0; // default (i.e. none) if(isset($discount_table[$i])){ $percentage = $discount_table[$i]; // get the defined percentage for this make } $discount = $price_inc_vat * $percentage; // calculate discount amount (zero if no discount for this make) $amount = $price_inc_vat - $discount; // net amount $total = $qty * $amount; // total for this item $price = $price + $total; // add to running sub-total // use the available values to output your form - // ... your form code ... $counter ++; } // end of the while loop
  6. i have a question about the values you are producing/displaying. which of - Price ex vat, Price inc vat, Discount on this item (-), or Total are unit amounts and which are multiplied by the quantity? also, i'm guessing the 1.2 value that showed up in the math has to do with the VAT? the only place you should have that value is in your calcVAT() fucntion. after looking at your code, you need to individually get/calculate the correct Price ex vat, Price inc vat, Discount on this item (-), and the Total as you are looping over the rows in the cart, storing each of those values in its own variable and only sum the correct one of those values with the running sub-total.
  7. sorry to jump in here, but your code is all over the place, difficult to follow, and contains several things that just shouldn't be done. some examples are running three select queries against your basket table to decide if you are going to insert a new item; using htmlspecialchars() all over the place, not just on values you are outputting into the html on the page; running the postage query inside of a loop (you should just get all the cart's 'Post_ID' values and run one query to get the lowest postage rate); hard-coding these discount comparisons and values into the code; the whole `shopper` table (you should not store calculated/derived data.) for your discount rate, assuming this is dynamic and could change for any product_make, it should be stored in a database table (or an array) that holds the non-zero discount and its corresponding product_make (there's no point in storing the zero discounts as that will be the default action of the code.) based on your 'full code' in post #18, you need to first calculate the cost (price * quantity) of the product and store that in a php variable, so that you can calculate the discount (if any) for that product, BEFORE you sum the item cost with the running total. your logic is currently summing the item cost into the running total without the discount, then figuring the discount using the running total.
  8. this is real basic stuff and means you skipped over the first few php chapters where it talks about variables, assigning values to them, and echoing them. // build the sql query in a php variable $query = "SELECT '".$dev_id."', ta.TERM_ID, '".$cust_id."', '".$dev_name."', '".$cust_fname."', '".$cust_lname."', DATE_OF_LOAN, DATE_RETURNED from device d join abc_audit au on d.DEV_ID = '".$dev_id."' join term_agreement ta on au.TERM_ID = ta.TERM_ID join customer cu on ta.CUST_ID = '".$cust_id."' where au.abc_status = 'O'"; // echo the sql query for debugging purposes echo $query; // run the query $result = mysqli_query($con,$query);
  9. most of the things you have selected in your query are literal string values. each item in the select list that are between single-quotes will be the literal strings those variables contain, not the values from the corresponding columns. i recommend that you form the sql query statement in a php variable, then echo out that variable so that you can see what it actually is and so that you can copy/paste it to run it directly against your database using your favorite database management tool (phpmyadmin or similar.)
  10. did you look at the OP's problem? he's getting an unknown column error because his $_POST['owner'] value has no quotes around it at all, producing a query - SELECT * FROM car WHERE owner = some_owner_name and the some_owner_name value is being interpreted as a column name.
  11. because, double-quotes can be enabled (a sql standard) to be used the same as back-ticks (a mysql specific abomination) and used around database, table, and column names, thereby breaking any query using double-quotes around string data and making it difficult to migrate to other database types -
  12. the value being put into the query is literal string data and needs to be surrounded by single-quotes so that it is treated as a string of characters, rather than a mysql keyword or a column name.
  13. the main reason i asked what your data is, that you expect to produce that output from, is because your posted query and code don't convey useful information. that query will only return one row, with the min of all dates, max of all dates, and the first encountered round number. you likely need a GROUP BY Round term in the query. your code is running that query once to get a count, then running that same exactly query again inside of a loop. your goal is to run one (or as few as possible) queries that gets the data you want in the order that you want it. there's no point in this. just run the query and loop over the row(s) it returns. your code that is iterating over the single row from that query is displaying three values, for the three things that query is selecting, min, max, and rounds. the output is "Rounds" followed by the first three characters of the minimum date found, "Rounds" followed by the first three characters of the maximum date found, then "Rounds" followed by the first three characters of the first encountered round number. i recommend you first study up on retrieving data from a query as this step in your code is nonsense. this is a case where rather than posting what you have tried (because it doesn't tell us anything useful), you need to post your data (enough of it to show anyone wanting to help what they would need to know to produce the specific output you expect from that data) and post the excepted output (which we already know.) if the data you are posting doesn't clearly correspond to the output you have shown from that data, don't bother posting it as it won't help anyone to help you.
  14. the code you posted is operating on data from your database table. the input data to that block of code is the data that is stored in your database table.
  15. without knowing what your input data is, it will be hard to help you based on your post above..
  16. your code is trying to include the mylibrary\login.php file multiple times. you would need to find out why and make sure you are only including it once. generally library files your code needs are included near the start of your main code file.
  17. okay, you already have a method/function - scrollPagination() that has parameters defined that tell each instance of it how it should behave. that this code has the url where it's going to make the ajax request to hard coded and buried in the javascript.js file isn't helping (the code is not general purpose now, making it harder than it should be to customize.) since the code in javascript.js is supposed to be defining a jquery plug-in, it should have been written completely configurable so that you don't have to touch the code in it at all and everything it does should be definable in the page where you use that code. for the purpose of making the 'ajax.php' url a call time parameter/variable, make the following changes to the original index.php and javascript.js files - in index.php, add the url : 'ajax.php', line (line #5 in the following) - <script> $(document).ready(function() { $('#content').scrollPagination({ url : 'ajax.php', // url to get data from, via .post method, to add a get parameter, just add it on the end of this nop : 10, // The number of posts per scroll to be loaded offset : 0, // Initial offset, begins at 0 in this case ... in javascript.js, add that same line in the var settings = { block (line #7 in the following) - (function($) { $.fn.scrollPagination = function(options) { var settings = { url : 'ajax.php', // url to get data from, via .post method, to add a get parameter, just add it on the end of this url nop : 10, // The number of posts per scroll to be loaded offset : 0, // Initial offset, begins at 0 in this case ... next, find the line in javascript.js that looks like this - $.post('ajax.php', { and change it to - $.post($settings.url, { the above makes the url (ajax.php in the example) a parameter that you can change or add anything to. for the usage in the code you posted immediately above this reply, for the index.php page, change the url : .... value to the following (this is the same line #5 in snippet of code from the original index.php that i had you change as the first step in this process, all you are doing now is making it into the url and any get parameters you want the code to use) - url : 'autoload.php?page=index', for the food page, use this for that line - url : 'autoload.php?page=food',
  18. if you are doing this on a web host, you will have the ability to put php settings into a local php.ini. you can also put the settings into your code (which won't show fatal parse errors, but will show all other errors in the code.) all the issues i mentioned concern variable scope, which are local to php functions.
  19. you need to set php's error_reporting to E_ALL and display_errors to ON, in your php.ini, to get php to report and display all the errors it detects so that php will help you. inside your function, the $pdo variable doesn't exist and would be throwing php errors to alert you to this problem. you need to define your function with $pdo as a parameter and pass the $pdo variable into your function when you call your function. next, are you even calling your SQL_Query(); function? lastly, the $output variable you are assigning values to inside your function only exists inside the function. you would need to use return $output; inside the function to return that value so that you can use it at the point where you call your function, i.e. the place where you call the function will essentially be replaced by the value the function returns.
  20. the term is called a semaphore - http://en.wikipedia.org/wiki/Semaphore_%28programming%29 you could probably implement this as a separate lock/semaphore database table, with the resource id of whatever you are trying to lock, a semaphore field, and a date/time field (when the lock was made so that you can timeout the operation if someone doesn't complete the edit to the data.) if the semaphore row doesn't exist or the date/time is more than a reasonable amount of time in the past, you would try to insert/update the row with the user id of the person requesting to make a change to the particular resource id. if the insert/update actually changed the semaphore to the requested user's id, you would know that user obtained the lock and could edit the data. if the value ended up being someone else's user id, they obtained the lock before you did. you could use the user id in this case to display a message - 'the resource is being edited by .... and will be locked until they finish or until ...the date/time field + some reasonable amount of time' when the person who obtained the lock saves the data, the row would be deleted from the lock/semaphore table.
  21. mac_gyver

    help

    besides the fact that you can have both post and get parameters at the same time, the logic in your code makes no sense. it will allow anyone who knows a valid user name to register a password for that user and anyone else who comes along can register additional password(s) for that user and add row(s) to the password table. this will either allow someone other than the actual user to register and impersonate that user or it could (if you don't have any restrictions in place) allow multiple rows in your password table for one username, resulting in a mess. what exactly are you trying to accomplish?
  22. the method (pun intended, read on) you used with the multiple .js files ignores the purpose of variables in programming. variables exist so that one piece of code can be used over and over and can operate on different values simply by changing the values in the input variable(s) the code uses when you call it. scrollPagination is already a method that has been added to the jquery library as a plug-in. it has a list of existing input parameters, the nop, offset, error... that tell it what to do when it runs (which btw are the defaults defined inside the code and don't need to be listed in the calling code unless you want to use different values than the defaults.) to make what you are adding to the code general purpose, just add a page : some value parameter in the calling code and then use that page variable inside ONE copy of the .js file.
  23. the code you posted, provided that lines 50-53 are actually commented out, WILL only include the 10 files that correspond to the requested page. if you are seeing more, then either your code isn't what you think or you are seeing a cached version of your page. btw - why do you have a ton of .php pages that you are trying to paginate this way? that indicates you have went to a lot of trouble and time creating and managing php pages instead of just storing the data that's present on these pages in a proper database.
  24. you cannot string multiple queries together and run them at one time. you must run each query separately - next, you should NOT be making a database table using a date as the table name. that is a bad design that will prevent you from easily using the data spread out across the many tables. you should have a date column in ONE table that identifies the date the data corresponds to.
  25. that might be where your images are stored, but you must specify which image you want to delete, which is why i asked what method have you used to associate the row in the product database table with the image that was stored in the $frontpage_url."/images/" folder? if you have no relationship that tells you which image belongs with which row in the product table, how do you expect to be able to delete the proper image file?
×
×
  • 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.