Jump to content

Making a variable keep its value? ...maybe?


wright67uk

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.