CMS Layer: Most Powerful PHP CMS Using CodeIgniter

CMS Layer The Most Developer Friendly CMS PHP and ASP

CMS Layer

CMS Layer The Most Developer Friendly CMS

The most flexible platform & programmer-friendly content management system (CMS Layer) all around the world! Build using powerful PHP framework CodeIgniter.

CMS Layer has built-in 100% Optimize SEO Comparable.

CMS Layer Plugin and Extensions are Page, Post, Product, Service, Portfolio, Forum, Package, Video, Slideshow, Classified, Download, Listing, Advertisement, Communities, Payment Gateway, ADP Template and AMP Theme.

Using PHP Create Payment System with BrainTree PayPal

Are you working for e-commerce project? Then you should have a better and secure payment system. I suggest you setup you project with BrainTree API, it is very powerful and quick. This is accepting most commonly used Cards, PayPal, Android Pay and etc. This post will explain you how to design a cart and order system with BrainTree payment process using PHP and MySQL.

brainTree PHP and ASP

Take a quick look the live demo and try demo transaction.

Database Design:

To build the eCommerce system, you have to create four basic tables such as Users, Producs, Orders and Cart.

User Table:
User table contains all the users registration details.

CREATE TABLE Users(
user_id INT  PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50),
password VARCHAR(100),
email VARCHAR(100)
);

users PHP and ASP

Products Table:
This contains all of the product details.

CREATE TABLE Products(
product_id INT PRIMARY KEY AUTO_INCREMENT,
product_name VARCHAR(200),
product_desc TEXT,
price FLOAT
);

products PHP and ASP

Orders Table:
User successful orders store here with BrainTree status code.

CREATE TABLE Orders(
order_id INT PRIMARY KEY AUTO_INCREMENT,
user_id_fk INT,
created INT,
price FLOAT,
FOREIGN KEY(user_id_fk) REFERENCES Users(user_id)
);

order PHP and ASP

users  PHP and ASP

Cart Table:
This table contains all the user cart details. Cart order_id_fk is a foreign key, it references to Orders order_id. This will update once the user Order is successful.

