Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. Per the manual rmdir() Have you turned on error reporting?
  2. Your question is vague. What do you mane show "all the difference between two dates in a column"? Give an example of a small set of data and what the expected output would be.
  3. Barand, I was just testing that script and there is a bug. When you change a value in one of the select lists it does not repopulate the value that is unselected into the other lists. So, if you select value "2" in the first select list, the "2" is removed from the other lists. But, if you then change the "2" to a "3", the "3" is removed from the other lists, but the 2 is not put back. I think the solution is that we would have to store all the possible options in an array and then compare against that any time changes are made. EDIT: Also, changing a value back to "--" removes that from any lists where it isn't selected.
  4. I am not a UI expert, but I did stay at a holiday Inn last night do work with some who are. So, I can say with certainty that the right UI is directly related on the context of the data being presented to the user and understanding "how" the user would use the data. Your example has been genericized so it is unclear what the data is or how it would be used. So, any suggestions provided would need to be evaluated on the actual need. I think the idea of making the fields not editable until the user double-clicks (or used some other control for enabling them) is a good idea. The display of the tabular data definitely needs an update. I don't know how many rows of data you would normally display, but alternating grid rows might be a good idea. As for "adding" records; instead of having the input fields always be displayed, you could just have an "Add" button and then provide a dialog when clicked. The benefit of this is if you want to have a view where the user can just see "the data". But, if the users will more often than not be adding data, then having a separate dialog might add more work to the user (again it's all about context). I assume the values of the fields to the right are dependent upon the editable fields on the left. If so, you would want to implement AJAX to auto update the rows when changes are made. This *could* be a problem if you want to update the row/record whenever an individual field is changed if that process has any delays. Here are a few pages that may provide some ideas: http://www.editablegrid.net/en http://demos.telerik.com/kendo-ui/grid/editing-inline http://mindmup.github.io/editable-table/
  5. 1. As I was saying, if there are lines in your import file that do not have data or are not in the format you expect, then trim() will do nothing to resolve that. Your code, right now, inserts a new record in the DB for every line in the import file regardless of what is contained on that line. 2. You state you are getting "special character" where the white space is. If you "see" a special character, it is not a white-space character. As I stated you need to add validation logic to your code to ensure the data is what you expect. For example, I would expect that you would want to ensure there are at least 9 values on each line. But, maybe you want to reject the line if there are more than nine as well. Second, what "types" of values do you expect for each field? Do some need to be numeric values (int or float), do some need to be dates, or what? You would want to validate each field based on what field type it needs to be. Lastly, are any fields "required"? If so, then you should reject records where any required fields are empty. Or perhaps you want to insert NULL when there is an empty field. Now that I think of it, trying to insert data that is not appropriate for the field type could cause some odd characters in the DB. I'm not sure as I always check my data before inserting. Basically, the code you have is woefully inadequate. But, since I don't know the context of the data you are inserting I don't know what logic you need. Plus, without an example file I can't be sure of what the problem really is. But, what I would probably do is create a function that I pass each line to. The function will process the line of data and ensure it is valid for insertion into the DB. If it is valid, it returns the data back to the process to do the insertion. Otherwise it returns false. There are several other problems with your code that I'm not going to address, but here is a quick example of a possible solution. The function would be modified based upon all the necessary business rules. Here is a rough example. This is not tested, so there may be some minor syntax or other issues to resolve. <?php session_start(); if (!array_key_exists("user", $_SESSION)) { header('Location: index.php'); exit; } $sDbHost = 'localhost'; $sDbName = 'examcenter'; $sDbUser = 'examcenter'; $sDbPwd = 'examcenter'; $dbConn = new mysqli ($sDbHost, $sDbUser, $sDbPwd,$sDbName); if ($dbConn->connect_error) { die('Connect Error (' .$dbConn->connect_errno . ') ' . $dbConn->connect_error); } function validRecord($data) { //Check if line has 9 values if(count($data) != 9) { return false; } ##Verify each piece of data based on the field type ##These are just examples, you need to do it based on your actual needs //Verify date and time $timestamp = strtotime($data[0] . ' ' . $data[1]); if(!$timestamp) { return false; } else { $date = date('Y-m-d', $timestamp); $time = date('h:i:s', $timestamp); }; //Verify subcode is not empty $subcode = trim($data[2]); if(empty($subcode)) { return false; } //Verify subname is not empty $subname = trim($data[3]); if(empty($subname)) { return false; } //Verify seatno is integer $seatno = intval($data[4]); if(!$seatno) { return false; } //Verify center is not empty $center = trim($data[5]); if(empty($center)) { return false; } //Verify center is not empty $coucode = trim($data[6]); if(empty($coucode)) { return false; } //Verify center is not empty $yearcode = trim($data[7]); if(empty($yearcode)) { return false; } //Verify center is not empty $mastercode = trim($data[8]); if(empty($mastercode)) { return false; } //All data is valid return result return array( 'date' => $date, 'time' => $time, 'subcode' => $subcode, 'subname' => $subname, 'seatno' => $seatno, 'center' => $center, 'coucode' => $coucode, 'yearcode' => $yearcode, 'mastercode' => $mastercode, '' => $date, ) } if(isset($_POST["Import"])) { include 'config.php'; $filename = $_FILES["file"]["tmp_name"]; $ext = substr($filename, strrpos($filename,"."), (strlen($filename)-strrpos($filename,"."))); if(!$_FILES["file"]["size"] > 0) { $file = fopen($filename, "r"); while (($row = fgetcsv($file, 100000000, ",")) !== FALSE) { $emapData = validRecord($row); if(!$emapData) { //Line is invalid, add error condition if you with } else { //Data is valid - insert it //This should be updated to use a prepared statement $sql = "INSERT into report (date, time, subcode, subname, seatno, center, coucode, yearcode, mastercode) VALUES ('{$emapData['date']}', '{$emapData['time']}', '{$emapData['subcode']}', '{$emapData['subname']}', {$emapData['seatno'], '{$emapData['center']}', '{$emapData['coucode']}', '{$emapData['yearcode']}', '{$emapData['mastercode']}')"; mysqli_query($dbConn, $sql); } } fclose($file); echo "<script>alert('CSV File has been successfully Imported')</script>"; } else { echo "Invalid File:Please Upload CSV File"; } } if(isset($_POST["Delete"])) { include 'config.php'; mysqli_query($dbConn,"DELETE FROM exseatchart") or trigger_error(mysqli_error($dbConn),E_USER_ERROR); mysqli_query($dbConn,"UPDATE block SET status= 0 ") or trigger_error(mysqli_error($dbConn),E_USER_ERROR); mysqli_query($dbConn,"UPDATE supportstaff SET status=0, blockname='0' ") or trigger_error(mysqli_error($dbConn),E_USER_ERROR); echo "<script>alert('Record Deleted Successfully')</script>"; } ?> FYI: You should consider creating a single field int he DB to hold the Date & Time rather than two separate fields.
  6. I only see the PHP script. Where's the CSV file? Also, please explain what is it about the results of the execution that are not what you want to occur. In other words, where are you seeing that there are white-space characters not getting trimmed? EDIT: If your only problem is that there are blank lines, then that is not a problem with trim(). That means you have lines in the import file that do not have data. Or at least not in the format you expect. With any process where you are receiving data from a user, you should never ASSUME the data will be valid and in the format you expect. You need to add validation logic to verify. And, FYI: your script is wide open to SQL Injection
  7. First off, you should stop using the mysql_ extension - it is deprecated. Use mysqli_ or, better yet, PDO. Then, when you do convert, use Prepared Statements for anything that will include variable data that could be a security risk (such as $_GET values). This is the best way to ensure user data will not create SQL Injection problems. Now, as to the best ways of searching, that is not an easy answer as it all depends on the context of what the user is searching for. Sometimes, you have to make an educated guess on the best business rules and try it out for a while and get some feedback. You can also add some logging of searches done to see any patters. Are users performing multiple searches before selecting a record? What did they search for and what did they ultimately select? How could you change the search logic so that what they ultimately selected would have been in the results of the first search? EDIT: If you are not going to use Full Text searching then you should at least explode the search words and create a multi-conditional where clause. What you have now requires the user to enter the search words in the exact order that they would appear in the fields being searched. E.g.: SELECT whatever FROM `video_table` WHERE (col1 LIKE '%.$word1.%' AND col1 LIKE '%.$word2.%' AND col1 LIKE '%.$word3.%') OR (col2 LIKE '%.$word1.%' AND col2 LIKE '%.$word2.%' AND col2 LIKE '%.$word3.%') But, yeah, you really need to use Full Text
  8. How much is the assignment worth to you? :)
  9. Well, it's not impossible. I don't know how your DB is currently constructed (and don't really want to). But, here is how I would tackle this problem. I would have one table for the questions which includes at least a questionID and the question text. I would then have an answers table. Each answer would have at least four fields: answerID, questionID (FK), question text and a Boolean field for whether the answer was correct or not. Then when it comes time to display a question, I would select all the available answers. If only ONE of the answers is a "correct" answer, then I would display the answers with a radio group. However, if there are more than one rights answer then I would use checkboxes. Additionally, I would get the count of right answers and implement JavaScript on the checkbox group to limit the max selected to that number. On second thought, you coulod just always use checkboxes and use JS to limit the selection to one as well when needed. As for what you do when processing the results, it all depends on whether you are giving partial credit for getting some of the multiple answer questions right or if they only get credit if they get them all right. Also, I think your current method for the answer values is flawed Question 1: "Blah blah blah" Answer 1: Has input type=checkbox, name=1 value=answer[1][1] Answer 2: Has input type=checkbox, name=1 value=answer[1][2] Answer 3: Has input type=checkbox, name=1 value=answer[1][3] Question 2: "Blah blah blah" Answer 1: Has input type=checkbox, name=2 value=answer[2][1] Answer 2: Has input type=checkbox, name=2 value=answer[2][2] Answer 3: Has input type=checkbox, name=2 value=answer[2][3] The NAME of the answer fields should identify the Question ID (and it should be an array so all answers results are in a single array. And the values should be the answer ID, not an arbitrary 1, 2, 3. Lastly, for those questions that will have multiple answers, the answer field name would be a sub array. Question 1: "Blah blah blah" Answer 1: Has input type=checkbox, name=question[1][] value=2 Answer 2: Has input type=checkbox, name=question[1][] value=4 Answer 3: Has input type=checkbox, name=question[1][] value=9 Question 2: "Blah blah blah" Answer 1: Has input type=checkbox, name=question[2][] value=13 Answer 2: Has input type=checkbox, name=question[2][] value=6 Answer 3: Has input type=checkbox, name=question[2][] value=7 Question 3: "Pick two answers" Answer 1: Has input type=checkbox, name=question[3][] value=22 Answer 2: Has input type=checkbox, name=question[3][] value=16 Answer 3: Has input type=checkbox, name=question[3][] value=5
  10. I think that's a bad idea. You can make it complicated where the user has to choose multiple answers, but I think a better option is to create your answers in this format: What are the two (2) main sources of non-introduced atmospheric hazards in a wind turbine hub? 1. Nitrogen & Hydrogen 2. Nitrogen & Helium 3. Hydrogen & H2S 4. Helium & Hydrogen That way each question has one and only one answer. If you make it so there are multiple options to select for a question, the database configuration and the logic will be more complicated.
  11. mannygo, I know you are just learning and that it seems like more work to create yet another table, but it really is the solution. Unfortunately, may, many people fall for the same "quick fix" idea that you are wanting. It may seem like it makes sense, but you are painting yourself into a corner. You will be back here days or weeks later wanting to do something that is very difficult or impossible with the solution you came up with. With very, very rare instances, you should never store a list of values in a single field in the database. Although, one correction to Barand's provided structure. The group_id in the attendance table should be an INT.
  12. It says array first because of two possible reasons that I can think of: 1. There is an echo/print somewhere before this code that is outputting that content OR 2. The first element of $_POST[$i] is a sub-array. You should almost never have logic that runs through an array and *assumes* the array contains specific vales and in a specific order. You should explicitly echo the indexes you want from that array. But, first thing is first. Let's check exactly what is contained in that array. Use this: var_dump($_POST);
  13. Did you write the code or did you just copy/paste it from somewhere and are looking to change it? I'm not understanding how you would not see why some fields are not included in the email. For example, you have this as part of the email content creation process $email_message .= "Address: ".clean_string($address)."\n"; But, nowhere in the preceding code did you define $address.
  14. Yeah, I started to combine the queries and saw that you could probably combine most of them to also include the conditional calculations you are making, such as for $ActvUpgrade. But, since you have absolutely no comments to even help someone understand what you are doing I decided it wasn't worth my time. The better the information you provide the more likely we are to invest our time to help.
  15. Is the "\r\n" needed in that context? Wouldn't the individual "\r" and "\n" cover that?
  16. While I agree that CSS is the appropriate solution, the statement above is not 100% accurate. You can use non-breaking consecutive spaces and they will all be rendered by the browser. As opposed to normal consecutive spaces that are rendered as a single space.
  17. ??? Did you see my last post? Take a look at what I did. I echo the values that are used in all the if/ifelse conditions. Then, I added a final else condition with an echo statement. Now, you should be able to see what is printed to the page and understand exactly what the values are and confirm that the right conditions are being executed.
  18. The answer is "it depends". How often would this data change and how "fresh" does it need to be? If the data can change often and/or the data needs to be up to date at the time you use it (not just the value when the user logged in) then you might need to pull from the DB on page load. Also, do you need the data on all pages or only some? If only some, how often are those pages accessed? If it is only used on a small percentage of page requests, then pulling from the DB when needed may make sense. Lastly, if the data is sensitive in nature, then I think it is best to leave it in the DB (encrypted) except when you need it. Yes, session data is stored on the server, but I don't believe it is encrypted. As to your second question, the answer is "It depends". You can still use friendly URLs along with MOD Rewrite which would convert URL path info into $_GET variables. The URL might look like this: "domain.com/somepage/something/thisdata" which would get re-written by the server to "domain.com/somepage.php?somedata=something&otherdata=thisdata". So, you would still create the page to use values in the $_GET array. Take a look at the URL for this page for an example. But, it all depends on whether there is value in doing that. If you need pages to be indexed by search engines, then you definitely want to use MOD Rewrite. Otherwise I think it is more of an aesthetic issue.
  19. Try this with some add'l debugging $query = "SELECT COUNT(1) FROM townSponsor_OBC_tools WHERE ts_obc_username = '$ts_obc_username' AND ts_obc_userID = '$ts_obc_userID'"; $result = mysql_query($query) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_result($result, 0, 0); echo "Row Count: {$num_rows}<br>\n"; echo "Paid Source: {$ts_obc_paidSourcee}<br>\n"; if ( $ts_obc_paidSourcee == 'MTM1000' ) { echo "This Paid source is MTM1000 and Nothing is done"; } elseif ( $ts_obc_paidSourcee == '2411' ) { echo "This Paid source is 2411 and Nothing is done"; } elseif ( $num_rows == 1 AND $ts_obc_paidSourcee <> 'MTM1000' AND $ts_obc_paidSourcee <> '2411')) { echo "Row Count is = 1 and paid source isn not MTM1000 or 2411"; mysql_query("DELETE FROM townSponsor_OBC_tools WHERE ts_obc_m_orgIDSponsor = '$ts_obc_m_orgIDSponsor' AND ts_obc_username = '$ts_obc_username' AND ts_obc_userID = '$ts_obc_userID'"); mysql_query("DELETE FROM townSponsor_members WHERE tsm_m_username = '$ts_obc_username' AND tsm_m_userID = '$ts_obc_userID' AND tsm_assocID = '$ts_obc_m_orgIDSponsor'"); mysql_query("UPDATE users SET zabp_paid = 'NEW_S' WHERE username = '$ts_obc_username' AND id = '$ts_obc_userID'"); } elseif ( $num_rows >= 2 AND $ts_obc_paidSourcee <> 'MTM1000' AND $ts_obc_paidSourcee <> '2411') { echo "Row Count is >= 2 and paid source isn not MTM1000 or 2411"; mysql_query("DELETE FROM townSponsor_OBC_toolsTest WHERE ts_obc_m_orgIDSponsor = '$ts_obc_m_orgIDSponsor' AND ts_obc_username = '$ts_obc_username' AND ts_obc_userID = '$ts_obc_userID'"); mysql_query("DELETE FROM townSponsor_members WHERE tsm_m_username = '$ts_obc_username' AND tsm_m_userID = '$ts_obc_userID' AND tsm_assocID = '$ts_obc_m_orgIDSponsor'"); } else { echo "Did not match any condition"; }
  20. Code does not just arbitrarily skip a condition. It is doing exactly what you have programmed it to do based upon the results. So, something is not as you think it is. Either the results are not what you think they are or the results are matching a condition you didn't think they would. Just add some better debugging logic to see ALL the applicable values and also put statements within the if/else code blocks But, I do see one thing that doesn't make sense in your first query SELECT COUNT(1) FROM townSponsor_OBC_tools WHERE ts_obc_username = '$ts_obc_username' AND ts_obc_userID = '$ts_obc_userID' Why do you have the two conditions in the WHERE clause? Typically both the User ID and the Username would be unique. So, only one would be needed. Also, for the last two ifelse conditions, the conditions don't match what you apparently are trying to test for. That is why Barand stated to use AND. Here is one example: elseif ( $num_rows == 1 || $ts_obc_paidSourcee <> 'MTM1000' || $ts_obc_paidSourcee <> '2411') { echo "Row Count is = 1 and paid source isn not MTM1000 or 2411"; The echo statement states that this block of code would be run because the row count is equal to 1 AND the paid source is not a specific value. But, that is NOT what the condition is checking. The condition is checking if the row count is 1 OR the paid source is one of two other values. Based upon the echo the condition should be elseif ( $num_rows == 1 AND $ts_obc_paidSourcee <> 'MTM1000' AND $ts_obc_paidSourcee <> '2411')) Also, the last condition (based on the echo statement, should be elseif ( $num_rows >= 2 AND $ts_obc_paidSourcee <> 'MTM1000' AND $ts_obc_paidSourcee <> '2411')
  21. Of course, JavaScript has no knowledge of what content was generated dynamically and what wasn't.
  22. Open the file for editing and use the "w" mode to truncate the file. Then close the file. Not sure, but you *may* have to write something to the file first. If so, just write an empty string. Do this AFTER you have read the contents and put into the DB. $myFile = "path/to/logfile.log"; $fh = fopen($myFile, 'w'); fwrite($fh, ''); //May not be needed fclose($fh);
  23. If you are reading the log file and copying the content to the database, then why not clear out the log file when you do that?
  24. A couple things come to mind: 1. Write the data to a database instead of (or in addition to) the log file. Getting dynamic entries would be much easier. 2. Create a new log file each week/month and archive older ones on a regular basis. Having log files n GB will become a problem even if you aren't wanting to dynamically read specific entries. Then you can just pull content from the current log file and possibly one back.
  25. I'm not following your question. If you want a record specific to a certain user, then you would need to include that in your WHERE clause.
×
×
  • 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.