Question

<html> <!--This is the form for an instructor to upload a file having the grade of...

<html>
<!--This is the form for an instructor to upload a file having the grade of students in a class-->
<body>
<h2>Upload Student Grade</h2>
<form action="1.php" method="POST" enctype="multipart/form-data">
   Instructor's First Name:<input type="text" name="first"><br><br>
   Instructor's Last Name: <input type="text" name="last"><br><br>  
   Instructor's Department Name:<input type="text" name="department"><br><br>         
Upload student grade: <input type="file" name="image" /><br><br>
<input type="submit"/>
</form>
  
</body>
</html>

//***************************************************Q1****************************************************************************     
/*(((( Q1)))). (18 points) Add the code below that
*   uploads the file containing the students' grade to a subfolder which is
*   named grades. The uploaded file is named: "grade_info.txt"
*   The operations include:
*   (1) collect the information of the uploaded file,
* (2) check and ensure that the extension and size of the uploaded file can be accepted,and
*   (3) upload the file.
*   
*/
  
  
  
  
  
  
  
  
  
  
  
//**************************************************End of Q1*****************************************************************************  
//call funB() that will read the content of the file uploaded in this functions
   funB("grades/".$file_name);
}   
}


function funB($filename)
{

$file = fopen($filename, "r");
//***********************************************Q2********************************************************************************
/* ((( Q2.)))) (16 points) Add the code below that
*       read the content of the file uploaded in funA() and then
*        save it to a string named $filetext. The operations include:
*       (1) check and see if the file can open correctly,
*       (2) get the size of the file, and
*       (3) read the file and save the content of the file to a variable named $filetext
*/

  
  
//*********************************************End of Q2**********************************************************************************     
   fclose( $file );  
//convert the string to an array  
   $address = explode(",", $filetext);
//call funC() to store each element of the array $address to the database
   funC($address);
}
function funC($address)
{
$dbname="csc395_4";
   $tbname="employee";
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = '';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

   $first = $_POST["first"];
   $last = $_POST["last"];
   $department = $_POST["department"];
  
if(!$conn)
   {
print "Could not connect: " . mysqli_error();
}
//*******************************************Q3************************************************************************************  
/* (( Q3)). (16 points) Add the code below that
*        save the value of each element of the array $address to the database. The operations
*       include:
*       (1) use a loop to create queries and run the queries.
*/  
  
  
  
  
  
  
  
//******************************************End of Q3*************************************************************************************
//store the information collected from the form into the table named instructor  
   $sql = "insert into instructor(first_name, last_name, department, date_entered)
   values(\"".$first."\",\"".$last."\",\"".$department."\",NOW());";
  
   $retval = mysqli_query($conn, $sql);
  
   print("<p>The grade has been inserted into the database. <br>
   <a href=\"2.php\">click here</a> to find the grade<p>");  
}  
?>


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

If you have any doubts, please give me comment...

<html>

<!--This is the form for an instructor to upload a file having the grade of students in a class-->

<body>

<h2>Upload Student Grade</h2>

<form action="1.php" method="POST" enctype="multipart/form-data">

Instructor's First Name:<input type="text" name="first"><br><br>

Instructor's Last Name: <input type="text" name="last"><br><br>

Instructor's Department Name:<input type="text" name="department"><br><br>

Upload student grade: <input type="file" name="image" /><br><br>

<input type="submit"/>

</form>

</body>

</html>

<?php

//***************************************************Q1****************************************************************************

/*(((( Q1)))). (18 points) Add the code below that

* uploads the file containing the students' grade to a subfolder which is

* named grades. The uploaded file is named: "grade_info.txt"

* The operations include:

* (1) collect the information of the uploaded file,

* (2) check and ensure that the extension and size of the uploaded file can be accepted,and

* (3) upload the file.

*

*/

funcA();

function funA(){

if(isset($_FILES['image'])){

$grades_file = $_FILES['image'];

$ext = end(explode(".", $grades_file));

$filename = "grade_info.txt";

if($ext != "txt"){

echo "Invalid filetype<br />";

return;

}

move_uploaded_file($grades_file['tmp_name'], "./grades/".$filename);

echo "Successfully file uploaded<br />";

//**************************************************End of Q1*****************************************************************************

//call funB() that will read the content of the file uploaded in this functions

funcB("grades/".$filename);

}

}

function funB($filename)

{

$file = fopen($filename, "r");

//***********************************************Q2********************************************************************************

/* ((( Q2.)))) (16 points) Add the code below that

* read the content of the file uploaded in funA() and then

* save it to a string named $filetext. The operations include:

* (1) check and see if the file can open correctly,

* (2) get the size of the file, and

* (3) read the file and save the content of the file to a variable named $filetext

*/

if(!$file)

return;

$filesize = filesize($filename);

$filetext = fgets($file);

//*********************************************End of Q2**********************************************************************************

fclose( $file );

//convert the string to an array

$address = explode(",", $filetext);

//call funC() to store each element of the array $address to the database

funC($address);

}

function funC($address)

{

$dbname="csc395_4";

$tbname="employee";

$dbhost = 'localhost:3306';

$dbuser = 'root';

$dbpass = '';

$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

$first = $_POST["first"];

$last = $_POST["last"];

$department = $_POST["department"];

if(!$conn)

{

print "Could not connect: " . mysqli_error();

}

//*******************************************Q3************************************************************************************

/* (( Q3)). (16 points) Add the code below that

* save the value of each element of the array $address to the database. The operations

* include:

* (1) use a loop to create queries and run the queries.

*/

foreach($address as $addr){

mysqli_query($conn, "INSERT INTO address VALUES('.$addr.')");

}

//******************************************End of Q3*************************************************************************************

//store the information collected from the form into the table named instructor

$sql = "insert into instructor(first_name, last_name, department, date_entered)

values(\"".$first."\",\"".$last."\",\"".$department."\",NOW());";

$retval = mysqli_query($conn, $sql);

print("<p>The grade has been inserted into the database. <br>

<a href=\"2.php\">click here</a> to find the grade<p>");

}

?>

Add a comment
Know the answer?
Add Answer to:
<html> <!--This is the form for an instructor to upload a file having the grade of...
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>...

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

  • Using form events functions to answer this question. Use the attached form html file which contains...

    Using form events functions to answer this question. Use the attached form html file which contains 2 html radio buttons. When the first choice is chosen, display the text ”First” under the first choice. When the second choice is chosen, display the text ”Second” under the second choice. Instead of using JavaScript complete this question using JQuery <!DOCTYPE html> <html> <head>     <title>midterm exam</title>     <link rel="stylesheet" href="css/q1.css" /> </head> <body>     <div id = "page">        <form>   ...

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

  • I am having an issue. When i press submit to test the code, it goes to...

    I am having an issue. When i press submit to test the code, it goes to a blank screen. Please, will some one assist me? Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sign Guest Book</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php if (empty($_POST['?rst_name']) || empty($_POST['last_name']))     echo "<p>You must enter your ?rst and last name! Click your browser's Back button to return to the Guest Book form.</p>"; else {     $DBConnect = @mysql_connect("localhost", "root", "");    ...

  • <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 8 Hands-on Project 8-1 Author: Date:   ...

    <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 8 Hands-on Project 8-1 Author: Date:    Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>Hands-on Project 8-1</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.65897.js"></script> </head> <body> <header> <h1> Hands-on Project 8-1 </h1> </header> <article> <h2>New Account Information</h2> <form> <fieldset id="deliveryinfo"> <label for="fnameinput">First Name</label> <input type="text" id="fnameinput" name="fname" /> <label for="lnameinput">Last Name</label> <input type="text" id="lnameinput" name="lname" /> <label for="addrinput">Street Address</label> <input type="text" id="addrinput" name="address" /> <label for="cityinput">City</label> <input type="text" id="cityinput" name="city"...

  • I need help please to add function for clean up any inputs form that we receive from the users for this code below : &lt...

    I need help please to add function for clean up any inputs form that we receive from the users for this code below : <?php session_start(); // initializing variables $fname = ""; $lname = ""; $address = ""; $city = ""; $state = ""; $zip = ""; $email = ""; $phone = ""; $errors = array(); // connect to the database $db = mysqli_connect("localhost","root","password","db"); // REGISTER USER if (isset($_POST['reg_user1'])) { // receive all input values from the form $fname =...

  • In this assignment you will combine HTML, PHP, and SQL in order to create a web...

    In this assignment you will combine HTML, PHP, and SQL in order to create a web form that allows a manager to add films to the sakila database. You will also create a method to allow the manager to view a list of all films along with their related information, and a list of actors in the movies. Task 1 Create an initial HTML page titled manager.html with 2 buttons. The first button will be labeled “View Films”, and the...

  • the is my HTML and CSS code. I didn't attach the image or the CSS file...

    the is my HTML and CSS code. I didn't attach the image or the CSS file because of the space limit. two things I wanted to incorporate on this page are to make "MY TOP 3 MUSIC GENRES" blink using javascript and to make the video links autoplay using javascript both should be using javascript requirement: our professor told us not to use <div> or alert. thank you for your help <!DOCTYPE html> <!-- I used w3school for the formatting...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

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