Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. Thanks Barand, Unfortunately, in trying to take out some of the other complexities in order to focus on the specific problem I was facing, I ended up removing an aspect that makes that approach invalid. In my actual data there are hundreds of thousands of data and it was difficult to validate results. So, I created a small test bed of data to test the query using just "Open" and "Closed". My intent was to change it to status IN (list of status ids) once I found a solution. In my actual data there are many different statuses that can represent "Open" or "Closed". A project can change from one Open status to another Open status - the same holds true for Closed statuses. Because of this, getting the 'difference' between "Open" and "Closed" statuses will not work. This will not be used often. At this point, I'm going to use the query I started with that gets me the value for a single point in time and run it in a loop to get the value for all the periods in the report range. As long as the time is somewhat reasonable it will get me to a viable solution for now. I may also consider caching, but the intent is that the report can be run with many different options.
  2. As someone who is responsible for hiring people, I will give you my honest feedback. As a professional, I know that I am not supposed to take into account any disabilities which can be addressed through reasonable accommodations. But, there are some issues with that: What is "reasonable". As the others have stated, much of our communication is via text - but not all of it. What about conference calls where employees talk through issues? Would it be reasonable to have everyone "talk" through text? There may be utilities to do speech-to-text, but on a conference call I suspect they may have problems (people taking over each other, background noise, etc.). And, as a manager, I know it would require more work of me to have to write out everything I need to communicate (stopping by to ask a question, weekly status meetings, etc.). That brings me to the most important factor . . . Even though a manager may consciously see the candidate and understand that the are "reasonable accommodations" that can be made, his subconscious will be thinking about the difficulties that have to be overcome and how it would be "easier" to hire someone else. People don't like discomfort and having to deal with situations they have never dealt with (with the inherent unknowns) is uncomfortable. The manager will ultimately be responsible for the output of the people they hire. So, I agree with Barand and gizmola: 1) A public sector job would probably be less of a challenge due to their hiring practices 2) Having a stellar history/examples of work will help alleviate any hiring manager's possible hesitation
  3. I got it! I made the query a sub-query with the @open_count calculation as part of the outer query (like you had it). Not sure why it wasn't calculating correctly as a single query. I still have more work to do as there are more complicated conditions than what I posted, but I'm pretty comfortable I can handle those. Here is the working query, but if you have any suggestions for improvement I would welcome them -- Calculate initial open count SET @open_count = ( SELECT COUNT(*) FROM projects JOIN ( SELECT project_id, MAX(change_date) as last_date FROM `project_status` WHERE change_date < '2015-01-01' GROUP BY project_id ) AS last_status ON projects.project_id = last_status.project_id JOIN project_status ON last_status.project_id = project_status.project_id AND last_status.last_date = project_status.change_date WHERE project_status.status = 'Open' ); -- Query the monthly changes in open count and apply to @open_count SELECT yearNum, monthName, @open_count := @open_count + openChange as open_at_end FROM ( SELECT MONTH(change_date) as monthNum, MONTHNAME(change_date) AS monthName, YEAR(change_date) as yearNum, SUM(status='Open') - SUM(status='Closed') as openChange FROM project_status WHERE DATE(change_date) BETWEEN '2015-01-01' AND '2015-03-31' GROUP BY YEAR(change_date), MONTH(change_date) ) as periodTotals ORDER BY yearNum, monthNum
  4. @Barand, I was waiting for you to respond What you supplied works perfectly for the specific sample data I provided. But, when I add some more realistic data (data that existed prior to January) it is not giving me the expected values. At the bottom I have provided some updated sample data. That data should provide the following output: January: 5 Feb: 4 March: 3 Using your query above I have made some progress and am very close, but there is one problem I am facing. I created the following query which correctly provides the change in open count each month: SELECT MONTHNAME(change_date) AS monthname, -- @open_count := @open_count + SUM(status='Open') - SUM(status='Closed') AS open_at_end FROM project_status WHERE DATE(change_date) BETWEEN '2015-01-01' AND '2015-03-31' GROUP BY YEAR(change_date), MONTH(change_date) ORDER BY YEAR(change_date), MONTH(change_date) Result: Jan: 3 Feb: -1 Mar: -1 So, the only thing missing is that it needs the starting value at the beginning of January and apply those changes to the running value for each month (which is what that commented line is for). So, I used the query I first provided to calculate and set that starting value and assign it to @open_count and it is being set correctly (2 with the new data). So, when I uncomment that line above I expect that it will return: January will be (2 + 3) 5, Feb will be (5 - 1) 4, March will be (4 - 1) 3. But, instead I am getting 5, 1, 1. Here is the same query, but I have hard coded the initial @open_count to 2 instead of providing the longer query above. SET @open_count = 2; SELECT MONTHNAME(change_date) AS monthname, @open_count := @open_count + SUM(status='Open') - SUM(status='Closed') AS open_at_end FROM project_status WHERE DATE(change_date) BETWEEN '2015-01-01' AND '2015-03-31' GROUP BY YEAR(change_date), MONTH(change_date) ORDER BY YEAR(change_date), MONTH(change_date) Here is the new sample data CREATE TABLE `projects` ( `project_id` int(11) NOT NULL auto_increment, `name` varchar(32) collate latin1_general_ci NOT NULL, PRIMARY KEY (`project_id`) ) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=9 ; INSERT INTO `projects` VALUES (1, 'Project A'); INSERT INTO `projects` VALUES (2, 'Project B'); INSERT INTO `projects` VALUES (3, 'Project C'); INSERT INTO `projects` VALUES (4, 'Project D'); INSERT INTO `projects` VALUES (5, 'Project E'); INSERT INTO `projects` VALUES (6, 'Project F'); INSERT INTO `projects` VALUES (7, 'Project G'); INSERT INTO `projects` VALUES (8, 'Project H'); CREATE TABLE `project_status` ( `status_id` int(11) NOT NULL auto_increment, `project_id` int(11) NOT NULL, `status` varchar(16) collate latin1_general_ci default NULL, `change_date` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`status_id`), KEY `project_id` (`project_id`) ) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=16 ; INSERT INTO `project_status` VALUES (1, 1, 'Open', '2015-01-12 17:07:31'); INSERT INTO `project_status` VALUES (2, 1, 'Closed', '2015-03-16 17:07:42'); INSERT INTO `project_status` VALUES (3, 2, 'Open', '2015-01-13 17:09:31'); INSERT INTO `project_status` VALUES (4, 2, 'Closed', '2015-02-10 17:09:36'); INSERT INTO `project_status` VALUES (5, 3, 'Open', '2015-01-13 17:11:39'); INSERT INTO `project_status` VALUES (6, 4, 'Open', '2015-04-14 17:12:25'); INSERT INTO `project_status` VALUES (8, 5, 'Open', '2015-02-03 12:48:09'); INSERT INTO `project_status` VALUES (9, 5, 'Closed', '2015-02-11 12:48:23'); INSERT INTO `project_status` VALUES (10, 5, 'Open', '2015-02-25 12:48:39'); INSERT INTO `project_status` VALUES (11, 6, 'Open', '2014-12-17 13:46:12'); INSERT INTO `project_status` VALUES (12, 7, 'Open', '2014-11-11 13:46:31'); INSERT INTO `project_status` VALUES (13, 7, 'Closed', '2014-12-16 13:46:48'); INSERT INTO `project_status` VALUES (14, 8, 'Open', '2014-12-17 13:47:01'); INSERT INTO `project_status` VALUES (15, 8, 'Closed', '2015-02-10 13:47:14');
  5. I *think* I see what you are doing there. You have separate queries to get the counts of different parameters and UNION them together. Each query appears to have logic to get the COUNT() for a particular parameter in each month/year. Maybe I oversimplified my sample data. For example, I could have a project that is 'Open' on Dec. 5, gets changed to a status of 'Closed' on Dec. 5, then gets moved back to 'Open" on Dec. 10. When I get the number of projects that are open at the end of December, I need that project to count only once even though there are two status records in December with a a value of 'Open'. I'll continue to review what you've posted to see if there is some solution I am not seeing.
  6. I need to build a report that displays the count of values based on a condition over time. I am going to give a watered down version of the problem for clarity. Assume I have two tables: projects and project_status. The project_status table tracks the changes to the status of the projects. I want to build a report on the number of projects that are currently in an 'open' status at the end of each month. The issue is that there could be multiple changes to the status of a project within a month or none at all. I can run a query to get the number of open projects for a single month (Join the projects table on the last status prior to the specific month). But I want to run a query that gets me the count for all months in the report range. Otherwise, I have to create a loop and run the query for each month in the report. Here is some sample date projects: project_id | name 1 Project A 2 Project B 3 Project C 4 Project D project_status: status_id | project_id | status | change_date 1 1 'Open' '2015-01-12 17:07:31' 2 1 'Closed' '2015-03-16 17:07:42' 3 2 'Open' '2015-01-13 17:09:31' 4 2 'Closed' '2015-02-10 17:09:36' 5 3 'Open' '2015-01-13 17:11:39' 6 4 'Open' '2015-04-14 17:12:25' So: Project A: Opened in January, Closed in March Project B: Opened in January, Closed in February Project C: Opened in January, not closed Project D: Opened in April, not closed If I wanted a report for the first quarter, the data I want returned would be something like this (note: the numbers represent the count at the end of each month): January: 3 February: 2 March: 1 Below is the query that would give the number of projects that are in an 'open' status at the end of March but, as I said, I want to have a query that gives me the records for each month in the report range rather than running separate queries for each month SELECT COUNT(*) FROM projects JOIN ( SELECT project_id, MAX(change_date) as last_date FROM `project_status` WHERE change_date < '2015-04-01' GROUP BY project_id ) AS last_status ON projects.project_id = last_status.project_id JOIN project_status ON last_status.project_id = project_status.project_id AND last_status.last_date = project_status.change_date WHERE project_status.status = 'Open' Here is an export from MySQL of the sample data for anyone that wishes to help CREATE TABLE `projects` ( `project_id` int(11) NOT NULL auto_increment, `name` varchar(32) collate latin1_general_ci NOT NULL, PRIMARY KEY (`project_id`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ; INSERT INTO `projects` VALUES (1, 'Project A'); INSERT INTO `projects` VALUES (2, 'Project B'); INSERT INTO `projects` VALUES (3, 'Project C'); INSERT INTO `projects` VALUES (4, 'Project D'); CREATE TABLE `project_status` ( `status_id` int(11) NOT NULL auto_increment, `project_id` int(11) NOT NULL, `status` varchar(16) collate latin1_general_ci default NULL, `change_date` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`status_id`), KEY `project_id` (`project_id`) ) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=8 ; INSERT INTO `project_status` VALUES (1, 1, 'Open', '2015-01-12 17:07:31'); INSERT INTO `project_status` VALUES (2, 1, 'Closed', '2015-03-16 17:07:42'); INSERT INTO `project_status` VALUES (3, 2, 'Open', '2015-01-13 17:09:31'); INSERT INTO `project_status` VALUES (4, 2, 'Closed', '2015-02-10 17:09:36'); INSERT INTO `project_status` VALUES (5, 3, 'Open', '2015-01-13 17:11:39'); INSERT INTO `project_status` VALUES (6, 4, 'Open', '2015-04-14 17:12:25');
  7. You could also just put a space between every character and put the text in a container with a width of 1px. <div style="width:1px">C L A S S</div>
  8. Try this. <?php //Verify proper key passed if (!isset($_GET['key']) || $_GET['key'] != '78J89ke93k93HJ883j003') { echo 'Invalid Key'; exit(); } //Define file to edit $htaccess = '.htaccess'; //read the entire file $contents = file_get_contents($htaccess, false); //Verify that contents were read if(!$contents) { echo "Unable to read {$htaccess} file"; exit(); } //Get current IP of user $ip = $_SERVER['REMOTE_ADDR']; //'allow from 92.27.111.112'; //Check if IP already exists if(strpos($contents, $ip)) { echo "The IP {$ip} already exists in {$htaccess} file"; exit(); } //Add new IP to contents (assumes 'deny from all' exists in file) $contents = str_replace('deny from all', "allow from {$ip}" . PHP_EOL . "deny from all", $contents); //Replace the contents of the file if(!file_put_contents($htaccess, $contents)) { echo "Error updating {$htaccess} file"; exit(); } echo "IP {$ip} added to {$htaccess} file"; ?> Edit: I just realized that this may not work as written. I wrote it with the intent that the script above would be accessible to any IP addresses. If you have the script in the same folder as the htaccess file, then how would the user ever be able to make a change? They would have to access the page from an IP that is not restricted. So, I would suggest hosting this page in another locaiton.
  9. Why not keep the IPs in a database. Then when a change is submitted you can just overwrite the existing file. Otherwise, you could end up with duplicates. Otherwise you would have to parse the current file to check for duplicates. Anyway, there is no error handling in your current script. You should start there to check file_exists() (can PHP see the file), that it could open the file, etc. EDIT: I see the problem (or at least one of them). The IF statement is checking the "variable": $_GET('key') I would think that would generate an error since the "function" $_GET() does not exist.
  10. OK, you are creating checkboxes, but there is no form. Your initial post kind of alluded to the fact that you may want the update to occur dynamically when the user clicks the checkbox. That is what budimir was referencing when he mentioned JavaScript. That is certainly achievable, but right now let's focus on doing this the old fashioned way - with a form submission. Once you get that working you can re-purpose the logic and make the action dynamic (i.e. when the suer clicks the checkbox a back end call is made via AJAX to update the database without a traditional form submission). Also, since there will be checkboxes for each record - each checkbox needs to be associated with the record that it should be updating The example code below is not optimal. Ideally you should use the PRG pattern to prevent a refresh from resubmitting the form, but in this instance it shouldn't matter. The code below assumes that the 'win' column contains a 0 or 1. <?php include ('conection.php'); //define $result as $con and run the query $sql $result = $conn->query($sql); //Check if the form was posted if($_SERVER['REQUEST_METHOD']=='POST') { //Update database with posted values //Note only CHECKED checkboxes are sent in the POST data //Get array of IDs sent in the post data $winIDsPostAry = $_POST['win']; //Filter out any IDs that are non-numeric or 0 $winIDsAry = array_filter(array_walk($winIDsPostAry, 'intval')); //Create a comma separated string for the query $winIDsStr = implode(', ', $winIDsAry); //Create query to update all the records based on the checked values $query = "UPDATE table_name SET win = id IN ({$winIDsStr})"; //Run the query } //Variable to hold the output $output = ''; //Check if there were records returned if ($result->num_rows == 0) { $output .= "<tr><td colspan='4'>0 results found</td></tr>\n"; } else { //output the data while($row = $result ->fetch_assoc()) { //Determine current state of win $winChecked = ($row['win']) ? " checked='checked'": ''; //add the results to populate the table $output .="<tr>\n"; $output .="<td>{$row['id']}</td>\n"; $output .="<td>{$row['name']}</td>\n"; $output .="<td>{$row['score']}</td>\n"; $output .="<td><input type='checkbox' name='win[]' value='{$row['id']}' {$winChecked}></td>\n"; $output .="</tr>"; } } $conn->close(); ?> <html> <head> <title> DaTaBaSe CoNeCtIoN TeStInG PaGe </title> <style> body { color: #FF0000; background-color: #000000; } .myTable { border-collapse: collapse;} .myTable td, th { color: #FF0000; border: 5px solid #0000FF;} </style> </head> <body> <form action='' method='post'> <table class="myTable"> <tr><th>ID</th><th>Name</th><th>Score</th><th>Win</th></tr> <?php echo $output; ?> </table> </form> </body> </html> EDIT: I did not test this, so I'm sure there are some errors, but hopefully this will get you pointed in the right direction.
  11. There could be any number of reasons why - many that have nothing to do about technology, but with organization politics and/or division. For example, you may have different groups responsible for the "desktop" vs. "mobile". Plus, when mobile first became a major factor, responsive design was not at the forefront. It was all about the phone since tablets were still gaining momentum. Thus the goal was to support the desktop and phones - not everything in between. it was quicker to get an adaptive rewrite to production. Also, responsible web design requires a unique skillset for which there was not a huge amount of expertise initially. Once the adaptive web designs were done to meet the immediate need, there was less of a priority to go back and rewrite once again to be responsive. So, the early mobile adopters may be slower to responsive. Lastly, many of the companies you cite have specific mobile applications. Many sites try to push mobile users to install their mobile apps instead of expanding their generic web content to be optimal for small displays.
  12. @SamuelLopez: Are there more than just the two statuses? If not, you should change the field to a Boolean. E.g. name the field "passed" and use 1 (TRUE) to indicate passed and 0 (FALSE) to indicate not passed. @Barand, Correct me if I am wrong, but I don't think the IF() statements are needed - just the conditions. A condition will resolve to either TRUE (1) or FALSE (0). So, this should work as well: SELECT projectid as project , SUM(Status_ID=1) as passed , SUM(Status_ID=2) as failed FROM tbltesttransactions GROUP BY projectid
  13. Some feedback: There is something wrong with your sign-up form. I think it is expecting an email address as the username, but then it has two other fields to enter an email and verify it. If I enter a value that doesn't look like an email in the username field it gives me errors that the email and username are not available. Huh? It also appears the value must be the same in all three fields. Plus, when there is an error the first password field is being repopulated - you should never repopulate a password field when there are errors. If the email address will be the "username", then you don't need a username field. Just have the email and confirmation fields - but make it known that their email address will be used for their username. I don't know what browser you are testing with, but in Chrome that custom cursor is an eyesore. Lastly, the buttons for Login and Sign Up are not acting like buttons. I can't click on the buttons - I have to click exactly on the text.
  14. Step 1: Create an array of values to be compared against. This can be set at the top of the script, in an external file or even in a database. The key takeaway is that this is DATA and should be separated from the LOGIC. Since we don't want to have to worry about string values not comparing because of an errant character in a different case, the values should be create in a specific case (lower or upper): /List of admin urls to test for $admin_urls = array('http://www.golden-wand.com/pages/admin.php', 'http://www.golden-wand.com/pages/admin-test.php'); Step 2: The condition: Comparisons work similar to mathematical order of operations: left to right with items in parenthesis worked inside out. The process is run to return an ultimate TRUE or FALSE response. 1. The first test checks to see if the session 'admin' value is 'loosely' equal to the string value '1' and results in a TRUE or FALSE for that partial comparison. 2. Next, there is an AND operator. If the first result was FALSE then the final result is FALSE and no further comparisons are needed. Since a FALSE AND any other result will be FALSE 3. strtolower() is run against the 'unknown' session value to convert it to all lower case. 4. the in_array() function then compares that lower case value to the array $admin_urls to see if the value is contained in one of the array elements. If it does exist in the array the partial result is TRUE, else it is FALSE 5. The "NOT" operator (!) is applied to the result of the above comparison - effectively switching the results. Therefore, if the value is NOT contained in the array the result will be TRUE - else it will be FALSE 6. THe results of the 'admin' comparison and the NOT in_array() comparison are tested. If both are TRUE, then the final result is TRUE. Else, the final result is FALSE. I hope that helps. If not, put the bong down before you burn any more brain cells.
  15. I put the strtolower() specifically because of a different post you made a day or two ago around this same code where you have a condition check where the values being compared had a difference in the case of one letter. You can prevent those problems from ever happening again if you: 1) create the array of values to validate against in all lower case. 2) use the strtolower() on the value being tested However, I did make a mistake because I did not follow #1 above in the example code I provided. As my signature states, I do not always test the code I provide (especially if it would require me to create DB tables and add data) - it is provided as a guide for writing your own code. It should have been //List of admin urls to test for $admin_urls = array('http://www.golden-wand.com/pages/admin.php', 'http://www.golden-wand.com/pages/admin-test.php'); Unless there are legitimate reasons, you should generally not have logic that is dependent upon the 'case' of the letters within strings. By forcing things to upper or lower case you will prevent a lot of potential bugs
  16. I gave you a complete, correct answer. But, since you apparently didn't understand it you dismissed it. What you are trying to do (include the URLs in the conditional logic) is a poor implementation. If you ever need to add/edit/remove any of the URLs used for this purpose you would need to modify the logic. Instead, I gave you a solution that allows you to modify the conditions (i.e. the URLs) without ever having to touch the logic. All you would ever need to do is modify the array "$admin_urls" to add/edit/delete any URLs you want used for the conditional check and the logic will work. And simple does not mean less lines of code - it typically means more lines. I can cram a whole bunch of conditions, loops, whatever onto a single line. That makes it more complicated to read, debug, edit. A simple solution is one that removes complexity. Usually it means each line of code has a specific purpose. EDIT: The only flaw I see in what I provided was that I read the logic as wanting to see if the session value was in the list of tested URLs. I now see that you wanted to verify it was not in that list of values. Simple enough change //List of admin urls to test for $admin_urls = array('http://www.golden-wand.com/Pages/admin.php', 'http://www.golden-wand.com/Pages/admin-test.php'); //One simple if() condition if($_SESSION['admin']=='1' && !in_array(strtolower($_SESSION['url']), $admin_urls)) { echo "<input type=\"button\" value=\"Admin Page\" class=\"button hvr-wobble-skew\" onclick=\"location.href='http://www.golden-wand.com/Pages/admin.php'\">\n"; }
  17. Absolutely, separate the data from the logic. That way you can change the values being checked without ever having to change the actual code. <?php //List of admin urls - this can be defined elsewhere $admin_urls = array('http://www.golden-wand.com/Pages/admin.php', 'http://www.golden-wand.com/Pages/admin-test.php'); //One simple if() condition if($_SESSION['admin']=='1' && in_array(strtolower($_SESSION['url']), $admin_urls)) { echo "<input type=\"button\" value=\"Admin Page\" class=\"button hvr-wobble-skew\" onclick=\"location.href='http://www.golden-wand.com/Pages/admin.php'\">\n"; } ?>
  18. Try this: <?php //Define the number of columns allowed $max_columns = 3; //Query the data $query = "SELECT ID, FirstName, LastName, MonthEx FROM Members ORDER BY LastName"; $result = mysqli_query($Garydb, $query); //Put results into an array $rows = array(); while($rows[] = mysqli_fetch_array($result, MYSQLI_ASSOC)) {} //Determine the number of rows $max_rows = ceil(count($rows) / $max_columns); //Separate data array into chunks for each column $data_chunks = array_chunk($rows, $max_rows); //Generate HTML output (into a variable) $output = ''; //Iterate over the array chunks while not empty while(count($data_chunks[0])) { //Open new row $output .= "<tr>\n"; //Get next record from each chunk foreach($data_chunks as &$chunk) { //Remove the first element off of the current chunk $data = array_shift($chunk); if(empty($data)) { continue; } //Create the $output .= "<td>{$data['FirstName']} {$data['LastName']}</td>"; $output .= "<td><a href='update.php?update={$data['ID']}'>EDIT</a></td>"; $output .= "<td><a href='delete.php?delete={$data['ID']}'>DELETE</a></td>\n";; } //Close the row $output .= "</tr>\n"; } ?> <html> <head></head> <body> <table border='1'> <?php echo $output; ?> </table> </body> </html>
  19. With all due respect, your grammar and punctuation is atrocious. I am not a grammar nazi, but what you wrote is very difficult to understand. If you want to get free help, the least you can do is write a clear request. I can't tell if you want the data to go top-down/left-right or left-right/top-down. Do you want this 1 2 3 4 5 6 Or this 1 4 2 5 3 6
  20. You only need to include a link to a txt file if you are wanting us to run some specific tests on your site. You do not need it to ask a question about some code. You may have a failure on both conditions: if($_SESSION['admin']==='1'){ The three equal signs means it has to match the value and the type - i.e. it has to be a string value of one. A numeric value of 1 will not pass the condition. On the second condition it will never match because "pages" does not equal "Pages"
  21. Jacques1 point is that the SELECT statement to check for a duplicate is faulty. Instead, you should just attempt the INSERT. Then, if the INSERT fails due to a duplicate constraint, you can then inform the user that the name is already taken. The current process has a hole in the logic. Granted it is very small, but it leaves the possibility for a race condition where two requests are made at the same time such that both SELECT queries pass, but then both try to do an INSERT with the same value. One will succeed and the other will fail - with no proper error handling. I believe the error code for a unique constraint is 1062. So, you would check for that error code after attempting the INSERT. Also, you should almost always trim() user submitted values. A password would be one example that it would not make sense to do so. You currently have no validation of the user submitted values: e.g. ensuring required fields have values, that the values contain content appropriate for the context, etc. I assume you plan on adding that, but you would need to trim them before doing that. I would also add some logic to setting the variables from the post values to handle if a field is not passed. E.g. $firstname = isset($_POST['FName']) ? trim($_POST['FName']) : false;; Otherwise you will get warnings if a field isn't included.
  22. I prefer to create a function to generate my select fields. I would also highly suggest you follow a standard of putting your logic (i.e. PHP code) at the top of the document and only output the generated content within the HTML at the bottom of the page. Here is a quick example <?php //Function to create select options function createSelectOptions($optionList, $selectedValue=NULL) { $optionsHTML = ''; foreach($optionList as $value => $label) { $selected = ($value == $selectedValue) ? " selected = 'selected'" : ''; $optionsHTML .= "option value=\"{$value}\"{$selected}>{$label}</option>\n"; } return $optionsHTML; } //Get previously selected value (if passed) $projectSelected = isset($_POST['project']) ? $_POST['project'] : NULL; //Query list of available values $projectList = array(); $query = "Select Proj_ID as value, PROJECT_NAME as label from tblproject"; $result = $mysqli->query($query); while($option = $result->fetch_object()) { $projectList[$option->value] = $option->label; } //Create the options for the project select list $projectOptions = createSelectOptions($projectList, $projectSelected); ?> <html> <head></head> <body> <select name="project" class="required" id="selproject"> <?php echo $projectOptions; ?> </select> </body> </html>
  23. Also, by default, PDO only emulates prepared statements. You should ensure you are turning off emulation in your connection to the DB. See this post by Jacques1 for an example: http://forums.phpfreaks.com/topic/298661-help-needed-with-signuplogin-page/?do=findComment&comment=1523598
  24. The timezone offset is basically the timezone. The timezone offset is the difference from the the user's timezone and UTC time. So, you can calculate a time in the user's timezone based on the offset. But, you need to ensure the the times you are storing are in UTC time. Then, when you retrieve the time (from the database) modify it to the user's timezone.
  25. Your query is malformed $del = "DELETE * FROM Members WHERE ID = '".$delete."'"; There is no field list for a delete query, e.g. the * Try this: $del = "DELETE FROM Members WHERE ID = '".$delete."'"; Also, your code is full of security risks - particularly with SQL Injection. You should spend some time learning some best practices.
×
×
  • 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.