Here comes what you eagerly waiting for.
We gonna create a contact form...
and email you when someone is touch in your website..
Web Development
Thursday, January 12, 2017
DATABASE CONNECTION
Connecting To A Database: connecting.php !
<?php
$link = mysqli_connect("localhost", "username", "password", "database name");
if (mysqli_connect_error())
{
die("Could not connect to database");
}
?>
mysqli_connect is latest version. You can also use mysql_connect but is outdated now.
Here, I assumed that you know how to create database. Else contact me for this.
<?php
$link = mysqli_connect("localhost", "username", "password", "database name");
if (mysqli_connect_error())
{
die("Could not connect to database");
}
?>
mysqli_connect is latest version. You can also use mysql_connect but is outdated now.
Here, I assumed that you know how to create database. Else contact me for this.
GET and POST variables
GET Variables: getvariables.php !
<!doctype html>
<html>
<head>
<title>My First Webpage</title>!
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> !
</head> !
<body>
<div>
<?php
if ($_GET["submit"])
{
if ($_GET["name"])
{
echo "Your name is ".$_GET['name'];
}
else
{
echo "Please enter your name"; }
}
?>
<form>
<label for="name">Name</label>
<input name="name" type="text" />
<input type="submit" name="submit" value="Submit Your Name" />
</form>
</div>
</body>
</html>
POST VARIABLES
The major difference between POST and GET variable is that, if you use GET user entered value will be displayed in url but not in case of POST. I recommend you to use POST.
Coding is same.. Just repalce GET by POST.
<!doctype html>
<html>
<head>
<title>My First Webpage</title>!
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> !
</head> !
<body>
<div>
<?php
if ($_GET["submit"])
{
if ($_GET["name"])
{
echo "Your name is ".$_GET['name'];
}
else
{
echo "Please enter your name"; }
}
?>
<form>
<label for="name">Name</label>
<input name="name" type="text" />
<input type="submit" name="submit" value="Submit Your Name" />
</form>
</div>
</body>
</html>
POST VARIABLES
The major difference between POST and GET variable is that, if you use GET user entered value will be displayed in url but not in case of POST. I recommend you to use POST.
Coding is same.. Just repalce GET by POST.
sending email
Sending Email: sendingemail.php
<!doctype html>
<html>
<head>
<title>My First Webpage</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div>
<?php
$emailTo="";
$subject="I hope this works!";
$body="I think you're great";
$headers="From: evazs@gmail.com";
if (mail($emailTo, $subject, $body, $headers))
{
echo "Mail sent successfully!"
}
else
{
echo "Mail not sent!";
}
?>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>My First Webpage</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div>
<?php
$emailTo="";
$subject="I hope this works!";
$body="I think you're great";
$headers="From: evazs@gmail.com";
if (mail($emailTo, $subject, $body, $headers))
{
echo "Mail sent successfully!"
}
else
{
echo "Mail not sent!";
}
?>
</div>
</body>
</html>
For LOOP
For Loops with PHP: forloops.php !
<?php
$array=array("cat", "dog", "turtle", "kangaroo");
foreach ($array as $key => $value)
{
echo "Key: $key Value: $value <br />";
}
/*
for ($i=500; $i>=100; $i=$i-5)
{
echo $i."<br />";
}
*/
?>
<?php
$array=array("cat", "dog", "turtle", "kangaroo");
foreach ($array as $key => $value)
{
echo "Key: $key Value: $value <br />";
}
/*
for ($i=500; $i>=100; $i=$i-5)
{
echo $i."<br />";
}
*/
?>
Variables with PHP: variables.php !
<?php
$myArray=array("pizza", "chocolate", "coffee");
print_r($myArray);
echo $myArray[5];
echo "<br /><br />";
$anotherArray[0]="pizza";
$anotherArray[1]="yoghurt";
print_r($anotherArray);
echo "<br /><br />";
$thirdArray=array("France" => "French", "USA" => "English", "Germany" => "German" );
print_r($thirdArray);
$anotherArray[]="salad";
echo "<br /><br />";
print_r($anotherArray);
echo "<br /><br />";
unset($thirdArray["Germany"]);
print_r($thirdArray);
echo "<br /><br />";
$name="evazs";
unset($name);
echo $name;
?>
<?php
$myArray=array("pizza", "chocolate", "coffee");
print_r($myArray);
echo $myArray[5];
echo "<br /><br />";
$anotherArray[0]="pizza";
$anotherArray[1]="yoghurt";
print_r($anotherArray);
echo "<br /><br />";
$thirdArray=array("France" => "French", "USA" => "English", "Germany" => "German" );
print_r($thirdArray);
$anotherArray[]="salad";
echo "<br /><br />";
print_r($anotherArray);
echo "<br /><br />";
unset($thirdArray["Germany"]);
print_r($thirdArray);
echo "<br /><br />";
$name="evazs";
unset($name);
echo $name;
?>
what is php?
What is php??
You may have already studied about HTML, Bootstrap, CSS in my previous blogs.
They are client model i.e. we can run them in our browser by us easily.
PHP is a server model where the business logic happens. This includes sending emails
taking information from data-base, or posting a tweet which we cant do in CSS, HTML, JS.
You may have already studied about HTML, Bootstrap, CSS in my previous blogs.
They are client model i.e. we can run them in our browser by us easily.
PHP is a server model where the business logic happens. This includes sending emails
taking information from data-base, or posting a tweet which we cant do in CSS, HTML, JS.
PHP is a popular general-purpose scripting language that is especially suited to web development.
Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.
Subscribe to:
Posts (Atom)