Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. 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.
  2. 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.
  3. 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.
  4. 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?
  5. 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.
  6. 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.
  7. 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?
  8. 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.
  9. 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?
  10. 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).
  11. 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.
  12. 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.
  13. 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.
  14. your php code contains a number of syntax/parse errors, some incorrect array references, and wrong usage of mysqli_query statement. 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 to get php to report and display all the errors it detects. due to the syntax/parse errors in your main file, these two settings cannot be set in your main code because your main code never runs for this type of error. the string concatenation you are doing inside the while(){} loop is where most of the problems are. you are missing some concatenation dots OR you should just put everything inside of a php double-quoted string and forget about concatenation. you also need to specify the array name inside that same code. all the array references need to have $row as part of them. the php errors, after you turn them on, should help you find the remaining problems in the code.
  15. if you are going to take the time to learn a new php database extension, use that time learning the PDO extension. it's more constant, simpler, and cleaner than the mysqli extension, particularly when using prepared queries.
  16. phpmailer should (according to the documentation) work for any php 5+ version (5.4+ if you are using oauth.) however, assuming you are using the latest version of php mailer, that particular section of code IS using php syntax that was introduced in php 5.3 and will throw a parse/syntax error for lower versions. the php version check logic they put in that particular code doesn't have any affect because the code never runs when there is a syntax error. you can edit the section of code for the clearQueuedAddresses method so that it only contains the first set of conditional logic. you could also put the section of code that's in the else{} conditional statement, that's using the php5.3+ syntax, into an external file and require it in place of the in-line code. the require statement will only be executed if the else{} condition is true and this won't throw a parse/syntax error since the code in the required file is only evaluated when the require statement is executed. you can also (at your own risk) download and use older versions of php mailer - https://github.com/PHPMailer/PHPMailer/releases
  17. probably not. there's two problems with this. 1) no one is likely to want to go through 40 or 6 * 40, depending on what your statement about what you are doing means, different select/option menus (there's probably a better interface to do this), and 2) this shows that your database table has designed badly. so, what does this data actually represent and how many select/option menus are there in each form and how many forms are there?
  18. the reason for this is because the html markup is broken. the value = '...' attribute needs quotes (either single or double quotes are valid) around the value. since this is inside of a double-quoted php string, use single-quotes in the markup.
  19. the reason you are having a hard time writing code, or are writing a ton of code that only differs in a name or value, to deal with your data is because your database design is bad. any time you find yourself with database table columns, variable names, or associative array names that have numerical endings, it's a sign that you are doing something wrong while programming. the point of databases is, each item (one, singular) of data is stored in its own row. you can then write simple queries and have simple code to retrieve any portion of the data you want. you also only store data that exists and wouldn't have 'slots' for each possible value. your data apparently corresponds to dates. you would instead have columns for the date (a mysql DATE YYYY-MM-DD data type) of the data, the value of the data, and perhaps an auto-increment id to uniquely identify and reference each data item. you would write a query that retrieves the data you want, in the order that you want it. you would then just display the data the way you want when you loop over the row(s) that the query returned.
  20. since you have a try/catch block around your code, that implies you have set the pdo error mode to exceptions. if this is true, why do you even have a conditional statement testing $stmt->execute() ? if the execute() method call fails, your code isn't going to be running any of that logic. it will be running the code in the catch{ } block.
  21. in php, empty is not the same thing that isset() tests. i suspect you mean a non-empty string? see the following example code - $flag_path = "http://aussietaste.recipes/wp-content/uploads/flags/"; // note: currency SYM and SYM$ map to just SYM due to trimming of any trailing $ by the code // define an array that maps input values to output values $map['USD'] = array('flag'=>'Flag_of_the_United_States.jpg','symbol'=>'$USD'); $map['GBP'] = array('flag'=>'Flag_of_the_United_Kingdom.jpg"','symbol'=>'£'); $map['£'] = array('flag'=>'Flag_of_the_United_Kingdom.jpg"','symbol'=>'£'); $map['AUD'] = array('flag'=>'Flag_of_Australia.jpg','symbol'=>'$AUD'); // add other mappings here... $currency = $product->currency != '' ? rtrim($product->currency,'$') : 'AUD'; // use value (less any trailing $) or default to 'AUD' if(!isset($map[$currency])) { // no mapping exists echo "The currency value {$product->currency} isn't defined."; } else { // the currency is defined, use it $arr = $map[$currency]; $cur = "<img src='$flag_path{$arr['flag']}' alt='' /> {$arr['symbol']} "; ?> <div class='prc'> <small> <?php if($product->saleprice > 0 && $product->saleprice < $product->price){ echo 'On Sale: <span style="font-weight: bold; color:red;">'; echo $cur; echo " [product.saleprice]</span>"; } else { echo $cur; echo " [product.price]"; } ?> </small> </div> <?php } ?>
  22. two things when programming - 1) Don't Repeat Yourself (DRY). you have two blocks of code that only differs in the On Sale: <span ...></span> text/markup. you should only write out program logic when you have different things you need to do. the common block of code, containing all the mapping of currency to flag image and display symbol, should not be repeated. 2) when all you are doing is mapping one value to other values, doesn't write out program logic (if/else/switch/case.) use a simple lookup array to do the mapping. by simplifying the code, it will be easy to see where and how you should ad the logic to default to the AUD value. i'll post some code showing how simply this can be done ....
  23. the only thing your form should submit is the radio button data. it should tell you which database table row the data corresponds to, as the name='Value[...]' key, and which radio button was selected, as the submitted value='1-5'. the only thing the UPDATE query should be SET'ing is the Value field, based on which row is being updated and which radio button was selected. the rest of your hidden form fields don't make any sense, mostly because they don't relate the submitted data to the row it corresponds to. if you define the table holding the user's choices as i suggested, the user_id/QuestionID pair identifies which row to UPDATE and your existing radio button form field is correct. if you instead have an auto increment column defined for that table, which i'm guessing is what the AnswerID is, you would use it as the name= 'Value[...]' key, instead of the QuestionID. in either case, the keys of the $_POST['Value'] field will tell you which row the submitted radio button data corresponds to. your loop would look like - foreach($_POST['Value'] as $key=>$value) { // $key will tell you which row to update, $value will be the selected radio button value 1-5 } the UserID value you use in the database query should be coming from your user-system php code. it shouldn't be coming from the form since that would allow a user to alter someone else's data.
  24. i would start by storing/defining the QuestionID and Questions (text) in one table and the user's choices in a different table. you would store the user_id, QuestionID, and the choice value (1-5) in the second table. the user_id/QuestionID (together) would be defined as a unique composite index to enforce uniqueness. this will also let you use an INSERT ... ON DUPLICATE KEY UPDATE query to either insert new data or update existing data.
  25. the following implements your logic, saving the output from each input .htm file to a corresponding .csv file - <?php ini_set('display_errors',1); error_reporting(E_ALL); $stats_wanted = array('playedPositionsShort', 'name', 'playerId', 'age', 'rating', 'shotOnTarget', 'shotsTotal', 'penaltyScored', 'penaltyMissed', 'passLongBallAccurate', 'passLongBallTotal', 'passTotal', 'passCrossAccurate', 'passCrossTotal', 'passThroughBallTotal', 'passThroughBallAccurate', 'keyPassTotal', 'dribbleWon', 'dribbleTotal', 'tackleWon', 'tackleLost', 'tackleWonTotal', 'tackleTotalAttempted', 'challengeLost', 'interceptionLost', 'penaltyTaken', 'interceptionAll', 'clearanceTotal', 'offsideGiven', 'offsideProvoked', 'foulGiven', 'foulCommitted', 'dispossessed', 'duelAerialWon', 'duelAerialLost', 'duelAerialTotal', 'touches', 'totalPasses', 'offsideWonPerGame', 'offsideGivenPerGame', 'passSuccessInMatch' ); $keys = array_flip($stats_wanted); // change stats wanted into keys $source_path = 'directory/'; $dest_path = ''; // enter the path, with trailing /, where you want the destination files to be written foreach (glob("$source_path*.*") as $filename) { echo "Processing: $filename<br>"; $info = pathinfo($filename); // get the ['filename'] $content = json_decode(file_get_contents($filename),true); // read file contents as an array $output = fopen("$dest_path{$info['filename']}.csv",'w'); // create output file fputcsv($output, $stats_wanted); // write header line to file // loop over players in the data foreach($content['playerTableStats'] as $arr){ $arr = array_intersect_key($arr,$keys); // keep only the stats wanted elements fputcsv($output, $arr); // write the data to the file } fclose($output); // close the current file } this makes the same assumption that your code does, that the order of the $stats_wanted elements matches the order that the data elements will exist as. if not, you can throw in a sort operation before writing the data to the 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.