HomePHP Page 2 - Generating Contract Numbers for Online Licenses using PHP and MySQL
Inserting generated random numbers into a MySQL database - PHP
PHP and MySQL form a powerful combination of open source technology available to any web developer. One of the increasing trends in modern web development is the generation of online contracts. E-commerce websites selling services online need automated contract generation for faster delivery of services. This article will help you learn to use this technology so you can get it working on your web site.
Let’s go deeper and make an attempt to put the generated numbers into the MySQL database. To apply this to a realistic application, let’s write a PHP program that will allow us to enter names in the web form, and then have PHP assign a random number from 1 to 10 associated with that name, and then store the data in the MySQL database. In order to make this happen, we will create a database before we build the PHP script. To create a database using phpmyadmin, take the following steps:
Step 1: Log into phpmyadmin.
Step 2: Click the “database” link.
Step 3: In the create new database area, type: “randomnumber” (this is just an example; in your actual application you can select any name you like).
Step 4: Leave it set to “collation.”
Step 5: Now that we have a database named “randomnumber,” we will create a table. In the “Create new table on database randomnumber” area, let's type “randgenerated” (again, you can select any names you like).
Step 6: In the number of fields, type “2.” This is 2 because we will store two types of data; the first column will be the name and the second column will be the random number generated.
Step 6: In this stage, phpmyadmin will ask you to enter your desired field name and data types.
For illustration purposes we will use the field “name” and “random,” and then, using the default type varchar, we will use 30 characters for the name and two characters for the associated random number stored.
Leave everything else as it is, and then click save. MySQL will make a table using your defined variables. You can see the screen shot below; your table should be set up to look like that: