Question

1.Write a PHP function that generates a random email. 2.Write a PHP function that generates a...

1.Write a PHP function that generates a random email.

2.Write a PHP function that generates a random password given the length as a parameter.

3. Run a query that will generate a database named lab4 b.

4.Run a query that will create a table named users, the table will only have three columns, email TEXT and password TEXT, ID INTEGER NOT NULL AUTO_INCREMENT. ID will be the primary key that will be generated for us automatically based on the record number in the table. You do not need to include ID in your INSERT statement in the following step.

5.Run a query, that will utilize a for loop to insert 100 random records into the database using the random email generator function and the random password generator function.

6.After the database, table, and 100 records have been successfully created, screenshot the structure of your table and run a query in PHPMyAdmin that shows the top 25 rows inserted (screenshot that too)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Table Creation

Create table GenerateRandom(id int Primary key NOT NULL AUTO_INCREMENT,email varchar(30),password varchar(30));

phpMyAdmin Server: 127.0.0.1 >> Database mydb>. Table: generaterandom Browse Structure SQL Search 3. Insert Export Import Pri

Coding

<!DOCTYPE html>
<html>
<head>
<title>Example of Class</title>
</head>
<body>
<?php
function generateEmailAddress($maxLenLocal=15,$maxLenDomain=5){
$numeric = '0123456789';
$alphabetic = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$extras = '.-_';
$all = $numeric . $alphabetic . $extras;
$Alpha = $alphabetic . $numeric;
$AlphaP = $alphabetic . $numeric . "-";
$StringRandom = '';
for ($i = 0; $i < 4; $i++) {
$StringRandom .= $alphabetic[rand(0, strlen($alphabetic) - 1)];
}
$rndNum= rand(20, $maxLenLocal-4);
for ($i = 0; $i < $rndNum; $i++) {
$StringRandom .= $all[rand(0, strlen($all) - 1)];
}
// ADD AN @ SYMBOL...
$StringRandom .= "@";
// GENERATE DOMAIN NAME - INITIAL 3 CHARS:
for ($i = 0; $i < 3; $i++) {
$StringRandom .= $alphabetic[rand(0, strlen($alphabetic) - 1)];
}
// GENERATE A NUMBER BETWEEN 15 & $maxLenDomain-7
$rndNum2 = rand(15, $maxLenDomain-7);
for ($i = 0; $i < $rndNum2; $i++) {
$StringRandom .= $all[rand(0, strlen($all) - 1)];
}
// ADD AN DOT . SYMBOL...
$StringRandom .= ".";
// GENERATE TLD: 4
for ($i = 0; $i < 4; $i++) {
$StringRandom .= $Alpha[rand(0, strlen($Alpha) - 1)];
}

return $StringRandom;
}
   function randomPassword()
   {
       $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
       $pass = array(); //remember to declare $pass as an array
       $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
       for ($i = 0; $i < 8; $i++) {
           $n = rand(0, $alphaLength);
           $pass[] = $alphabet[$n];
       }
return implode($pass); //turn the array into a string
   }
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDB";
/* Create table GenerateRandom(id int Primary key NOT NULL AUTO_INCREMENT,email varchar(30),password varchar(30)); */
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
for($i=0;$i<100;$i++)
{
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$email=generateEmailAddress();
$password=randomPassword();
$sql = "INSERT INTO GenerateRandom(email,password) VALUES ('$email','$password')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully<br>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();  

?>
</body>
</html>

Output

as we run program we can see here new 50 new record addeds New record created successfully New record created successfully NephpMyAdmin Server. 127.0.0.1 > Database mydb > Table generaterandom Browse Structure SQL Search i Insert Export Import Privil

if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........

Add a comment
Know the answer?
Add Answer to:
1.Write a PHP function that generates a random email. 2.Write a PHP function that generates a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow...

    How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow user to add his name and email to my database, all I need to print my final database when the user click on submit. <form action="" method="post"> <label>Name :</label> <input type="text" name="name" required="required" placeholder="Please Enter Name"/><br /><br /> <label>Email :</label> <input type="email" name="email" required="required" /><br/><br /> <input type="submit" value=" Submit " name="submit"/><br /> </form>...

  • Write a PHP script that obtains a URL and its description from user and stores the...

    Write a PHP script that obtains a URL and its description from user and stores the information into a database using MySQL. Create and run a SQL script with database named URL and a table named Urltable. The first field of the table should contain an actual URL, and the second, which is named Description, should contain a description of the URL. Use www.deitel.com as the first URL, and input Cool site! as its description. The second URL should be...

  • 1. Write the php statements to connect to MySQL server and select the database named personnel....

    1. Write the php statements to connect to MySQL server and select the database named personnel. The database personnel is located at localhost server. The user id and password to log on to the server are finalexam and thePassword respectively. 2. Using the above connection, write the php statements to retrieve the name and the email fields from all records of the users table ( 'SELECT name, email FROM users') and display them one record per line.

  • 1. Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database....

    1. Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database. Give INSERT and UPDATE permission to the new role for the Orders and OrderItems table. Give SELECT permission for all user tables. 2. Write a script that (1) creates a login ID named “RobertHalliday” with the password “HelloBob”; (2) sets the default database for the login to the MyGuitarShop database; (3) creates a user named “RobertHalliday” for the login; and (4) assigns the user...

  • PHP Programming In this project, you will create a Web page that allows visitors to your...

    PHP Programming In this project, you will create a Web page that allows visitors to your site to sign a guest book that is saved to a database. Create a new document in your text editor and type the <!DOCTYPE> declaration, <html> element, document head, and <body> element. Use the strict DTD and “Guest Book” as the content of the <title> element. Add the following text and elements to the document body: <h2>Enter your name to sign our guest book</h2>...

  • C++ 1) Write a random number generator that generates random integers from -10 to 10. 2)Write...

    C++ 1) Write a random number generator that generates random integers from -10 to 10. 2)Write a random number generator that generates random integers from 0 to 10. Also can you explain how does it work if possible. Thank you.

  • Write a Python function that generates a random password which meets the following conditions: • Length...

    Write a Python function that generates a random password which meets the following conditions: • Length = 10 • At least 2 capital letters, at least 2 small letters and at least 2 numbers. Example: ZlSyx0gDbX

  • This is a website picture The html and css code is as follow And my problem is as follow use the php and mysql Northwind Customer Database Search List Records All Records CustomerName v CustomerName...

    This is a website picture The html and css code is as follow And my problem is as follow use the php and mysql Northwind Customer Database Search List Records All Records CustomerName v CustomerName ContactName Address City PostalCode Search O ASC DESC List All Records Insert Record Country List City CustomerName ContactName Address City PostalCode Country List City Find by IID Find Insert 1 <! DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http:L 3-<head> 4 Kmeta http-equiv-"Content-Type" content-"text/html; charset-utf-8" />...

  • For this code below, I need to add the form information to mysql when I click...

    For this code below, I need to add the form information to mysql when I click on submit, at the same time when I click on submit I need to move to another page like Welcome.php WITH NOTE THAT THE ENTERED INFORMATION NOW ALREADY IN DATABASE how can I male that with my code below? THANKS ................................................................................................................................................   <form method="POST"> <div class="container">    <label for="fname"><b>First Name</b></label> <input type="text" placeholder="Enter First Name" name="fname" required> <label for="lname"><b>Last Name</b></label> <input type="text" placeholder="Enter Last Name"...

  • 1. Write an INSERT statement that adds this row to the Categories table: CategoryName: Brass Code...

    1. Write an INSERT statement that adds this row to the Categories table: CategoryName: Brass Code the INSERT statement so SQL Server automatically generates the value for the CategoryID column. 2. Write an UPDATE statement that modifies the row you just added to the Categories table. This statement should change the Category Name column to “Woodwinds”, and it should use the CategoryID column to identify the row. 3.Write an INSERT statement that adds this row to the Products table: ProductID:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT