Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,448
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. as a continuation of the above reply, you can calculate the date difference in the query, so it's both possible for the query to return the date difference value to use in your php code AND you can have the query return only the rows that match your date range of interest so that you don't need to retrieve every row from your table and loop through them all to find the ones you want. likewise, you can select and format the deadline date in the query the way you want to display it.
  2. the error is calling your attention to the point in the query statement that mysql could not understand. you are using { } instead of ( )
  3. your statement of what the problem is, makes no sense - you only have one $remail variable in the posted code and it is being set based on what is in the row retrieved from the `job` table. what exactly do you mean by that statement? what result are you getting and what result do you expect? have you verified the data stored in the `job` table is what you expect? you also have too much code. about three times too much of it. you should only write code for things that differ. the code that is the same for all three of your conditions should only appear once. your conditions for two days before and one data before can be combined into ONE statement using an || (or) condition. your query to get a user's email address (while it should be gotten by having your existing query for the `job` table JOIN'ed with the user table) should only match one row and there's no need to loop over the result from that `users` table query or to loop later sending emails to what should be one to: address.
  4. a) why do you have two nested foreach(){} loops? if $data contains the arrays of values, the first foreach(){} loop gives you each of those arrays in $value. you still have too much code that isn't doing anything towards your goal. b) one reason the help given so far is just general things, is because, without knowing/having an example of what is in your .txt files, no one here can offer more specific help. posting an example of what your input is, so that someone can see what result your code should be producing, would get more specific help. c) i still don't think your $process flag is doing what you expect, but since we don't know what the purpose of it is, cannot really help you. adding some comments to your code would be helpful. if it is to indicate that there is at least one new file that needs to be scanned and added to the database, why not just let the number of entries in the $data array tell you that? if the file needs to be scanned, add it to the $data array. if it doesn't need to be scanned, don't add it to the $data array? d) cannot really help you with the current errors without the current code that corresponds to those errors. you are either un-setting elements in the $data array, accessing past the end of the $data array, overwriting $value with something that isn't an array, or perhaps storing an entry in $data that isn't an array. [rant] i've been meaning to write this. i've been mentioning that people have too much code in a number of threads. programming is a little like Goldilocks and the three Bears. you must have just the right amount of code. if you have too much code, you have wasted your time writing, testing, and debugging code that doesn't have anything to do with your goal. if you have too little code, you have left out things like validation and error checking and your code will vomit or die at the least little thing that isn't prefect. [/rant]
  5. the issue is that if there are no rows for any type, there's nothing to group by. you need to use the list of types to define the output, then if there's none for any type, take an appropriate action. try this - <?php // Define how to display/report errors ini_set("display_errors", "1"); error_reporting(-1); // Connection Info $con=mysqli_connect("localhost","*****","*****","*****"); // Check connection if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); // Querys $typeCount = mysqli_query($con, " SELECT actcaseld, type, encdate, COUNT(type) AS thecount FROM `Stats` WHERE type IN ('Type 1', 'Type 2 diet', 'Type 2 ADA', 'Type 2 ADA and Insulin', 'Type 2 Insulin', 'Pre-Diabetes', 'Other') AND actcaseld='New Client' AND encdate BETWEEN (SELECT bdate FROM `ReportRange` WHERE cf_id=1) AND (SELECT edate FROM `ReportRange` WHERE cf_id=1) GROUP BY type"); // pre-processes the data, storing the count using the type as an index/key $data = array(); while($row = mysqli_fetch_assoc($typeCount)){ $data[row['type']] = $row['thecount']; } // array of type values and the corresponding html table legends (in case the legend differs from the stored value) $types = array('Type 1'=>'Type 1','Type 2 diet'=>'Type 2 Diet','Type 2 ADA'=>'Type 2 ADA', 'Type 2 ADA and Insulin'=>'Type 2 ADA + Insulin','Type 2 Insulin'=>'Type 2 Insulin', 'Pre-Diabetes'=>'Pre-Diabetes','Other'=>'Other'); // Output to html //Build Headers echo "<table border='1' align='center'> <tr> <th></th> <th></th>\n"; foreach($types as $legend){ // dynamically produce the headings using the array of values echo "<th>$legend</th>\n"; } echo "</tr>\n"; //Output Results echo "<tr>\n"; foreach($types as $type=>$not_used){ $count = isset($data[$type]) ? $data[$type] : 0; // get the count, default to zero if none echo "<td><center>$count</center></td>\n"; } echo "</tr></table>"; // Close Connection mysqli_close($con); ?> the reason for suggesting ONE query is to make your code and query(ies) more efficient. it only takes slightly longer to run the one single query that gets all 7 results at once than it takes to run ONE of your previous queries and the overall amount of code is less as well.
  6. the query that Zane posted should give you one row for each type, with the type and thecount, even if the count is a zero. what is your current code? edit: additionally, if those 5 types are all the types in the table, you don't need to include them in the WHERE clause, but if you want to display them in the order shown, you need to add an ORDER BY clause that forces that order - ORDER BY FIELD(type,'Type 1', 'Type 2 diet', 'Type 2 ADA', 'Type 2 ADA and Insulin', 'Type 2 Insulin')
  7. your file is saved as a UTF-8 encoded file with the Byte Order Mark (BOM) characters saved at the front of the file or you have some characters in the file before the <?php tag AND either output buffering is turned on on the live server so that the characters don't matter OR you are FTP'ing the file using ascii mode and the BOM characters are stripped off. make sure you have no characters in the file before the <?php tag and if you need to save the file as a UTF-8 encoded file, you need to save it without the BOM characters (this is a setting in your editor) or if you don't need it to be saved as a UTF-8 encoded file, save it as an ascii encoded file.
  8. here's another specific flaw in your logic - you have corresponding entries in the $tables and $ReportFile arrays. you need to use ONE loop to access the same entry in both arrays. you are currently looping over everything in the $ReportFile array for every entry in the $tables array. use something like - foreach ($tables as $key=>$companyTbl) { $report = $ReportFile[$key]; ... } or you could just build one overall data array, where all the needed values are stored as an array (you could for example store the $path, and $file values as entries in the array, which i suspect you need to do anyway.)
  9. what he means is, your form has two fields with the same name='user' attribute and the one for the $getcode value should have the name='code'
  10. you need to find and fix what is causing each error. your undefined ... error messages are because you are referencing a variable you haven't initialized. you need to initialize the $error variable/array (you are using it two separate ways in the code) or you must test if it is set before you try to reference the value in it. fix these errors so that you only see the real errors your code produces. the copy/unlink errors are because the file or path being referenced doesn't exist. you need to determine if it is the path that doesn't exist or if it is the filename that doesn't exist (and it may be that the filename contains new-line or other non-printing characters that is causing the error.) one specific problem that jumps out is your code is referencing the wrong variables at times. one example is the $file variable. $file is set in the first foreach(){} loop, but you are trying to use it later in the code. it would only have the last value from the first foreach(){} loop, not any current value. make sure each functional block of code is doing what you intend. are the inputs, processing, and output/result correct for that block of code. you also need to work on simplifying your code (the less code there is the easier it will be to see what your code is and what it is doing.) for example, your first loop is testing against four different values, but is repeating all the logic each time. just put those four values into an array and use in_array() to test if the result is one of those four values. also, your $process flag is probably not doing what you think. it is only reflecting the value from the last file that was looped over. btw - you cannot set magic_quotes_gpc in your code, so that ini_set() statement isn't doing anything and is just adding clutter.
  11. after you have finished processing the form data, redirect to the exact same URL of that page so that the browser won't continue to submit the post data when that URL is requested.
  12. best i can tell, your form doesn't have a field with the name="Event_Type" and you also have some extra dots . among the method and action attributes in the <form > tag.
  13. you would output the sort links above each column of data. the links would contain the column/field name to sort and the asc/desc sort order (opposite of what the current sort order is, default to asc if there is no current sort order.) something like ?sort=some_field_name,sort_order=asc you would also combine the submitted column/field name and the asc/desc sort order with the page= and ipp= attributes in the links. you would end up with combined links that look like ?page=x&ipp=10&sort=some_field_name,sort_order=asc
  14. the example i posted contained only the same level of detail as what you provide about what you are actually doing. you would actually use a name_id in that table, with a separate table that stores the actual names and their associated id's. if you want better/specific/detailed replies, you need to post actual/better/detailed information about what you are doing. something tells me that the 1,2,3,4,... values control some ordering of the output and your statement that you want to find the column for a specific value like 2 really means - you want to retrieve/find the values in the order given by the numbers. using the method i have suggested, this would be - SELECT value FROM your_table WHERE name='Eric' ORDER BY key you would then just loop over the rows the query return and output whatever your fruit names actually correspond to.
  15. you seem to be randomly changing your code, rather than actually troubleshooting what is causing the problem(s). you have posted code with different database table names, with and without hashing of the password value, with two different methods of forming the query string that produce an identical query string (except that you left out the hashing in one), with extra session_start() statements (which should have been producing errors), and with a few php syntax errors that are typo's on your part. you need to slow down and find and fix one problem at a time. if the 'live' server code you posted above in this thread actually logs you in, then that either means your code on your localhost development system wasn't actually doing what you think or you have also removed the hashing from your registration code or perhaps you are not posting your actual code in this thread. it's more likely that your session related problems are due to header errors, but you don't have php's error_reporting set to E_ALL and the errors are not being reported.
  16. not very likely. you are producing a value, passing that value through a session variable, and comparing that value with another value that was submitted from a form. make an attempt at performing those steps. the first two steps are already in your code and wherever you found the captcha.php image code probably contained examples of the rest of what is needed.
  17. the reason you are having a hard time doing this is because you are trying to use the database table like it is a spread-sheet and that is not efficient from a coding standpoint. you need to store each separate piece of data as one row in your database table. then you can find any or all of any type of data directly in the query. name | key | value Eric | 1 | apple Eric | 2 | banana Eric | 3 | grape Eric | 4 | orange SELECT value FROM your_table WHERE name='Eric' AND key=2
  18. unless your development system was identical to your live server, there's at least 5-10 different things that could cause a script to not work when moving between different server configurations or to a lesser extent, different versions of php/mysql. most likely your development system is setup with and you are using some of php's short-cuts that result in non-portable code. you need to troubleshoot what your code is doing so that you can find what is causing it. if you want us to help with that, you would need to post the relevant code needed to reproduce the problem.
  19. if your captcha.php image code was working and saved the $code value to the $_SESSION['code'] variable, all you need to do is check in your form processing logic if the submitted value the user entered in the form is not empty and that it is not exactly equal to the value in the $_SESSION['code'] variable, all the code you have leftover that is passing the "code_key" as a hidden field (which was insecure anyway) and testing that value with the submitted code from the user would go away, unless you are trying to confuse bot scripts by tricking them to submit that hidden field's value.
  20. i would use count_chars() with mode = 3 and test if the length of the original word is the same length as the string count_chars($word,3) returns.
  21. because you are using negative logic, you must complement the conditional test OR you could use true logic and complement that expression. either of the following should work (untested) - if ((($dow != 'Friday' && $dow != 'Saturday') && $hour == '23' && $minute == '45') || $showname == 'livingthecountrylife') if ((!($dow == 'Friday' || $dow == 'Saturday') && $hour == '23' && $minute == '45') || $showname == 'livingthecountrylife')
  22. if those are your actual database credentials, go change them now. you cannot ping the database server at it's hostname because only specific ip addresses, such as your web server's, should have permission to connect to the database server. because your connect statement has error checking logic, that means that the connection worked and the select_db statement is failing due to a permissions problem. did you add that database username to the database you are trying to select and give it any permissions? depending on the method you are using to configure your database, you may also need to flush the permissions after altering them to get them to take effect.
  23. if you understood the method of passing the id of each piece of data as a hidden field in the delete logic, what exact problem are you having applying that method to the update logic? just posting your update logic (repeatedly) and asking what to do for it, when you just went through the process of making your delete logic work, isn't going to get you much sympathy or help on a forum.
  24. lol, as Barand stated, where your $to variable is being defined at doesn't guarantee that it will exist when it is accessed when the form is produced. your code has two problems - 1) the first time it is requested, the form hasn't been submitted and none of the variables in your form processing code will exist at all. 2) after your form has been submitted, inside your conditional logic that has tested if the form has been submitted, all the text/textarea fields will be set and you don't need to test each one to see if it is set. just use the posted values (after you filter/validate them) inside your form processing code. your - $to = isset($_POST['to']) ? htmlspecialchars($_POST['to'], ENT_QUOTES) : ''; statement shouldn't be inside the form processing code at all, it needs to be somewhere right before the form. you could actually put it right where the value=' ... ' attribute is at (assuming you know how to concatenate an expression into a string.) you also should not apply htmlspecialchars or htmlentities to data being put into a database. it should only be applied to data right before you output it into a html page.
  25. if you temporarily change that line to the following it should tell you why the statement is failing - mysql_select_db("(this is the database name)",$db) or DIE(mysql_error());
×
×
  • 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.