Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
When you login into a website or into your mail box, you are interacting with a form.
Forms are used to get input from the user and submit it to the web server for processing.
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h2>Registration Form</h2>
</form>
</body>
</html>
Out put :-
This is the built in PHP super global array variable that is used to get values submitted
via HTTP POST method.
The array variable can be accessed from any script in the program; it has a global scope.
This method is ideal when you do not want to display the form post values in the URL.
A good example of using post method is when submitting login details to the server.
<?php
$_POST['variable_name'];
?>
This is the built in PHP super global array variable that is used to get values submitted
via HTTP GET method.
The array variable can be accessed from any script in the program; it has a global scope.
This method displays the form values in the URL.
It’s ideal for search engine forms as it allows the users to book mark the results.
<?php
$_GET['variable_name'];
?>
.
POST.PHP
html>
<body>
</body>
</html>
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h2>Registration Form</h2>
</form>
</body>
</html>
Out put :-
GET.PHP
<html>
<body>
</body>
</html>
Write a PHP program for Connecting database, inserting and accessing data
from a database.?
<?php
// Create connection
$conn = mysql_connect(“localhost:3306”,”root”,” “);
// Check connection
if (!$conn) {
die("Connection failed: " . mysql_error());
}
// sql to create database
if(mysql_query(“create database:mydb”,$Conn)
{
Echo “Database is Created”;
}
else
{
Echo “Database not created”.mysql_error());
}
// sql to create table
$sql = "CREATE TABLE Persons (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
email VARCHAR(50),
)";
if (mysql_query($conn, $sql)) {
echo "Table Persons created successfully";
} else {
echo "Error creating table: " . mysql_error($conn);
}
// sql to inserting data
$sql = "INSERT INTO Persons (name, email)
VALUES ('503', 'Ranjith', 'rk@gmail.com')";
if (mysql_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysql_error($conn);
}
// sql to accessing data
if (mysql_num_rows($result) > 0) {
// output data of each row
while($row = mysql_fetch_assoc($result)) {
echo "Id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["email"]. "<br>";
}
} else {
echo "0 results";
}
mysql_close($conn);
?>