wright67uk Posted February 22, 2011 Share Posted February 22, 2011 Good evening, Im using GenRandomString, and wondered how I can get $confirm to keep its first value throughout my script. I have put comments on the lines that use $confirm. Do I need to change $confirm to a constant and how can I go about this? $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; $companyname = $_GET['companyname']; $doornumber = $_GET ['doornumber']; $street = $_GET ['street']; $town = $_GET['town']; $postcode = $_GET['postcode']; $useremail = $_GET ['usermail']; $telephone = $_GET['telephone']; $shortcode = substr($postcode,0,2); function genRandomString() { $length = 10; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = ""; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))];} return $string;} $confirm = genRandomString(); //creating a random number $query =mysql_query ("INSERT INTO treesurgeons (firstname, lastname, companyname, doornumber, street, town, postcode, useremail, telephone, Id) VALUES ('$firstname', '$lastname', '$companyname','$doornumber', '$street', '$town', '$postcode', '$useremail', '$telephone', '$confirm')");//1st Value echo mysql_error(); echo "<p>Thankyou for submiting your details.\r\n Please check your inbox and click on your confirmation link.</p>"; $message = "The following details have been submited to the tree directory and are awaiting confirmation; \r\n Please click on the link below to confirm these details are correct\r\n '$firstname', '$lastname', '$companyname','$doornumber', '$street', '$town', '$postcode', '$usermail', '$telephone' <a href='http://www.mywebsite.co.uk/confirmed.php?Id=$confirm'>"; //2nd Value $subject = "Your tree directory details"; $to = "$useremail"; $email = "$emailad"; mail( "$to", "$subject","$message", "$headers"); ?></body></html> I havent really played around with constants before, so please an advice appreciated! Im guessing im using DEFINE but im unsure how I would combine this with GenRandomString in my code. Link to comment https://forums.phpfreaks.com/topic/228531-making-a-variable-keep-its-value-maybe/ Share on other sites More sharing options...
kenrbnsn Posted February 22, 2011 Share Posted February 22, 2011 Once you assign a value to a variable, it doesn't change unless you assign another value to the same variable. The value of the variable isn't being changed between those two statements. Are you seeing something different? Ken Link to comment https://forums.phpfreaks.com/topic/228531-making-a-variable-keep-its-value-maybe/#findComment-1178353 Share on other sites More sharing options...
wright67uk Posted February 22, 2011 Author Share Posted February 22, 2011 Yes, the number being stored in mysql database //1st value is different to the number appearing in my <a href ... //2nd value I can see that this is probably because $confirm = genRandomString(); causes a new random number to be assigned each time I use $confirm. However Im unsure as what to do about it. Link to comment https://forums.phpfreaks.com/topic/228531-making-a-variable-keep-its-value-maybe/#findComment-1178354 Share on other sites More sharing options...
AbraCadaver Posted February 22, 2011 Share Posted February 22, 2011 Yes, the number being stored in mysql database //1st value is different to the number appearing in my <a href ... //2nd value I can see that this is probably because $confirm = genRandomString(); causes a new random number to be assigned each time I use $confirm. However Im unsure as what to do about it. With the code you posted, that's not possible. Link to comment https://forums.phpfreaks.com/topic/228531-making-a-variable-keep-its-value-maybe/#findComment-1178355 Share on other sites More sharing options...
AbraCadaver Posted February 22, 2011 Share Posted February 22, 2011 Yes, the number being stored in mysql database //1st value is different to the number appearing in my <a href ... //2nd value I can see that this is probably because $confirm = genRandomString(); causes a new random number to be assigned each time I use $confirm. However Im unsure as what to do about it. With the code you posted, that's not possible. I take that back, depending on the field type of confirm in the DB. Link to comment https://forums.phpfreaks.com/topic/228531-making-a-variable-keep-its-value-maybe/#findComment-1178356 Share on other sites More sharing options...
wright67uk Posted February 22, 2011 Author Share Posted February 22, 2011 Huge apologies, after a long delay Ive just recieved another email with the correct code, sorry guys. Link to comment https://forums.phpfreaks.com/topic/228531-making-a-variable-keep-its-value-maybe/#findComment-1178359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.