Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,367
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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
  7. 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?
  8. 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.
  9. 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.
  10. 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.
  11. 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 } ?>
  12. 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 ....
  13. 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.
  14. 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.
  15. 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.
  16. what tool/software are you using to assign privileges to the database? you may need to explicitly flush the privileges to get them to take effect. another possibility is if you have a typo or some white-space as part of the value(s) in the php code.
  17. are you sure of the database server hostname for the new domain? it may in fact be different from any previous domain. are you sure of the database username and database name? a lot of web hosting requires the hosting account name as part of the database username. after you created the database username/password, did you assign that database username privileges to the database you are trying to use?
  18. and since these key values likely came from user supplied data, you should use a prepared query to supply the data values at the time the query gets executed in order to avoid sql injection. this would involve dynamically building the IN (....) term with the correct number of place holders and dynamically binding the input data. doing this with mysqli is a pita. using the PDO extension, instead of mysqli, is all around easier and more consistent.
  19. what debugging have you done to narrow down the problem? have you dumped (see: var_dump()) the role value so that you know what if anything it is? are you sure that login success code is even running for the users with those roles? if all your code is doing is mapping a set of values to other values, you shouldn't write out conditional logic (if/elseif/switch/case) for each possible choice. this will require that you edit the program logic just to add, remove, or change any of the possible choices. it also makes for cluttered code, which i just noticed is the cause of your problem. you have a missing {, which has made all your conditional logic off a bit. properly indenting your code, based on where matching { and } are at would help you make sure all the { and } are where you intend. you should instead write general purpose, data driven code, that defines data (arrays) that tells simple code what to do. see the following example - // define categories of roles (in a configuration file) $management = array('Admin', 'Manager', 'Front_Desk'); $staff = array('Writer'); // at the point of decided what to do for the category a role belongs to if(in_array($role,$management)){ header("location: reservation.php"); exit; } elseif (in_array($role,$staff)){ header("location: articles.php"); exit; } else { // none of the defined roles, handle that condition here... } next, logging someone in, involves identifying who they are, not what permissions/roles they have, which is a different concern/different process. all your login code should do, when the username/password has been confirmed, is to store the user_id in a session variable. after your post method form processing code successfully runs (with no errors), it should do a header() redirect to the exact same url that the form submitted to. this will cause a get request for the page, which stops the browser from trying to resubmit the form data. when each page gets requested, it should take the user_id from the session variable and query for the current user permissions/role. this will insure that any change made to a user's permissions/roles take affect on the very next page request. any page should take the user permissions/role and use them to determine what will be processed on the page and what will be displayed.
  20. the examples in the documentation, SELECTing the value returned by the FIELD() statement are only to demonstrate what value is returned for each example. imagine calculating that value for each row of data in the result set and ordering the data by that value - ORDER BY FIELD(cstype,'main character in', 'secondary cast in', 'appears in', 'cameo appearance in')
  21. you can either use FIELD() or FIND_IN_SET() in an ORDER BY term in the query to do this.
  22. the OP's symptom is most probably due to php not being able to send the session cookie to the browser. the session data file is still created in this instance. does the OP have php's error_reporting set to E_ALL and display_errors set to ON in the php.ini on his development system so that php would report and display all the errors it detects, particularly a couple of warnings at the session_start() statement?
  23. you will need to attach a partial sql dump of your database table as a file to a reply. this will show us the table definition, in case the definition of that column has something to do with the problem, and it will provide us with the actual data value you expect the query to match. also, how do you know the query doesn't match the data? the method/code you are using to detect if there is a result set may be at fault.
  24. if you read the whole error message, it's also telling you where the output is occurring at that is preventing the header() from working.
  25. $filenames = array("index.html", "areas.html", "test.html", "example.xls"); $folder = $this->skeleton_dir; $files = glob("$folder{".implode(',',$filenames)."}",GLOB_BRACE); return (count($filenames) == count($files));
×
×
  • 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.