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
https://forums.phpfreaks.com/topic/228531-making-a-variable-keep-its-value-maybe/
Share on other sites

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

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

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