Question: Please provide the answer to PHP programming I sent my answer and I wrote somewhere that I have problem Please fix it) Create a php

Please provide the answer to PHP programming

I sent my answer and I wrote somewhere that I have problem Please fix it)

Create a php page with to display an html form using the post method and submitting to the same page

Include the following fields:

album id (text)

artist name (text)

album name (text)

price (text)

media type (radio buttons)

Value Label
1 MPEG audio file
2 Protected AAC audio file
3 Protected MPEG-4 video file
4 Purchased AAC audio file
5 AAC audio file

playlist (checkboxes- create at least 5 playlist names of your choice)

genre (drop down list)

Value Label
1 Rock
2 Jazz
3 Metal
4 Alternative and Punk
5 Jazz
6 Blues
7 Latin
8 Reggae
9 Pop
10 Soundtrack

tracks

submit

Check to see if the form has been submitted. If not, just display the form.

If the form has been submitted, validate the form as follows:

album id: required

artist: required

album name: required

price: required, numeric

media type: required

playlist: at least 1 required

genre: required

tracks: required, numeric, minimum 1, maximum 50.

If the data is valid, transfer to a second php page and pass the album id, artist name and album name

The second page should display the message: album-id album-name by artist added (i.e. BT101 Help! by The Beatles added).

If the data is not valid, redisplay the form with the user entered values and appropriate error messages.

I wrote the answer, but is not correct .my problems are:

( You did not add the validation for tracks to be numeric and between 1 and 50, -5 points. The mediatypes are not sticky because you need to put the word checked inside the tag (before the closing >) not as part of the text. -5 points. Same for the genre (drop down list), you need to put selected inside the option tag. -5 points. When the data is valid you should transfer to another page using header("Location:...) with the values in the querystring to display the album id, name and artist. -10 points. )

if (isset($_POST['submit'])) {

$valid = true;

$albumid = htmlspecialchars($_POST['albumid']);

if (empty($albumid)) {

echo "

Please enter your Album Id.

";

$valid = false;

}

$artistname = htmlspecialchars($_POST['artistname']);

if (empty($artistname)) {

echo "

Please enter your artist name.

";

$valid = false;

}

$albumname = htmlspecialchars($_POST['albumname']);

if (empty($albumname)) {

echo "

Please enter your album name

";

$valid = false;

}

$price = htmlspecialchars($_POST['price']);

if (!is_numeric($price)) {

echo "

Price must be numeric

";

$valid = false;

}

if (isset($_POST['mediatypes'])) {

$mediatypes = $_POST['mediatypes'];

} else {

echo "

Please select a Media type.

";

$valid = false;

$mediatypes[0]="";

}

$genre = $_POST['genre'];

if ($genre=="") {

echo "

Please select a genre.

";

$valid = false;

}

$tracks = $_POST['tracks'];

if (empty($tracks)) {

echo "

Please enter your tracks.

";

if(strlen($_POST['tracks'])< 1 )

echo "

$valid = false;

}

if ($valid) {

echo "

You entered the following information.

";

echo " Album id: $albumid";

echo " Artist name: $artistname";

echo " Album name: $albumname";

echo " Price: $price";

echo " Mediatype : $mediatypes[0]";

echo " genre: $genre";

echo " Tracks: $tracks";

}

if ($valid) {

header("Location: form.php?albumid=$albumid&artistname=$artistname&albumname=$$albumname&price=$price&mediatype=$mediatype&genre=$genre&tracks=$tracks");

exit();

}

} else {

$albumid="";

$artistname="";

$albumname="";

$price="";

$mediatypes[0]="";

$genre="";

$tracks="";

}

?>

value="">

value="">

value="">

value="">

foreach ($mediatypes as $mediatype){

if($mediatype == "MPGEaudiofile"){echo "checked";}

}

?>

foreach ($mediatypes as $mediatype){

if($mediatype == "ProtectedAACaudiofile"){echo "checked";}

}

?>

foreach ($mediatypes as $mediatype){

if($mediatype == "Protected MPEG-4 video file"){echo "checked";}

}

?>

foreach ($mediatypes as $mediatype){

if($mediatype == "PurchasedAACaudiofile"){echo "checked";}

}

?>

foreach ($mediatypes as $mediatype){

if($mediatype == "AACaudiofile"){echo "checked";}

}

?>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!