Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,449
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. actually, you would want to make sure you can produce the code to do this at all, before you make the jump to using ajax to do it without refreshing the page. the task you are attempting is fairly common and even has an acronym - CRUD (Create, Read, Update, Delete.) your goals are to be able to create new records and insert them and to display the existing records with a way of updating or deleting them. when you select the update operation, the existing values are retrieved and populate the form. when you submit the form, the values are used to update the record.
  2. i'm going to guess your page has a header() redirect back to itself, for just the base url without the ?query string on it and you are seeing the result of the second page request? if so, your execution path probably changed due to a change in the data, combined with an error in the program logic. what's the entire logic on the page? and for your 'This page has been accessed in error.' condition, shouldn't you prevent execution of the remainder of the code on the page so that you don't produce follow on errors?
  3. these are your two function definitions (i corrected the mailresetlink() function to use the original $to parameter.) put these into a file that you include into your main code - <?php function getRandomString($length) { $validCharacters = "ABCDEFGHIJKLMNPQRSTUXYVWZabcdefghijklmnopqrstuvwxyz123456789"; $validCharNumber = strlen($validCharacters); $result = ""; for ($i = 0; $i < $length; $i++) { $index = mt_rand(0, $validCharNumber - 1); $result .= $validCharacters[$index]; } return $result; } function mailresetlink($to,$token){ $subject = "Glömt lösenord - Website"; $uri = 'http://'. $_SERVER['HTTP_HOST'] ; $message = ' <html> <head> <title>Glömt lösenord - Website</title> </head> <body> <p>Klicka på länken för att ändra ditt lösenord, <a href="'.$uri.'/test/reset.php?token='.$token.'">LÄNK</a></p> </body> </html> '; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: NiceMail<noreply@domain.se>' . "\r\n"; $headers .= 'Cc: Admin@example.com' . "\r\n"; if(mail($to,$subject,$message,$headers)){ echo "Mailet med länken för att ändra ditt lösenord är skickat till <b>".$to."</b>"; } } your main code, with the query and code to fetch the email2 column value - <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php if(!isset($_GET['email'])){ // no get variable - display the form echo'<form action=""> Email: <input type="text" name="email" /> <input type="submit" value="Ändra lösenord" /> </form>'; exit(); } // the form has been submitted $email=$_GET['email']; include("settings.php"); connect(); $q=sprintf("SELECT email2 from hm_accounts where accountaddress='%s'", mysql_real_escape_string($email) ); $r=mysql_query($q); $n=mysql_num_rows($r); if($n==0) { echo "Emailadressen finns inte <br /> <button onclick='javascript:history.go(-1)'>Gå tillbaka</button>"; die(); } list($email2) = mysql_fetch_array($r); $token=getRandomString(20); $q="INSERT into tokens (token,email) values ('$token','$email2')"; mysql_query($q); mailresetlink($email2,$token);
  4. your last class method/function is missing its closing } i recommend that when writing code that you use indentation so that the {} that belong together are at the same indentation level.
  5. you can start by not creating new threads in the forum for the same task. the forum members are not going to follow you around through a series of threads for the same thing.
  6. are the domains, the @xxx.com, in both of the email addresses the same? anyway, you are probably triggering some relaying restrictions on your mail server. what if any php errors do you get when you add the following two lines of php code into your program - ini_set("display_errors", "1"); error_reporting(-1);
  7. what have you tried? the point of programming help forums are not to find or to write code for you. help forums are to help you with code you have written.
  8. one of the points of using functions is that after you write and test them, you can put them aside in a library file (that gets included into your main code.) this removes the clutter from the main code and all you have in front of you in your main code is the logic you are trying to create for the main code. to call a function with a different input value, all you need to do is supply that different value when you call the function. the code inside the function remains unchanged. your goal is to accept the $_GET['email'] value as an input to your program, retrieve the corresponding email2 value from your database table, and send an email using that email2 value. given that your original query was - $q="SELECT accountaddress from hm_accounts where accountaddress='".$email."'"; the only things you need to change are - 1) SELECT the emal2 column in the original query. 2) fetch the row the query returned, get the email2 value out of the fetched row, and use that email2 value in the correct places in the rest of the code.
  9. the code you have posted is not running the sql query statement at all, nor is it fetching and using the data from the query statement, so just exactly how did you expect your code to produce the expected output?
  10. you actually need to debug what your code is doing. find out why it is not taking the execution path you expect. what values do all of those variables have in them? also, here's some hints - 1) don't repeat yourself (DRY) and always try to use POSITIVE logic - if( empty($id) || empty($user) || empty( $pass ) || empty($uname) || empty($pos) || empty($divi) || empty($divhd)) { // your code for when this condition is true echo "<script>alert('Fill all the required fields!!')</script>"; } else { // your code for when this condition is false } 2) you should also form your sql query statement in a php variable so that you can echo/log it for debugging purposes. when you do this and echo the sql query statement, does it contain the expected values? 3) you ALWAYS need to have error checking logic in your programs to test if your query executed or not before trying to use the result from a query. in the case of your "You are Now Registered" message, you should only display that if the query ran without any errors and the row was actually inserted. 4) a person's userid is generally the autoincrement field in your database and you wouldn't have that as a from field or a value you put into the sql query statement.
  11. what second email address in the form? i only see one.
  12. @KaiSheng, there's nothing technically wrong with the if/else statement for the OP's connection code. you simply don't know all the possible php syntaxes and you keep knocking topics off track with your posts.
  13. the src=" ... " attribute is the URL where the browser fetches the image from on your server. it is not the file system path where the image is stored at on your server. the URL is relative to your document root/htdocs folder - ref: http://en.wikipedia.org/wiki/Uniform_Resource_Locator
  14. by using eval() you have opened yourself up to let hackers run their php code on your server. you must now validate that the $name variable (or any other value you put into the eval() statement) does not contain php code. does the rest of your code contain sufficient validation to insure someone isn't going to take over your web site? databases are for storing data, not code. if you want to store html makeup in your database, you need to use a template system where values have place-holders and the template essentially does a search/replace at runtime to put the values into the markup.
  15. @SpartanTacoDuckie, i recommend that you go back to your original code and find what is wrong in it and fix it. the most immediate problem with your original code that prevented it from working is your form's submit button does not have a name='submit' attribute and the if (isset($_POST['submit']) ) { statement in the php code was false.
  16. @KaiSheng, the point of programming help is to actually troubleshoot and help with problems in the OP's code. posting 'fixed' code that's no better then the OP's code doesn't help because there's no learning going on, just copy/pasting. you need to actually post things that help the OP find what the problem is in his code. the last code you posted above is a hack-up of calling database functions without first having a database connection, double-escaping data (and possibly triple if php's magic_quotes is on) mixing mysql_ and mysqli_ functions, having session_start() statements after outputting characters on the page, coding database connection information in multiple place, despite having an included file for that purpose.... and many more problems.
  17. your query statement contains a space character, both before and after the $gender value, so unless you actually have spaces stored in with your data, the query will never match anything. in a large amount of cases of a beginner using confrontation to build a string in php, they end up with errors due to the clutter. use the simplest, least mix of different contexts, to produce any statement - $query = "SELECT * FROM mytable WHERE Gender = '$gender'";
  18. you have far too much code and variables, making it difficult to see the forest for the trees, a lot of which isn't even used (and i don't mean the commented out debugging code.) you should write just the code and variables you need for any step. it would also help if you first define and write a general comment at the start of each step stating what the step is supposed to accomplish. the following (untested) is a first-pass simplification of your code, with the unneeded bits removed (the comments i put/left in the code are the general comments that help define what the code is doing) - // query for booster dates within the next 30 days $sql = "SELECT serviceID FROM service WHERE boosterDate BETWEEN CURDATE() AND CURDATE() + INTERVAL 30 DAY"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } while($row = $result->fetch_array()){ // update the email30 field for any matching rows (there might be previous/existing rows as well.) $sql = "UPDATE service SET email30 = 30 WHERE serviceID = {$row['serviceID']}"; if(!$con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } } // get all rows with email30 set (existing and new ones) $sql = "SELECT patientID, boosterDate FROM service WHERE email30 = 30"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } while($row = $result->fetch_array()){ list($patientID,$boosterDate) = $row; // get patient info $sql = "SELECT clientID, name FROM patientInformation WHERE patientID = $patientID}"; if(!$resultb = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } list($clientID,$name) = $resultb->fetch_array(); // get client info $sql = "SELECT firstName, lastName, email FROM clientInformation WHERE clientID = $clientID}"; if(!$resultb = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } list($firstName,$lastName,$email) = $resultb->fetch_array(); // $email, $firstName, $lastName - clientInformation // $name - patientInformation // $boosterDate - service $to = $email; $subject = "Just a friendly reminder from the Shot Spot"; $message = "Greetings $firstName $lastName\r\n\r\n\r\n" . "Thank you for choosing the Shot Spot for all of your animals healthcare needs. This is a friendly reminder that\r\n" . "$name is ready for their booster on $boosterDate\r\n\r\n\r\n" . "Thank you for choosing the Shot Spot"; $headers = 'From: info@txshotspot.com'; mail($to, $subject, $message, $headers); } next, a few advanced tips - 1) you don't need to select data and loop through it, in order to update it based on a condition. 2) each simple query you run takes far longer to communicate from php to the database server than what it takes to actually run on the database server, so you should avoid running queries in loops and running multiple queries that operate on related data. you need to learn to write JOIN'ed query statements (there's a ton of information in the mysql documentation and on the Internet) what your code (untested) could be simplified to look like - // update data within the next 30 days $sql = "UPDATE service SET email30 = 30 WHERE boosterDate BETWEEN CURDATE() AND CURDATE() + INTERVAL 30 DAY"; if(!$con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } // get all rows with email30 set (existing and new ones) $sql = "SELECT s.boosterDate, p.name, c.firstName, c.lastName, c.email FROM service s JOIN patientInformation p USING(patientID) JOIN clientInformation c USING(clientID) WHERE s.email30 = 30"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } while($row = $result->fetch_array()){ list($boosterDate, $name, $firstname, $lastName, $email) = $row; $to = $email; $subject = "Just a friendly reminder from the Shot Spot"; $message = "Greetings $firstName $lastName\r\n\r\n\r\n" . "Thank you for choosing the Shot Spot for all of your animals healthcare needs. This is a friendly reminder that\r\n" . "$name is ready for their booster on $boosterDate\r\n\r\n\r\n" . "Thank you for choosing the Shot Spot"; $headers = 'From: info@txshotspot.com'; mail($to, $subject, $message, $headers); }
  19. how is the variable $rp the same as the variable $_POST['rp']? this seems to be a copy/paste coding failure.
  20. your <select tag is missing the closing > so everything up to the first > is part of the <select tag.
  21. your most immediate problem is because php variables are not replaced with their value when used inside of a single-quoted string. you should use double-quotes for the initial and final quotes around sql query strings, with single-quotes around pieces of string data within it. however, for what you are doing, you need to learn how to write JOIN'ed queries and do this using one query. there's plenty of information to be found on the Internet.
  22. your imploded string of bad words contains some regex syntax, something like ?*, at the 2322'th character position. any characters that have meaning in regex syntax will need to be escaped with a \
  23. programming help forums are not here to find or to write code for you. they are for helping with code you have written. for your 2nd listed task, where exactly are you stuck at in doing this? without your attempted code that queries your database and what result or problem you had when you ran it, we don't have a clue what to help you with.
  24. the question actually is - what did you define for where you wanted the value to come from? programming is all about defining what you want, then writing the code that does it. there must be some reason that you ran the SELECT query and retrieved the $row['redeem_points'] value out of the redeemer table based on the submitted $_POST['redeem_code'] value, otherwise you wouldn't have went to the trouble of putting those lines of code in your program. i'm guessing it was so that if the $_POST['redeem_code'] value was found that you would add the corresponding $row['redeem_points'] to the correct row in the rewards table?
×
×
  • 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.