zzdave Posted November 6, 2010 Share Posted November 6, 2010 Hi, Newbie! I need to generate a unique number and put it in a field called "intInstD" value ="123456" to send to Paypoint to initiate an order. They insist each order from my website has a unique number. Can anyone help with a bit of code that does this please? Much appreciated zzdave Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/ Share on other sites More sharing options...
Pikachu2000 Posted November 6, 2010 Share Posted November 6, 2010 Hopefully, you'll be storing some sort of related information in a database, so why not send them the PK ID from the DB record? Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1130907 Share on other sites More sharing options...
zzdave Posted November 6, 2010 Author Share Posted November 6, 2010 Er... wasn't expecting to use a database, just wanted to generate a unique number to send to PayPoint, they check the credit card and send me an email with users address so that I can send the product. I don't particularly want to use a database to store stuff. Is this possible? Cheers Dave Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1130910 Share on other sites More sharing options...
Rifts Posted November 6, 2010 Share Posted November 6, 2010 <?php srand ((double) microtime( )*1000000); $random_number = rand( ); echo "$random_number"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131103 Share on other sites More sharing options...
zzdave Posted November 6, 2010 Author Share Posted November 6, 2010 <?php srand ((double) microtime( )*1000000); $random_number = rand( ); echo "$random_number"; ?> <form action = "https://secure.metacharge.com/mcpe/purser" method = "post"> <input type = "hidden" name = "intTestMode" value = "1"> <input type = "hidden" name = "intInstID" value = "123456"> <input type = "hidden" name = "strCartID" value = "YourOrderId/userId/987654321"> <input type = "hidden" name = "fltAmount" value = "29.99"> <input type = "hidden" name = "strCurrency" value = "GBP"> <input type = "hidden" name = "strDesc" value = "description of purchase"> <input type = "submit" value = "Make Payment"> </form > This is the form given me by Paypoint. I have to make sure that the "intInstID" field is filled with this number. Do I just paste the code where it says "123456"? Cheers Dave Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131119 Share on other sites More sharing options...
Rifts Posted November 6, 2010 Share Posted November 6, 2010 <?php srand ((double) microtime( )*1000000); $random_number = rand( ); ?> <form action = "https://secure.metacharge.com/mcpe/purser" method = "post"> <input type = "hidden" name = "intTestMode" value = "1"> <input type = "hidden" name = "intInstID" value = "<?= $random_number; ?>"> <input type = "hidden" name = "strCartID" value = "YourOrderId/userId/987654321"> <input type = "hidden" name = "fltAmount" value = "29.99"> <input type = "hidden" name = "strCurrency" value = "GBP"> <input type = "hidden" name = "strDesc" value = "description of purchase"> <input type = "submit" value = "Make Payment"> </form > Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131160 Share on other sites More sharing options...
zzdave Posted November 6, 2010 Author Share Posted November 6, 2010 Sorry still not quite working I paste this in before the form action : <?php srand ((double) microtime( )*1000000); $random_number = rand( ); ?> then <form action etc I paste this where the 123456 was: "<?= $random_number; ?>"> The actual code appears in the field, not the number Thanks for your help - nearly there Cheers Dave Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131174 Share on other sites More sharing options...
zzdave Posted November 6, 2010 Author Share Posted November 6, 2010 So my code now looks like this: <?php srand ((double) microtime( )*1000000); $random_number = rand( ); ?> <form action = "https://secure.metacharge.com/mcpe/purser" method = "post"> <input type = "hidden" name = "intTestMode" value = "1"> <input type = name = "intInstID" value = "<?= $random_number; ?>"> <input type = "hidden" name = "strCartID" value = "YourOrderId/userId987654321"> <input type = "hidden" name = "fltAmount" value = "29.99"> <input type = "hidden" name = "strCurrency" value = "GBP"> <input type = "hidden" name = "strDesc" value = "description of purchase"> <input type = "submit" value = "Make Payment"> </form> I removed the "hidden" bit from the appropriate line so I can check it Dave Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131184 Share on other sites More sharing options...
Yucky Posted November 6, 2010 Share Posted November 6, 2010 Perhaps short tags aren't enabled. Try <?php echo $random_number; ?> instead of <?=$random_number;?>. Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131187 Share on other sites More sharing options...
zzdave Posted November 6, 2010 Author Share Posted November 6, 2010 Hi, Still shows code in the box: <?php srand ((double) microtime( )*1000000); $random_number = rand( ); ?> <form action = "https://secure.metacharge.com/mcpe/purser" method = "post"> <input type = "hidden" name = "intTestMode" value = "1"> <input type = name = "intInstID" value = "<?php echo $random_number; ?>"> <input type = "hidden" name = "strCartID" value = "YourOrderId/userId/987654321"> <input type = "hidden" name = "fltAmount" value = "39.99"> <input type = "hidden" name = "strCurrency" value = "GBP"> <input type = "hidden" name = "strDesc" value = "description of purchase"> <input type = "submit" value = "Make Payment"> </form> Cheers Dave Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131200 Share on other sites More sharing options...
BlueSkyIS Posted November 7, 2010 Share Posted November 7, 2010 you should not put spaces between key/values in html tags. and any key that is set must have a quoted value. this way should work: <input type="text" name="intInstID" value="<?php echo $random_number; ?>" /> if not, remove the rest of the spaces before and after the equal signs in your input tags. Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131233 Share on other sites More sharing options...
Yucky Posted November 7, 2010 Share Posted November 7, 2010 I guess he's trying to say that all of the PHP code is displaying in his browser. I did consider that it wasn't being parsed at all but I concluded that he meant that only the code in the text field was being displayed. Make sure the document extension is .php and not .html or some variant. If that fails to work, make sure you actually have a working PHP installation on your server. Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131241 Share on other sites More sharing options...
zzdave Posted November 7, 2010 Author Share Posted November 7, 2010 Hi, I am using a package called Serif WebPlus. This has an option to preview pages in a browser. When I do this, its only this code appears in the text box: <?php echo $random_number; ?> My full code(cut and pasted from my browser) now reads as follows: <!-- Header Code --> <!--Header code for HTML frag_5 --> <!-- Body Code --> <!-- HTML frag_5 --> <!--Preamble--> <div style="position:absolute; left:127px; top:295px; width:855px; height:489px; /*MainDivStyle*/" __AddCode="here"> <!--MainDivStart--> <div id="frag_5" style="text-align:left; /*Tag Style*/" __AddCode="here"> <?php srand ((double) microtime()*1000000); $random_number = rand(); ?> <form action = "https://secure.metacharge.com/mcpe/purser" method = "post"> <input type = "hidden" name = "intTestMode" value = "1"> <input type="text" name="intInstID" value="<?php echo $random_number; ?>" /> <input type = "hidden" name = "strCartID" value = "YourOrderId/userId/987654321"> <input type = "hidden" name = "fltAmount" value = "39.99"> <input type = "hidden" name = "strCurrency" value = "GBP"> <input type = "hidden" name = "strDesc" value = "description of purchase"> <input type = "submit" value = "Make Payment"> </form> </div></div> <!--Postamble--> Thanks to everyone for your help and I hope this problem can be soleved Dave Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131361 Share on other sites More sharing options...
Yucky Posted November 7, 2010 Share Posted November 7, 2010 You have to run the script on a proper server that supports PHP. You can't just preview PHP scripts in your browser. Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131406 Share on other sites More sharing options...
zzdave Posted November 7, 2010 Author Share Posted November 7, 2010 I have uploaded the website to my server and the code still appears in the box. http://chiswickrestaurants.com/page9.html I imagine that my web host does not support php. I will call them on Monday to confirm this and then follow up here to let you know. Thanks for you help, it's been great. Dave Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131528 Share on other sites More sharing options...
Yucky Posted November 8, 2010 Share Posted November 8, 2010 I said earlier that the file should be .php, not .html. Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131571 Share on other sites More sharing options...
fortnox007 Posted November 8, 2010 Share Posted November 8, 2010 Dave, IF it needs to be really unique i would recommend using either a database or a textfile where you store the numbers as a Unique_id. What your doing now is indeed creating random numbers, But that also means it's not unique (random != unique). It could very well happen that the same number pops up. IF you still dont want to use a database, atleast salt it with the name of the company or client (maybe translated into binary if it has to be numbers) using it, the likelyness that you get the same number with the methds above is around 0.(no longer valid since its for invoices) Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131572 Share on other sites More sharing options...
fortnox007 Posted November 8, 2010 Share Posted November 8, 2010 Oh I just saw its for a restaurant. I bet this number is for the VAT. The owner should know the number must be incrementing!! doesnt matter what your starting point is. IF its 100001 or 1000890 the next should be 1000891 Keep that in mind and Use a database for the sake of simplicity and LAW (which in my country orders you to store the crap for 7 years and have incrementing invoices.) -edit Just make a simple table in data and name a field and integer give it a unique incrementing value and primary key. you dont have to do anything special. Everytime you insert a new row it automatically increases the id. Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131575 Share on other sites More sharing options...
zzdave Posted November 8, 2010 Author Share Posted November 8, 2010 Hi This number is not for VAT. It is supposed to be a unique order number for the benefit of Paypoint. I have found a solution using javascript: <html> <head> </head> <body> <form> <input type="text" name="MyField" /> </form> <script langueage="javascript" type="text/javascript"> var d = new Date(); var tm = d.getTime(); document.getElementsByName('MyField')[0].value=tm; </script> </body> </html> My only problem now is to limit the number to only 6 digits. I realise this is a PHP forum so I apologise for this posting in advance. I called the hosting company earlier and they tell me their server does indeed use php so I am at a loss to understand why the earlier php script does not work. I really appreciate the assistance you guys have given me and I am learning a lot. Any further help you can offer would be great Thank you David Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131743 Share on other sites More sharing options...
fortnox007 Posted November 8, 2010 Share Posted November 8, 2010 Well just keep in mind random is not unique how unlikely a match may sound. (a date+time is unique depending on how many requests per time unit) Maybe make a little hello world php script to test if there is any php. just call it helloworld and place the following. <?php //don't us short tag like <? $string = 'hello world!'; //assign a variable; echo $string; ?> Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131786 Share on other sites More sharing options...
ninedoors Posted November 8, 2010 Share Posted November 8, 2010 I have found a solution using javascript: What happens when you have a user who has javascript disabled? Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131791 Share on other sites More sharing options...
fortnox007 Posted November 8, 2010 Share Posted November 8, 2010 well what if someone does have it enabled... check your spelling: <script langueage="javascript" type="text/javascript"> it's language not langueage use php its not client dependent Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131796 Share on other sites More sharing options...
zzdave Posted November 8, 2010 Author Share Posted November 8, 2010 Hi, Disabled javascript !!! I hadn't thought of that - bummer. Even if they do have it enabled "check your spelling" - thanks for the heads up. I am only expecting around 5 to 10 sales a day so I reckon random is good enough, unless someone can supply code that makes it truly unique. OK - so I decide to use PHP as its not client dependant and my server is PHP enabled. The bit of code still doesn't work - here it is again: <?php srand ((double) microtime( )*1000000); $random_number = rand( ); ?> <form action = "https://secure.metacharge.com/mcpe/purser" method = "post"> <input type = "hidden" name = "intTestMode" value = "1"> <input type = "hidden" name = "intInstID" value = "<?= $random_number; ?>"> <input type = "hidden" name = "strCartID" value = "YourOrderId/userId/987654321"> <input type = "hidden" name = "fltAmount" value = "29.99"> <input type = "hidden" name = "strCurrency" value = "GBP"> <input type = "hidden" name = "strDesc" value = "description of purchase"> <input type = "submit" value = "Make Payment"> </form > What's wrong with this - why doesn't it work and can I limit it to 6 digits? Thanks Dave Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131844 Share on other sites More sharing options...
Yucky Posted November 8, 2010 Share Posted November 8, 2010 In what way doesn't it work? Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131895 Share on other sites More sharing options...
zzdave Posted November 8, 2010 Author Share Posted November 8, 2010 Hi This appears in the field: <?= $random_number; ?> not the expected generated number. In addition I only need 6 numbers in the box when it works Thanks Dae Quote Link to comment https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/#findComment-1131905 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.