Question

8. Write a script that creates an associative or multidimensional array in PHP a. And displays that array in a table b. Create a form with at least two input fields and a Submit button. c. Write a scr...

8. Write a script that creates an associative or multidimensional array in PHP

a. And displays that array in a table

b. Create a form with at least two input fields and a Submit button.

c. Write a script that will validate that the user entered data in the input fields and that the fields are not blank when the Submit button is pressed

d. And returns the values entered in the input field when the Submit button is pressed.

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

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

This demonstration is using WAMP (Windows,Apache,MySQL And PHP).

Question a :

Here a new web page with name "multi.php" is created, which contains following code.

multi.php :

<!DOCTYPE html>

<html lang="en">

<head>

<!-- title for web page -->

<title>Multidimensional Array</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

<?php

//creating multidimensional array

$trainers=array

(

array("John","Microsoft stack","10 years"),

array("Sam","Database","8 years"),

array("VK","Java","5 years"),

array("SR","Javascript framwork","6 years"),

array("KL","Web Technology","15 years"),

);

?>

<table border=1>

<tr>

<th>Trainer Name</th>

<th>Technology Stack</th>

<th>Working Experience</th>

</tr>

<!-- this loop goes till number of rows -->

<?php for($i=0;$i<5;$i++) {?>

<tr>

<!-- this loop will goes till number columns -->

<?php for($j=0;$j<3;$j++) { ?>

<!-- display each value from the array -->

<td><?php echo $trainers[$i][$j]?></td>

<?php

}

?>

</tr>

<?php

}

?>

</table>

</body>

</html>

======================================================

Output : Open web page multi.php in the browser and will get the screen as shown below.

Screen 1 :multi.php

Multidimensional Array Cl localhost:8080/multi.php Trainer Name Technology Stack Working Experience John Sam VK SR. Microsoft

********************************

Question b ,c,d:

Here a new web page with name "PhpForm.php" is created, which contains following code.

PhpForm.php :

<!DOCTYPE html>

<html lang="en">

<head>

<!-- title for web page -->

<title>PHP Form Validation</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<!-- <body> -->

<!-- form with action and method attribute -->

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<!-- textbox for name -->

Name :<input type="text" name="txtName"/>

<br/><br/>

<!-- textbox for age -->

Age :<input type="text" name="txtAge"/>

<br/><br/>

<!-- button to submit form -->

<input type="Submit" name="btnSubmit"/>

</form>

<?php

if(isset($_POST["btnSubmit"]))

{

$name=$_POST["txtName"];//name

$age=$_POST["txtAge"];//age

//checking name and age

if($name=="")

{ //display message

echo "Please provide name<br/>";

}

else if($age=="")

{ //display message

echo "Please provide age<br/>";

}

else if($age<18)

{ //display message

echo "Please provide age > 18.<br/>";

}

else

{

//display name and age

echo "Name : ".$name."<br/>";

echo "Age : ".$age."<br/>";

}

}

?>

</body>

</html>

======================================================

Output : open web page in the browser and will get the screen as shown below

Screen 1 :PhpForm.php

PHP Form Validation ぐ → C ⓘlocalhost:8080/PhpForm.php Name Age Submit

Screen 2 :Screen when name is empty

PHP Form Validation ぐ -) C ⓘlocalhost:8080/PhpForm.php Name Age Submit Please provide name

Screen 3 :Screen when age is empty

PHP Form Validation Clocalhost:8080/PhpForm.php Name Age Submit Please provide age

Screen 4 :Screen when age is <18

PHP Form Validation ぐう C ⓘlocalhost:8080/PhpForm.php Name Age Submit Please provide age > 18.

Screen 5 :Screen showing name and age

PHP Form Validation C localhost:8080/PhpForm.php Name Age Submit Name : Virat Kohli Age: 23

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
8. Write a script that creates an associative or multidimensional array in PHP a. And displays that array in a table b. Create a form with at least two input fields and a Submit button. c. Write a scr...
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
  • 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...

  • Create a C# Form with a textbox and a button. The box is for a user...

    Create a C# Form with a textbox and a button. The box is for a user to enter a number of seconds. And when the user clicks the button, the program displays the equivalent number of hours, minutes and seconds using a MessageBox. Show method. If the seconds entered is less than 60, your program should only display the seconds; if the seconds is a least 60 and less than 3600, your program should display minutes and seconds; if the...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • Develop an HTML form that could be used to enter your book information (Books, Authors, and...

    Develop an HTML form that could be used to enter your book information (Books, Authors, and Publishers) start with the HTML/JavaScript template provided Expand upon it! What field information would you enter into a system? Have your form use more then just character text fields ... radio buttons, pick lists, and other elements make your form easier to use and you don't need to do lots of JavaScript checks. What fields would be mandatory ... which could be left blank?...

  • Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php...

    Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php script, create an associative array named $order that stores the following values: - the number of cheese toppings; - the number of pepperoni toppings; - the number of ham toppings; - the size of the ordered pizza; - the number of the ordered pizza; - the total cost of the order; - the discount rate; - the total cost after the discount. 2) the...

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

  • Form Processing HTML One of the most ubiquitous uses of JavaScript is validating form data on...

    Form Processing HTML One of the most ubiquitous uses of JavaScript is validating form data on the client side before it is submitted to the server. It is done everywhere because it is fast and it gives you a great deal of flexibility in how you handle errors insofar as the GUI is concerned. Attached is an image of some code I wrote (so Blackboard can't mess it up). Some things to notice that will help you with the lab....

  • Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in thr...

    Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the...

  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • MEDIA INHERITANCE - C++ You will create an inheritance set of classes. Use proper rules for...

    MEDIA INHERITANCE - C++ You will create an inheritance set of classes. Use proper rules for data types, class definitions, and inheritance (check input/output of data below). You will create a super media class that will define a general form of media. A media properties will consist of the name and price. The media should be able to construct itself out of the arguments sent to it, virtually print both data fields labeled (price to two decimal places) and overload...

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