Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/217899-unique-number-field-in-post-form/
Share on other sites

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

<?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

 

<?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 >

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

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

 

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

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.

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. ;)

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

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

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)

 

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.

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

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;
?>

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

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.