Dosti Movie
Dosti Movie
</form>
The "welcome.php" file can now use the $_POST function to collect form data (the names of the form
fields will automatically be the keys in the $_POST array):
ARRAY
Numeric Arrays
1. In the following example the index are automatically assigned (the index starts at 0):
$cars=array("Saab","Volvo","BMW","Toyota");
$cars[0]="Saab";
$cars[1]="Volvo";
$cars[2]="BMW";
$cars[3]="Toyota";
In the following example you access the variable values by referring to the array name and index:
<?php
$cars[0]="Saab";
$cars[1]="Volvo";
$cars[2]="BMW";
$cars[3]="Toyota";
echo $cars[0] . " and " . $cars[1] . " are Swedish cars.";
?>
Associative Arrays
Example 2
This example is the same as example 1, but shows a different way of creating the array:
$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";
<?php
$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";
?>
What is a Cookie?
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's
computer. Each time the same computer requests a page with a browser, it will send the cookie too.
With PHP, you can both create and retrieve cookie values.
Note: The setcookie() function must appear BEFORE the <html> tag.
Syntax
In the example below, we will create a cookie named "user" and assign the value "Alex Porter" to it.
We also specify that the cookie should expire after one hour:
<?php
?>
In the example below, we retrieve the value of the cookie named "user" and display it on a page:
<?php
// Print a cookie
echo $_COOKIE["user"];
print_r($_COOKIE);
?>
Before you can store user information in your PHP session, you must first start up the session.
Note: The session_start() function must appear BEFORE the <html> tag:
The correct way to store and retrieve session variables is to use the PHP $_SESSION variable:
<?php
session_start();
$_SESSION['views']=1;
?>
<html>
<body>
<?php
?>
Destroying a Session
If you wish to delete some session data, you can use the unset() or the session_destroy() function.
<?php
unset($_SESSION['views']);
?>
You can also completely destroy the session by calling the session_destroy() function:
<?php
session_destroy();
?>
Mysql Connect
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
?>
Mysql Insert
Now we will create an HTML form that can be used to add new records to the "Persons" table.
<html>
<body>
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
mysql_select_db("my_db", $con);
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
mysql_close($con)
?>
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
mysql_select_db("my_db", $con);
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysql_fetch_array($result))
echo "<tr>";
echo "</tr>";
echo "</table>";
mysql_close($con);
?>
Mysql Where
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
mysql_select_db("my_db", $con);
WHERE FirstName='Peter'");
while($row = mysql_fetch_array($result))
{
?>
Mysql update
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
mysql_select_db("my_db", $con);
mysql_close($con);
?>
Mysql Delete
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
mysql_select_db("my_db", $con);
mysql_close($con);
?>
Registration
<form action="register.php" method="post">
</form>
register.php
<?php
mysql_select_db("store") or die(mysql_error());
$username=$_POST[username];
$pass=$_POST[password];
or die(mysql_error());
Login
</form>
Login.php
<?php
mysql_select_db("store") or die(mysql_error());
$username=$_POST[username];
$pass=$_POST[pass];
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
session_start();
$_SESSION['logged'] = 1;
$_SESSION['username'] = $username;
header('Location: http://localhost/store/');
else {
?>