-
Posts
5,451 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
what result are you trying to achieve? comparing them using what condition or rule?
-
your form processing code isn't testing if there is any data in any of the variables and it isn't even testing if a form was submitted. for each piece of submitted data you need to define what is an acceptable value and if it is required or if it can be empty. for required fields, at a minimum, you need to trim the data value and if it is empty, don't even run the code for the database query.
-
your Postcode table should have an id (auto increment) column. you would just submit the id value and query the database table at any point where you need all the other information related to that submitted id. also your current use of the suburb as the submitted value is not unique. an auto increment id would be unique.
-
you are multiplying $mypassword * 12. as long as $mypassword doesn't start with a number, that multiplication will produce a zero value as will an empty $mypassword and the hash of that will always be the same. if you used the same logic when you inserted the row in to the user table, the hash stored in the user table corresponds to a zero value and leaving the password field empty will match it. why are you multiplying a string by a number?
-
lol, you should have never used the password() function for your user's passwords. there is now an old_password() mysql function that you can use and it should return values that match what you have stored in the database table. i would also recommend the following - 1) add two new columns to your database table to hold a new hash value and a unique random salt per user. 2) when anyone successfully logs in, take the entered password, apply a new salted-hash algorithm of your choice to the password and store the new hash value and random salt string in the database table. 3) if any one tries to log in and the new columns already hold values for them, use the new columns to log in the user. 4a) at some point your active users will be switched over to use the new hash/salt columns. email all the users who haven't logged in yet to do so with a deadline date or they will need to specifically request a password reset to log in after that date. 4b) on the date you have determined remove the old password column and any code that is using the password() or old_password() function. make backups of your database and code before making any functional changes and test the changes off-line before putting them onto a iive server.
- 6 replies
-
- passwords
- 16 characters
-
(and 3 more)
Tagged with:
-
you are binding the month as though it is an integer. it is apparently the month abbreviation, a string. the internal conversion of those mismatched data types is probably causing all the month values to be matched. make sure you are treating data as the correct type.
-
but does it produce the result you expect for different sets of data?
-
test code that implements the suggestion i made - <?php $String = '48.010918880032534,-102.27871447619208,48.007298546092386,-102.27871873313035,48.007300404087175,-102.28410804755288,48.007302263082124,-102.28949736197535,48.007304121076913,-102.29488670439923,48.007305979071589,-102.30027601882199,48.010925506717513,-102.30027931864152,48.014545007363211,-102.30028259146059,48.018163867996407,-102.3002842242235,48.023143739025727,-102.30028731751861,48.023143709229146,-102.29967535036019,48.023140964347476,-102.29489150234963,48.023137856666608,-102.28949565918271,48.023137825974516,-102.28890660889158,48.023135053987971,-102.28409987201547,48.023131946306933,-102.2787040848512,48.018158490915084,-102.27870810340568,48.014539184972818,-102.27871024825487,48.010918880032534,-102.27871447619208'; $Exp = explode(',',$String); if(is_array($Exp)){ $C = 1; foreach($Exp as $Exp2){ if(!empty($Exp2)){ if($Exp2 > 0){ $latitude[] = $Exp2; } else { $longitude[] = $Exp2; } } } } $m['maxlat'] = max($latitude); $m['minlat'] = min($latitude); $m['maxlong'] = max($longitude); $m['minlong'] = min($longitude); // the prefect corners $c[1] = array($m['minlat'],$m['minlong']); $c[2] = array($m['maxlat'],$m['maxlong']); $c[3] = array($m['minlat'],$m['maxlong']); $c[4] = array($m['maxlat'],$m['minlong']); function distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } foreach($c as $corner=>$arr){ foreach($latitude as $key=>$lat){ $dist = abs(distance($arr[0],$arr[1],$lat,$longitude[$key], "M")); $result[$corner]["$dist"][] = array($lat,$longitude[$key]); } ksort($result[$corner]); } echo "The four corners found are:<br>"; foreach($result as $arr){ $first = array_shift($arr); echo $first[0][0] .' '. $first[0][1] . '<br>'; }
-
exactly what i was going to write. without a state-able rule, there's no way to write any code to do it. how does this sound - form the prefect rectangle using the min/max x/y values then find the distance between those 4 "prefect" corners and the actual points and the closest point to each of the "perfect" corner points is the corner point you are trying to find?
-
it's probably for consistency purposes. you can use the same line of code to fetch the next element from the array no matter how rows are in the array being operated on.
-
it might help if you state what it is you are trying to accomplish, rather than stating what you are doing that doesn't produce the result you want. what i think you are trying to do is use a search radius and add/subtract that radius to the starting point's lat/longitude to quick find all the points within that bounding square, then to actually calculate the distance from the starting point to those quick find points to remove any that are outside the search radius.
-
an issue that stands out is that you are using number_format() on values, not just for display purposes, but that those formatted numbers are being used in the calculations. when you end up with a number with a comma 1000's separator in it, only the leading number before the comma will be used in the calculations. you should only use number_format() right before you display a value and only to produce the displayed output. the original variable needs to contain the unformatted value.
-
How to keep checkboxes checked and dropdown selections on submit
mac_gyver replied to jrpelt's topic in PHP Coding Help
for drop-down select menus output selected="selected" inside the <option > tag you want to be selected. -
mysqli: select rows, update if >0 else insert
mac_gyver replied to wright67uk's topic in PHP Coding Help
as a continuation of the above reply, the link i posted is the same information as the link awjudd posted in his last reply. using this method will shorted your code from about 13 lines to 3 lines. your original code needed to do what pbs posted, but in order to use $stmt->num_rows you need to store the result using $stmt->store_result() first. the $stmt->get_result() in the code posted by awjudd returns a mysqli_result that you need to fetch the row from before you can access the count value. -
mysqli: select rows, update if >0 else insert
mac_gyver replied to wright67uk's topic in PHP Coding Help
there's a query that does that - http://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html -
a form page like that linked to script is using would be simple to create. 1) read the first two lines of the uploaded csv file. extract the header names from the first line and extract sample data from the second line. 2) read the database table definition to get the column names and produce the drop-down menus. 3) when the form is submitted, any drop-downs that have been picked will define which csv column name goes with a database column name. any drop-downs that have not been picked don't map to anything and would cause that csv column to be ignored in the data. the submitted information (or sets of data you have saved somewhere) would produce a map like this - // list of csv header names to database column names $field_list['Latitude'] = 'latitude'; $field_list['Longitude'] = 'longitude'; $field_list['DateOccurred'] = 'date'; $field_list['Tripname'] = 'trip'; $field_list['Angle'] = 'angle'; $field_list['Speed'] = 'speed'; $field_list['Altitude'] = 'alt'; the $want array in the code i posted above would be produced from the $field_list array keys. the $fields variable in the code i posted would need to loop through the resulting $map array to get the csv fields in the same order as the data will be and get the actual database column names out of the above $field_list array.
-
everything i posted had to do with working with an arbitrary order of the fields in the csv file, not relating a specific csv header name to its corresponding database column name. do you want to do this upon each import or do you just want to set up a static definition that relates the csv header names, like "DateOccurred" to a database column name, like "date"? to do the former, you would need a script like the one you linked to. to do the latter, you could use the code I posted and just add one array that lists the database table columns and build the field list in the query from that array.
-
MSSQL and PHP Incorrect syntax near 'id'. (severity 15
mac_gyver replied to NewSQLDev's topic in Microsoft SQL - MSSQL
sticking with a problem until it is solved is actually a highly valued trait, no matter what the subject is. if you just post your code and your error on any help forum and expect a copy/paste solution that won't involve any effort on your part, you are in for a huge surprise. -
the order doesn't matter (see the code i posted.) the field list in the query and the data in the query match each other. if any of the fields you do want are not present in the actual data file, you would need to set up appropriate default values in your database table since the code won't include a column name that isn't in the header line.
-
as a continuation of the above reply, once you have the result from array_intersect, you can use array_intersect_key against the $data array to get just the correct data values from it. quicker to just post some code - // the fields you want (these can be in any order) $want = array('Latitude','Longitude','DateOccurred','Tripname','Angle','Speed','Altitude'); // the fields from the header line (code to get this from your data is left up to you) $have = array('Latitude','Longitude','DateOccurred','field3','field4','field5','Tripname','field7','Angle', 'field9','field10','field11','field12','field13','field14','Speed','Altitude','field17'); $map = array_intersect($have,$want); // get only the fields you want $fields = implode(',',$map); // use this to make the list of field names in the query statement $date_field = array_search('DateOccurred', $map); // find the position of the date field for special handling // make up some test data. the order of fields matches the $have array (your code would get this from the file) $data = array('Latitude1','Longitude1','11/4/2013','field31','field41','field51','Tripname1','field71', 'Angle1','field91','field101','field111','field121','field131','field141','Speed1','Altitude1', 'field171'); // processing of the data starts here ---------------------------------------- $data = array_intersect_key($data,$map); // get only the data fields you want $data[$date_field] = date('Y-m-d H:i:s',strtotime(str_replace('/', '-', $data[$date_field]))); // format the date $data = array_map('mysql_real_escape_string',$data); // treating all fields like strings and apply escape $sql = "INSERT INTO temp ($fields) VALUES ('".implode("','",$data)."')"; // treating all fields like strings echo $sql;
-
A twister - Unable to prevent a second login by the same member.
mac_gyver replied to ajoo's topic in PHP Coding Help
you would need to temporarily comment out the header() statements. -
you would get the field names from the header line into an array and have an array of the fields you want. use array_intersect to filter out all the field names that you don't want between the first array and the second. the keys in the resulting array will be the index offsets [0],[16],[6], ... in the $data array for the corresponding field name. if you post an example of the format of the header line someone could post code showing how to do this.
-
web pages contain html tags. the html tag for an image is <img src='a url'> in this case, the url would be that of your pchart php script.
-
A twister - Unable to prevent a second login by the same member.
mac_gyver replied to ajoo's topic in PHP Coding Help
each of your header() redirect statements need an exit statement after it to prevent the rest of the code on the page from running. you also cannot echo or output any characters to the browser before a header() statement. if you are actually seeing the echoed output, the header() statement won't work at all and if you are not seeing the output and the header() is working it means that php is buffering output and echoing things to help you debug won't work.