Jump to content

TapeGun007

Members
  • Posts

    307
  • Joined

  • Last visited

Everything posted by TapeGun007

  1. Thanks mac_gyver. I did my homework on what you said as I wasn't sure where to set this. I used this to do it for now and will set it back later. ini_set("display_errors", 1); ini_set("track_errors", 1); ini_set("html_errors", 1); error_reporting(E_ALL); [/cdoe] That gave me the error I was looking for on another page and was able to quickly resolve the issue.
  2. Ok, I figured out WHY I'm getting an error. I didn't add the table ProspectCounty as of yet. But again, my question more or less is related to why this doesn't generate an error so that I could troubleshoot from there.
  3. No. When I submit the form, the top header menu appears and nothing below. It's just a blank page.
  4. I'm trying to figure out my bug here, and I what I really want to know is how to debug my own code which would result in less posting here. Also it would be nice to contribute and help others as I learn from my mistakes. I have this code: mysqli_report(MYSQLI_REPORT_ALL); This is near the top of my code after all the include files. Then below after a form I have this code: $sql = "INSERT INTO Prospects (ProspectCode, ProspectBusinessName, ProspectName, ProspectAddress, ProspectAddress2, ProspectCity, ProspectState, ProspectZip, ProspectCounty, ProspectCountry) VALUES (?,?,?,?,?,?,?,?,?,?)"; // Check $sql to ensure it's correct echo "<p>$sql</p>"; /* Prepared statement, stage 1: prepare */ if (!($stmt = $con->prepare($sql))) { echo "Prepare failed: (" . $con->errno . ") " . $con->error; } // Bind parameters, stage 2. Types: s = string, i = integer, d = double, b = blob if (!$stmt->bind_param('ssssssssss', $ReferralCode, $Business, $Contact, $Address, $Address2, $City, $State, $Zip, $County, $Country)) { echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; } // Execute. stage 3 if (!$stmt->execute()) { echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error; } I'm trying to error check, so I could debug it myself, but there is no error. Weirdly enough, it worked fine up until I added County and Country. *sigh* It's probably some very simple syntax error, but how come it doesn't produce an error so I can troubleshoot the problem?
  5. Thanks Barand, good knowledge. I did not know about the <pre> tags. I just went and looked them up. I'll remember that for future reference.
  6. You can use <div> containers to seperate content into multiple layers. Therefore the div containers have to be positioned absolutely and marked with a z-index. for instance: <div style="position: absolute; z-index:100">This is in background</div> <div style="position: absolute; z-index:5000">This is in foreground</div> Of course the content also can contains images, etc. This isn't a php related question however.
  7. I'm not sure I understand the question. Is the purpose where if an employee forgets their password, they can request it via email? The php code above are some functions that appear unrelated to the save button. If I am understanding you correctly you would use SQL something like this: $employee_id = $_POST['employee_id']; SELECT * FROM Users WHERE employee_id = $employee_id $password = $row['password']; Now that you have the variable set, you can email it to them. Again, this is if I am understanding what you are trying to accomplish here.
  8. gizmola, I'm no expert php coder per se. I've been asked to do a fairly complex job at work with my little bit of knowledge. I've written some decent code, but never used json or var_dump. I've written pretty simple stuff like writing to mySQL databases. Now I've had to completely re-learn that using mySQLi. At the time of this post, I didn't realize that there wasn't much to json. Most of my post was just reaching out because I had no idea where to even start. All of the code that I had looked at wasn't working. Barand got me on the right track of research as I never mind learning or taking the time to learn on my own. As I read though his curl example it led me to read up on the json_decode which in turn helped me to understand what json was. I had the raw json up at one point and viewing it helped me to understand Barands code better as well as other examples. Most of what I'm trying to understand is not just what code works, but how it works. Sometimes the lack of explanations leaves me hanging a bit. Thank you for your input as well. I'll have to learn how to use the var_dump better to understand how best to use that tool to help debug my code.
  9. Finally. I just kept googling different information and with both of your help, I was able to find the answer I was looking for. I wasn't realizing that it was a multi-dimensional array. I keep looking at the Google output, looked at the json_decode and realized that was the key to my success. Now this may not be the BEST way to accomplish this, but it serves the purpose none the less. $geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=95117&sensor=true'); $output= json_decode($geocode); for($j=0;$j<count($output->results[0]->address_components);$j++){ echo '<b>'.$output->results[0]->address_components[$j]->types[0].': </b> '.$output->results[0]->address_components[$j]->short_name.'<br/>'; $type = $output->results[0]->address_components[$j]->types[0]; switch ($type){ case "sublocality_level_1": // Sub Locality (for foreign address') $ForeignAddress = $output->results[0]->address_components[$j]->short_name; case "locality": // Name of City $City = $output->results[0]->address_components[$j]->short_name; case "administrative_area_level_2": // County or equivalent $County = $output->results[0]->address_components[$j]->short_name; case "administrative_area_level_1": // State / Province $State = $output->results[0]->address_components[$j]->short_name; case "country": // Country $Country = $output->results[0]->address_components[$j]->short_name; } } echo "$City, $State, $County, $Country"; This also works if you have a longitude/latitude or if they are in a foreign country, you may need to store additional address information like this one: $geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=48.283273,14.295041&sensor=false');
  10. I was excited to see that he could extract the city, state, and country from just a zip code so easily. However, I need to separate the variables as I noted above and also need to extract the county. I've read so many examples online, some of which are incomplete (never answered). For example, I tried this to see if I could just extract the city name: $request = file_get_contents ('http://maps.googleapis.com/maps/api/geocode/json?address=95117&sensor=true'); $data = json_decode( $request, true ); foreach ( $data['results'][0]['locality'] as $value ) { echo $value['short_name'] . '<br />'; // no value is echo'd } It does not work, so there is something I'm not understanding. However this does work: $request = file_get_contents ('https://maps.googleapis.com/maps/api/geocode/json?address=meerpaal%208d%20oosterhout&sensor=true'); $data = json_decode( $request, true ); foreach ( $data['results'][0]['geometry'] as $value ) { echo $value['lat'] . '<br />'; echo $value['lng'] . '<br />'; // This will show me the longitude and latitude }
  11. @ginerjm, yes but that doesn't contain the county. @Barand, this is my fault, because I didn't explain the results I was looking for. In the above example is there a way to separate out the following: $county = San Diego County $city = Bonita $state = CA $zip = 91920 I will research what you just gave me, but yes that works perfectly.
  12. I'm trying to create a page where if a person inputs a zip code, I can return the County, City, and State. After reading about the Google API, it seems you need to register an API key and they can force a quota of some sort. Plus they use a lot of JSON and I simple don't understand what their code is doing. One way around trying to learn JSON, the Google API, registering a key and worrying about a quota, is using a form that collects the zip code and then making a call that will return a value. For example, let's say I enter the zip code "91920" into the form. I can URL encode that into the following link: http://maps.googleapis.com/maps/api/geocode/json?address=91902&sensor=true This link will send back all the information I am looking for, what I want to do is pull the information from that link/page. I'm not sure how to accomplish this task and cannot seem to google the right question. Also, let me know if you think there is a much better way to go about this process.
  13. Ug. Nevermind, I solved my own deal here, obviously I had different variable names that didn't match. I wish I could delete this.
  14. I just realized that is supposed to be $_POST
  15. I've read up on being able to POST multiple inputs, unfortunately every example I see of this assumes there is a value already assigned. So for example, I wants a sales person to enter multiple Business names in a form. From what I read it would go something like this: <input name="BusinessName[]" /> Every example I see though assumes that I should put value="Business1", "Business2" etc. However using the value will fill out the form with Business1 and Business2 where I need a blank input field. I tried the above anyway to no avail as I used this code to try to read it: foreach ($POST['Business'] as $b){ echo "$b <br>"; } This resulted in nothing being echo'd. I can't seem to find the right information when trying to Google a solution. Any help would be greatly appreciated.
  16. LOL. I can't believe it was that simple. Yeah, I had $con->close; in there.
  17. I have a typical prepared mySQLi statement that runs just fine for example: ... $stmt = $con->prepare($sql); if($stmt === false){ trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $con->error, E_USER_ERROR); } $stmt->bind_param("s",$Username); $stmt->execute(); $stmt->bind_result( ** Variables here** ); $stmt->fetch(); $stmt->close(); This all works fine. Now I want to make another mySQLi call using a function basically. The function works FINE in a test file with no other mySQLi calls in it. For sake of ease, just assume this was actually in the code after the above. $sql="INSERT INTO LoginAttempts (LASalesID) VALUES ('$ID')"; if ($con->query($sql) === TRUE) { echo "New record created successfully"; } else { // Report the Error echo "Error: " . $sql . "<br>" . mysqli_error($con); } I'm getting the Error message every time. Am I not closing out the initial calls correctly and freeing up resources?
  18. I found a different way, but I'm betting this is a LONG way around the issue: I basically just take a new var, $penaltytime and add that time to $LastAttempt. $penaltytime = new DateTime($LastAttempt); $penaltytime->add(new DateInterval($penalty)); $penaltytime = $penaltytime->format('Y-m-d H:i:s'); Then I just compare if the $penaltytime is now greater than the current time, $date. if ($penaltytime > $date){ echo "<p>You have a penalty</p>"; }else{ echo "<p>You have no penalty</p>"; } This actually worked. However, I read several other articles about doing this in the mySQL mentioned by Barand, I would like to know exactly how to implement that. I probably didn't write the best mySQLi here, but it does work. $sql="SELECT * FROM LoginAttempts WHERE LASalesID = '$ID' AND LACleared = 'no' ORDER BY LATimeStamp ASC"; $rs=$con->query($sql); $rs->data_seek(0); // Get the total number of attempts $attempts = $rs->num_rows; // Cycle through all the login times and get the last login date/time. while($row = $rs->fetch_assoc()){ $LastAttempt = $row['LATimeStamp']; } How would I implement your method Barand? The table is simply (LA = "last attempt") LAID LASalesID = The Sales Persons ID LATimeStamp (The db auto generates this by default when a LASalesID is INSERTED) LAFailed (This is so I can keep track of the number of times a log in has failed regardless of time/date, default is 'yes') LACleared (If the log in failed and I reset this field to "yes" then they can log in again, default is 'no')
  19. I have a table where a timestamp is automatically stored with the UserID if they fail to login correctly. I want to track each failed login attempt and at what time it occurred. I set $LastAttempt to their last login attempt and the format is simply this: 2015-07-28 01:46:08 I also set $date to the current date/time in the same format as above. If they have more than 5 login attempts, I want to set a penalty. I have a switch that sets $penalty to the number of minutes before they can attempt to log in again. So if their failed log in attempts exceed 5, then it penalizes them 10 minutes before they can even try again. What I want is for that user to have to wait 5 minutes before they can log in again. I just cannot figure out the best way to go about this and could use some direction. I've tried several pieces of code, but because I'm not understand how it works, I'm probably not modifying it correctly. I'm open to suggestions, but what I'm assuming I would do is this: I know they have 5 failed log in attempts, so I would take the timestamp, add the penalty to it and if the result is greater than the current timestamp then they cannot log in yet. Then I would like to post how much longer before they can make another attempt. Does this sound right?
  20. I had a mySQLi prepared statement that was just before that initial IF THEN. I put $stmt->close(); just before the IF THEN and that fixed the error. Thank you for helping me find the correct error message!
  21. Error: INSERT INTO LoginAttempts (LASalesID) VALUES ('10000') Commands out of sync; you can't run this command now Good catch Barand. I was using code from another site and apparently didn't fix all the conn to con's. At least I can Google this error message and see if that helps.
  22. I'm beating my head against the wall trying to figure out what I've changed. This INSERT near the bottom was working. I changed something and now it fails every time. if($Email == $Username && $Pass == $Password){ {set session ID's} // $stmt->close(); // If the login is successful, then go ahead and UPDATE and override all failed attempts. $sql = "UPDATE LoginAttempts SET LACleared = 'yes' WHERE LASalesID = '$ID'"; if ($con->query($sql) === TRUE){ echo "Login Successful"; }else{ echo "Error updating record"; } // $con->close(); // Redirect to crm.php header('Location: crm.php'); die(); }else{ $sql="INSERT INTO LoginAttempts (LASalesID) VALUES ('10000')"; if ($con->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; <---- I get this error every time. } $con->close(); So at the bottom, I get the Echo "Error: " with the sql string every single time. I have no idea what I've done wrong. All the other fields in the table LoginAttempts are set to default one of which is a TimeStamp in mySQL. I know that the $con is fine because I use it early to verify the username is correct from another table. What am I doing wrong here?
  23. Check with your web hosting company. They likely automatically update everything.
  24. Ah ok. Thank you kicken, I just didn't know the right thing to Google. This makes total sense.
  25. Ok, so I setup up a file .htaccess that points to my .htpasswds file in a secure location. When a user tries to enter into a specific directory, it is password protected and prompts a box with a username and password. Is there any way that I can read this username and password with php? I'm not asking you to write code for me, but you if have an example or a page I can read, I would love to see how this is done (if possible). Depending on the username, it would direct them to the correct folder with their files. Or maybe I'm going about this the wrong way altogether? Thanks.
×
×
  • 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.