CS345 Assignment Unit2 Aditya Mishra
CS345 Assignment Unit2 Aditya Mishra
Submission
Assessment Group/ Deadline
Assignment ID Assignment Submission Method- Individual- Weightage- Date of (Date and
-02 Title-Unit 2 Mode-Online Online Individual 02 Release time)
Instructions:
Problems:
1. Write a JavaScript program where the program takes a random integer between 1
to 10, the user is then prompted to input a guess number. If the user input matches
with guess number, the program will display a message "Good Work" otherwise
display a message "Not matched"
2. How to retrieve a value from textbox in PHP on click event of button?
3. Differentiate between $_GET and $_POST methods in PHP.
Solutions –
Q1) The javascript code, using the random() method, is given below –
<p id="random"></p>
<script>
function check() {
}
</script>
1) $_POST
$_POST is a php super global variable which is used to collect form data after
submitting an HTML form with method=”post”.
$_POST is widely used to pass variables.
Syntax:
<?php
$_POST[‘variable_name’];
?>
2) $_GET
$_GET is a php super global variable which is used to collect form data after submitting
an HTML form with method=”get”.
Syntax example -
<?php
$name=$_GET[“name”];
echo“Welcome, $name”;
?>
GET POST
GET Parameters are included in URL POST parameters are included in the body
GET requests are often used for fetching
POST parameters are often used for
documents and GET parameters are used to
updating data for actually making changes
describe which document we are looking for
to the server (or) to the data held on the
(or) what page we are on (or) things of that
server
nature.
Because they are in URL, have a maximum By default, they don’t have any maximum
URL length because you can encode many length. Now the Server can be configured
parameters. For eg: Internet Explorer allows and most are to have a maximum length but
Assignment
2000 characters in the URL or something it is usually substantially longer than 2000
like that which can be quite limiting. characters.
When we make a GET request- a simple
Post parameters are almost never cached
request for URL. There are a lot of
because you are probably updating data on
machines between you and server It saves a
the server so the industry standard is: Don’t
lot of effort if we know the document has
cache POST request
not changed
They should not change the server. You Post requests are okay to change the server.
should be able to make the same GET That is what they are generally used for
request over and the server should not requesting an update for the server and are
change. not cached and there is no maximum length