CREATE TABLE Cart(
cart_id INT PRIMARY KEY AUTO_INCREMENT,
product_id_fk INT,
user_id_fk INT,
order_id_fk INT,
cart_status enum(‘0′,’1’) DEFAULT ‘0’,
FOREIGN KEY(product_id_fk) REFERENCES Products(product_id),
FOREIGN KEY(user_id_fk) REFERENCES Users(user_id),
FOREIGN KEY(order_id_fk) REFERENCES Orders(order_id)

cart PHP and ASP

cart  PHP and ASP

Payment Form & System Design

This project contains three folders called js,includes and uploads with PHP files.

braintree:
braintree.php //BrainTree library file
js
jquery.min.js
jquery.creditCardValidator.js
index.php
cardProcess.php
functions.php
db.php

Payment form contains Card Number, Card Name, Expiry Date and CVV(Secure Number).PaymentSystem PHP and ASPHTML5 Code:
Simple HTML5 code

<form method=”post”  id=”paymentForm”>
Payment details
<ul>

<li>
<label>Card Number </label>
<input type=”text” name=”card_number” id=”card_number”  maxlength=”20″ placeholder=”1234 5678 9012 3456″/>
</li>
<li>
<label>Name on Card</label>
<input type=”text” name=”card_name” id=”card_name” placeholder=”Srinivas Tamada”/>
</li>
<li class=”vertical”>

<ul>
<li>
<label>Expires</label>
<input type=”text” name=”expiry_month” id=”expiry_month” maxlength=”2″ placeholder=”MM” />
<input type=”text” name=”expiry_year” id=”expiry_year” maxlength=”2″ placeholder=”YY” />
</li>
<li>
<label>CVV</label>
<input type=”text” name=”cvv” id=”cvv” maxlength=”3″ placeholder=”123″ />
</li>
</ul>

</li>
<li>
<input type=”submit” id=”paymentButton” value=”Proceed” disabled=”true” class=”disable”>
</li>
</ul>
</form>
<div id=”orderInfo”></div>

CSS Code:

*{margin: 0px; padding:0px;}
ul {list-style: none;}
label{padding:8px 0px 8px 0px;}
#paymentForm label
{
color: #555;
display: block;
font-size: 14px;
font-weight: 400;
}
#paymentForm input[type=text]
{
background-color: #FFFFFF;
border: 1px solid #E5E5E5;
color: #333333;
display: block;
font-size: 18px;
height: 32px;
padding: 0 5px;
width: 275px;
}
#paymentForm li {margin: 8px 0;}
#orderInfo{display:none}
.disable{opacity: 0.2}
.vertical li
{
float: left;
width: 140px;
}

JavaScript:
Validating the payment form using Regular Expressions.

<script src=”js/jquery.min.js”></script>
<script src=”js/jquery.creditCardValidator.js”></script>
<script>
$(document).ready(function()
{
/* Form Validation */
$(“#paymentForm input[type=text]”).on(“keyup”,function()
{
var cardValid=$(“#card_number”).attr(‘rel’);
var C=$(“#card_name”).val();
var M=$(“#expiry_month”).val();
var Y=$(“#expiry_year”).val();
var CVV=$(“#cvv”).val();
var expName =/^[a-z ,.’-]+$/i;
var expMonth = /^01|02|03|04|05|06|07|08|09|10|11|12$/;
var expYear = /^16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31$/;
var expCVV=/^[0-9]{3,3}$/;

if(cardValid>0 && expName.test(C) && expMonth.test(M) && expYear.test(Y)
&& expCVV.test(CVV) && parseInt(cardCheck)>0)
{
$(‘#paymentButton’).prop(‘disabled’, false);
$(‘#paymentButton’).removeClass(‘disable’);
}
else
{
$(‘#paymentButton’).prop(‘disabled’, true);
$(‘#paymentButton’).addClass(‘disable’);
}
});

/* Card Validation */
cardValidate();

/*Payment Form */
$(“#paymentForm”).submit(function()
{
//…….
});

});
</script>

Card Validation:
Credit Card Validation using jquery.validateCreditCard plugin.

/* Credit Card Type Check */
function cardValidate()
{
$(‘#card_number’).validateCreditCard(function(result)
{
var N=$(this).val();
var C=$(this).attr(“class”);
$(this).attr(“class”,””);
if(result && N.length>0)
{
$(this).addClass(result.card_type.name);

if(result.valid && result.length_valid && result.luhn_valid)
{
$(this).addClass(‘valid’);
$(this).attr(“rel”,”1″);
}
else
{
$(this).attr(“rel”,”1″);
}

}
else
{
$(this).removeClass(C);
}
});
}

Ajax Payment Process:
BrainTree Payment process with Jquery Ajax, here $(this).serialize() get all the form input values and posting to cardProcess.php. Once order is successful, use will get the Order status message.

/*Payment Form */
$(“#paymentForm”).submit(function()
{
var datastring = $(this).serialize();
$.ajax({
type: “POST”,
url: “cardProcess.php”,
data: datastring,
dataType: “json”,
beforeSend: function(){  $(“#paymentButton”).val(‘Processing..’) },
success: function(data)
{
$.each(data.OrderStatus, function(i,data)
{
var HTML;
if(data)
{
$(“#paymentGrid”).slideUp(“slow”);
$(“#orderInfo”).fadeIn(“slow”);

if(data.status == ‘1’)
{
HTML=”Order <span>”+data.orderID+”</span> has been created successfully.”;
}
else if(data.status == ‘2’)
{
HTML=”Transaction has been failed, please use other card.”;
}
else
{
HTML=”Card number is not valid, please use other card.”;
}

$(“#orderInfo”).html(HTML);
}
});
},
error: function(){ alert(‘Network Error’); }
});
return false;
});

BrainTree Integration:

Create a sandbox account at sandbox.braintreegateway.com for testing process.

braintreelogin PHP and ASPGo to Account -> My User scroll down you will find API keys.
button PHP and ASPYou will find merchantId, publicKey and privateKey
keys PHP and ASP

cardProcess.php:
Here you have to modify with your BrainTree merchandID, pulicKey and privateKey. This is update Orders table, once the transaction is successful. Always maintain/storecart total price value in session. Once testing is done, you can modify environment value from sandbox to production.

<?php
include ‘db.php’;
include ‘functions.php’;
$session_price =$_SESSION[‘session_price’]; //Cart Total Price
if($_SERVER[“REQUEST_METHOD”] == “POST” )
{
$card_number=str_replace(“+”,””,$_POST[‘card_number’]);
$card_name=$_POST[‘card_number’];
$expiry_month=$_POST[‘expiry_month’];
$expiry_year=$_POST[‘expiry_year’];
$cvv=$_POST[‘cvv’];
$expirationDate=$expiry_month.’/’.$expiry_year;

require_once ‘braintree/Braintree.php’;
Braintree_Configuration::environment(‘sandbox’); // Change to production
Braintree_Configuration::merchantId(‘Merchant_ID’);
Braintree_Configuration::publicKey(‘Public_Key’);
Braintree_Configuration::privateKey(‘Private_Key’);
//BrainTree payment process
$result = Braintree_Transaction::sale(array(
‘amount’ => $price,
‘creditCard’ => array(
‘number’ => $card_number,
‘cardholderName’ => $card_name,
‘expirationDate’ => $expirationDate,
‘cvv’ => $cvv
)
));

if ($result->success)
{
if($result->transaction->id)
{
$braintreeCode=$result->transaction->id;
updateUserOrder($braintreeCode,$session_user_id,$session_price); //Order table update.
}
}
else if ($result->transaction)
{
echo ‘{“OrderStatus”: [{“status”:”2″}]}’;
}
else
{
echo ‘{“OrderStatus”: [{“status”:”0″}]}’;
}
}
?>


Update User Order:
This will update orders table, based on the BrainTree status code. Cart table status will change 0 to 1 with order id.

<?php
function updateUserOrder($braintreeCode,$session_user_id,$session_price)
{
$db = getDB();
$sql = “INSERT INTO Orders(user_id_fk,created,braintreeCode)VALUES(:user_id,:created,:braintreeCode)”;
$stmt = $db->prepare($sql);
$stmt->bindParam(“user_id”, $session_user_id);
$time=time();
$stmt->bindParam(“created”, $time);
$stmt->bindParam(“braintreeCode”, $braintreeCode);
$stmt->execute();

$sql1 = “SELECT order_id FROM Orders WHERE user_id_fk=:user_id ORDER BY order_id DESC LIMIT 1”;
$stmt1 = $db-> prepare($sql1);
$stmt1-> bindParam(“user_id”, $session_user_id);
$stmt1-> execute();
$OrderDetails = $stmt1->fetchAll(PDO::FETCH_OBJ);
$order_id=$OrderDetails[0]->order_id;

$sql2 = “UPDATE Cart SET order_id_fk=:order_id,cart_status=’1′,price=:price WHERE cart_status=’0′ AND user_id_fk=:user_id”;
$stmt2 = $db-> prepare($sql2);
$stmt2-> bindParam(“user_id”, $session_user_id);
$stmt2-> bindParam(“order_id”, $order_id);
$stmt2-> bindParam(“price”, $session_price);
$stmt2-> execute();
$db = null;
echo ‘{“OrderStatus”: [{“status”:”1″, “orderID”:”‘.$order_id.'”}]}’;
}
?>


Get User Cart Details:
Getting card details based on user session id.

<?php
function getUserCartDetails($session_user_id)
{
$db = getDB();
$sql = “SELECT P.product_name,P.price FROM Users U, Cart C, Products P WHERE U.user_id=C.user_id_fk AND P.product_id = C.product_id_fk AND C.user_id_fk=:user_id AND C.cart_status=’0′”;
$stmt = $db->prepare($sql);
$stmt->bindParam(“user_id”, $session_user_id);
$stmt->execute();
$getUserCartDetails = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
return $getUserCartDetails;
}
?>
db.php:
You have to modify username, password and databaseName values. Make sure enable PDO extension in PHP.ini.
<?php
function getDB() {
$dbhost=”localhost”;
$dbuser=”username”;
$dbpass=”password”;
$dbname=”databaseName”;
$dbConnection = new PDO(“mysql:host=$dbhost;dbname=$dbname”, $dbuser, $dbpass);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbConnection;
}/* User Sessions */
session_start();
$session_user_id=$_SESSION[‘user_id’];

Note: Once your testing is done, create a BrainTree production account and modify the key details.

Tips for common tasks in PHP

Tips for common tasks

Now know the basics. Where you go from here is up to you. You know enough now to implement some of these useful tasks:

User database to Tips for common tasks
You could implement a user database. You can add a login feature to this.

• News to Tips for common tasks
You could code a section that always displays the latest news or maybe a “What’s new” section that’s automatically generated. The TABLE could be something like:

Create Table For common tasks

(
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(40),
newsbody TEXT,
news_date DATE,
PRIMARY KEY (id),
UNIQUE id (id)
);

And assuming you want to automatically show the title of the latest five news items, the code could be something like to Tips for common tasks:

<HTML>
<?php
$sql="SELECT * FROM news ORDER by news_date DESC";
$db = mysql_connect("localhost", "root", "");
mysql_select_db("newsdb",$db);
$result = mysql_query($sql,$db);
echo "Latest News:<br>";
$i=1;
while ($myrow = mysql_fetch_array($result))
{
echo "<a href=\"newsdetail.php?id=".$myrow["id"]."\">".$myrow["title"]."</a><br>";
$i=$i+1;
if($i>5)
break;
}
?>
</HTML>

• Product database for Tips for common tasks
You could create a detailed database of your products. Clients could see all the products or search for particular product.

How to Customized Data in PHP

Deleting rows  for Customized Data in PHP

So far we have only entered new information in our database and viewed it to Customized Data in PHP. Where’s the fun if we can’t trash some of those data, at least the useless ones? Our delete.php will do just that. It works exactly like view.php. The only difference is the SQL command “DELETE FROM personnel WHERE id=$id”, which tell MySQL to delete the row that contains the id corresponding to the variable $id. Generally, the SQL command for deleting a row is DELETE FROM database_name WHERE field_name=somevalue for Customized Data in PHP.

<HTML>
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
mysql_query("DELETE FROM personnel WHERE id=$id",$db);
echo "Information Deleted";
?>
</HTML>

Once again we modify our previous viewdb2.php script How to  viewdb3.php to add this new feature Customized Data in PHP. The additions should be obvious.

<HTML>
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
$result = mysql_query("SELECT * FROM personnel",$db);
echo "<TABLE BORDER=2>";
echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Options</B></TR>";
while ($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>".$myrow["firstname"]." ".$myrow["lastname"]."</a><TD>".$myrow["nick"];
echo "<TD><a href=\"view.php?id=".$myrow[id]."\">View</a> ";
echo "<a href=\"delete.php?id=".$myrow[id]."\">Delete</a>";
}
echo "</TABLE>";
?>
</HTML>

Try clicking on delete and then view the database again with viewdb3.php to verify that the row was really deleted. You may have to refresh your browser for How to Customized Data in PHP.

Editing data to Customized Data in PHP

So far we have viewed and deleted database content. But sometimes we need to edit database content to Customized Data in PHP. For this we will modify our previously coded input.php file. By now you are familiar with the concept of passing variables by URL. We will call this modified script addedit.php:

Customized Data in PHP

<HTML>
<?php
if($submit)
{
$db = mysql_connect("localhost", "root","");
mysql_select_db("learndb",$db);
$sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary)
VALUES ('$first','$last','$nickname','$email','$salary')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
}
else if($update)
{
$db = mysql_connect("localhost", "root","");
mysql_select_db("learndb",$db);
$sql = "UPDATE personnel SET firstname='$first',
lastname='$last',nick='$nickname',email='$email',
salary='$salary' WHERE id=$id";
$result = mysql_query($sql);
echo "Thank you! Information updated.\n";
}
else if($id)
{
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
$result = mysql_query("SELECT * FROM personnel WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
First name:<input type="Text" name="first"
value="<?php echo $myrow["firstname"]?>"><br>
Last name:<input type="Text" name="last"
value="<?php echo $myrow["lastname"]?>"><br>
Nick Name:<input type="Text" name="nickname"
value="<?php echo $myrow["nick"]?>"><br>
E-mail:<input type="Text" name="email" value="<?php echo $myrow["email"]?>"><br>
Salary:<input type="Text" name="salary" value="<?php echo $myrow["salary"]?>"><br>
<input type="Submit" name="update" value="Update information"></form>
<?
}
else
{
?>
<form method="post" action="<?php echo $PHP_SELF?>">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Nick Name:<input type="Text" name="nickname"><br>
E-mail:<input type="Text" name="email"><br>
Salary:<input type="Text" name="salary"><br>
developerWorks® ibm.com/developerWorks
Creating dynamic Web sites with PHP and MySQL Trademarks
© Copyright IBM Corporation 2001. All rights reserved. Page 14 of 20
<input type="Submit" name="submit" value="Enter information"></form>
<?
}
?>
</HTML>

Hmmm…the code looks quite complex. But really it isn’t. Previously input.php had two features: it could add information to the database or could show the form. We’ll add two more features to it: the ability to show the same form but with values of a particular person already there and the ability to update records for that person.  For Customized Data in PHP The SQL commands for entering new information and updating existing information are different, so we can’t use our previous code for entering information. The script searches for the $submit variable. If it contains some value, then someone submitted new data and the information is entered into the database. If $submit does not contain any value, then someone might have just posted their updated information, so we check $update for How to Customized Data in PHP. If it contains a value, then we update that person’s record with the SQL statement “UPDATE personnel SET

fieldname1=’$variablename1′,fieldname2=’$variablename2′ ……… WHERE id=$id”;”. Otherwise, if someone provided the id in the query string, we show that person’s information, but this time in a form so he may change it. If all these are not the case, we simply have to show the old form. Experiment with the script. Open it with your browser to see what comes up. Then call it providing query string ?id=1. Change the information and click update. Verify whether the database is updated by viewing the database with viewdb3.php. Another new element was just introduced. It is the global PHP variable $PHP_SELF. To Customized Data in PHP This variable always contains the name of the script it is in and its location. We have used this variable in a ‘form action’ so no matter what you name this file, this script will always post information to itself to How to Customized Data in PHP. Once again we modify our viewing script incorporating this feature. Here’s the listing for viewdb4.php:

Customized Data in PHP

<HTML>
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
$result = mysql_query("SELECT * FROM personnel",$db);
echo "<TABLE BORDER=2>";
echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Options</B></TR>";
while ($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>".$myrow["firstname"]."
".$myrow["lastname"]."</a><TD>".$myrow["nick"];
echo "<TD><a href=\"view.php?id=".$myrow[id]."\">View</a> ";
echo "<a href=\"delete.php?id=".$myrow[id]."\">Delete</a> ";
echo "<a href=\"addedit.php?id=".$myrow[id]."\">Edit</a>";
}
echo "</TABLE>";
ibm.com/developerWorks developerWorks®
Creating dynamic Web sites with PHP and MySQL Trademarks
© Copyright IBM Corporation 2001. All rights reserved. Page 15 of 20
?>
</HTML>

Searching our data to Customized Data in PHP

Information is useless if you can’t find the data you require from a wealth of information. We need a way to search our database, so let’s implement a search function. The page will show a static form initially and will show the search result when we have something submitted to How to Customized Data in PHP.

Customized Data in PHP

<HTML>
<?php
if ($searchstring)
{
$sql="SELECT * FROM personnel WHERE $searchtype
LIKE '%$searchstring%' ORDER BY firstname ASC";
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
$result = mysql_query($sql,$db);
echo "<TABLE BORDER=2>";
echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Options</B></TR>";
while ($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>".$myrow["firstname"]." ".$myrow["lastname"]."<TD>".$myrow["nick"];
echo "<TD><a href=\"view.php?id=".$myrow["id"]."\">View</a>";
}
echo "</TABLE>";
}
else
{
?>
<form method="POST" action="<?php $PHP_SELF ?>">
<table border="2" cellspacing="2">
<tr><td>Insert you search string here</td>
<td>Search type</td></tr>
<tr>
<td><input type="text" name="searchstring" size="28"></td>
<td><select size="1" name="searchtype">
<option selected value="firstname">First Name</option>
<option value="lastname">Last Name</option>
<option value="nick">Nick Name</option>
<option value="email">Email</option>
</select></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
</form>
<?php
}
?>
</HTML>

The script checks whether a search string exists. If $searchstring contains a value, then we have something to search; otherwise, we just show an HTML form. The part of code that searches is similar to our viewdb2.php. The SQL command deserves a bit of explanation here. Let’s look at it closely. The SQL command is to Customized Data in PHP:

"SELECT * FROM personnel WHERE $searchtype LIKE '%$searchstring%' ORDER BY firstname ASC"

if we Customized Data in PHP ,Two news things are introduced here, “LIKE” and “ORDER BY”. LIKE simply means ‘sounds like’. The ‘%’ sign represents any possible combination of characters (numbers or letters). So to find people whose first name starts with ‘J’ we would use the SQL command “SELECT * FROM personnel WHERE firstname LIKE ‘J%'” To find those people with a name ending with J we have to use ‘%J’. If we wish find people with ‘J’ anywhere in their name (first, middle, or last) we have to use ‘%J%’. ‘ORDER BY’ simply orders the records in ascending or descending order. The syntax is: “ORDER BY fieldname order_method” where order_method is ASC or DESC allowing the ordering to be done in ASCending or DESCending order here to How to Customized Data in PHP.

in PHP Get a better view

Passing variables for Get a better view

Let’s take a different view now and consider how information can be passed to another PHP page. One method is by using forms as we have done already; another is by using query strings. What are query strings? Change the line method=”post” to method=”get” in our script input.php. Now try submitting new data into the database with it. After clicking submit you will see our familiar “Thank you! Information entered” in the browser. But look at the URL. It looks something like the following (the following line has been split for space reasons; you would enter it as one line):

http://yourhost/input.php?first=Rick&last=Denver&nickname=Mike&[email protected]
&salary=25000&submit=Enter+information

Look closely for Get a better view. Now the information is passed as a string in the URL instead of posting directly. The sentence after the ? is the query string, and as you can see it contains the name of the variable and its values. When PHP receives a query string like ?first=John it automatically creates a variable named $first and assigns the value from the query string to it. So it is equivalent to $first=”John”; When more than one variable is present, the variables are separated by an ampersand (&).

Viewing individual rows for Get a better view

So now we will create a script that will display the information of a particular row in our database defined by the variable $id. Save the following code as view.php. Try viewing it through your Web server as http://yourhost/view.php?id=2 (here we have passed the variable $id=2 through the query string). The page should show information corresponding to the id 2 in the MySQL database for Get a better view.

<HTML>
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
$result = mysql_query("SELECT * FROM personnel WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
echo "First Name: ".$myrow["firstname"];
echo "<br>Last Name: ".$myrow["lastname"];
echo "<br>Nick Name: ".$myrow["nick"];
echo "<br>Email address: ".$myrow["email"];
echo "<br>Salary: ".$myrow["salary"];
?>
</HTML>

Here the SQL command for  Get a better view

has changed and it tells the database to search for the row that has the value $id. But can’t multiple rows contain the same values of id? Generally a column can contain any value, the same or different Get a better view. But in our database two rows can never have the same value of id, as we have defined id as UNIQUE when we created our database. We immediately modify our previous viewdb.php to viewdb2.php so that it can call view.php with the proper query string.

<HTML>
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
$result = mysql_query("SELECT * FROM personnel",$db);
echo "<TABLE BORDER=2>";
echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Options</B></TR>";
while ($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>".$myrow["firstname"]." ".$myrow["lastname"]."<TD>".$myrow["nick"];
echo "<TD><a href=\"view.php?id=".$myrow[id]."\">View</a>";
}
echo "</TABLE>";
?>
</HTML>

Viewing this page will show a list of names and corresponding nicknames to Get a better view. Look at the third column with a hyperlink view. Take your mouse over the hyperlink and look what it points to. The link should be something like http://yourhost/view.php?id=3 and the links in each row will be different. Click on one of the links. It will bring up our previously coded view.php showing the detailed information of that person. How is this achieved? Let’s take a look at our code viewdb2.php. where all the real stuff takes place. The only unfamiliar thing here should be those odd dots (.) all around the line. The dot (.) is a concatenating operator in PHP, which means it concatenates the two strings on its two sides, which in turn means that if we write echo “Hello”.”World”, the output will actually be “HelloWorld”. In our example we use the concatenate operator to generate a line like for Get a better view:

<TR><TD>Camilla Anderson<TD>Rose<TD><a
href="view.php?id=2">View</a>