<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>The Book Center</title>
</head>
<body>
<?php
include('header.html'); //shtohet pjesa e kodit qe gjendet ne fajllin header.html
// ne variablat perkatese ruhen vlerat perkatese qe vijne nga fajlli paraprak
$bookid=$HTTP_POST_VARS['bookid'];
$title=$HTTP_POST_VARS['title'];
$datereal=$HTTP_POST_VARS['datereal'];
$cost=$HTTP_POST_VARS['cost'];
$pages=$HTTP_POST_VARS['pages'];
$genderid=$HTTP_POST_VARS['genderid'];
$pubhouseid=$HTTP_POST_VARS['pubhouseid'];
//ne qofte se njera nga kto variabla eshte e shprazet d.m.th. nuk kan ardh vlera nga fajlli paraprak nxiret mesazhi me poshte
if (!$bookid || !$title || !$datereal || !$cost || !$pages || !$genderid || !$pubhouseid)
{
echo 'You have not entered all the required details!<br />'
.'Please <a href=addbook.php>go back</a> and try again.';
exit;
}
$bookid = doubleval($bookid); //variabla e mer vleren si double
$title = addslashes($title) //variables i shtohen slash simbole ("/") qe mos te kete pengese me vone me querin kur do e shkrujm
$datereal = addslashes($datereal); //...
$cost = addslashes($cost); //...
$pages = addslashes($pages); //...
$genderid = doubleval($genderid); //...
$pubhouseid = doubleval($pubhouseid); //...
@ $db = mysql_connect('localhost', 'root'); //krijohet lidhja me serverin
if (!$db) //nese $db variabla eshte null d.m.th nuk eshte lidhur me bazen atehere hyn ne if dhe e paraqet mesazhin me poshte:
{
echo 'Error: The database connection fail. Please try again later!';
exit;
}
mysql_select_db('bookcenter'); //selektohet databaza 'bookcenter'
//ne variablen $query, ruhet nje string vlere qe do te perdoret si query per te futur te dhena ne tabelen book
$query = "insert into book values
('".$bookid."', '".$title."', '".$datereal."', '".$cost."', '".$pages."', '".$genderid."', '".$pubhouseid."')";
$result = mysql_query($query); //ekzekutohet query ne databaze dhe rezultati ruhet ne variablen $result
if ($result) //nese eshte ekzekutuar me sukses dhe kemi ndonje vlere ne var &result, atehere...
echo mysql_affected_rows().' BOOK was inserted into database.'; //... printojme numrin e reshtave qe jane shtuar (qe zakonisht eshte 1)
?>
<P><b>Your entry has been added.</b> Would you like to
<a href="addbook.php">add another?</a> Or just <a href="login_admin1.php">go Back!</a></p>
<?php
echo "<h1 align=center>The BOOK Collection</h1>";
//make the database connection
@ $db = mysql_connect('localhost', 'root');
if (!$db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
mysql_select_db('bookcenter');
//create a query
$sql = "SELECT * FROM book";
$result = mysql_query($sql);
print "<table border = 3 align = center>\n";
//get field names
print "<tr>\n";
while ($field = mysql_fetch_field($result)){
print " <th>$field->name</th>\n";
} // end while
print "</tr>\n\n";
//get row data as an associative array
while ($row = mysql_fetch_assoc($result)){
print "<tr>\n";
//look at each field
foreach ($row as $col=>$val){
print " <td>$val</td>\n";
} // end foreach
print "</tr>\n\n";
}// end while
print "</table>\n";
?>
</body>
</html>
gonidelux 0 Newbie Poster
pritaeas 2,194 ¯\_(ツ)_/¯ Moderator Featured Poster
gonidelux 0 Newbie Poster
Shanti C 106 Posting Virtuoso
karthik_ppts commented: good spot +5
gonidelux 0 Newbie Poster
karthik_ppts 81 Posting Pro
ravisoni6262 0 Newbie Poster
gonidelux 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.