This is my first php program!



Download 6,9 Mb.
Pdf ko'rish
bet63/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   59   60   61   62   63   64   65   66   ...   69
Bog'liq
PHP

Sample Application
|
205
Administrator’s Page
Example 8-4 shows the backend page that allows administrators to add categories to
the listing service. The input fields for adding a new record appear after a dump of
the current data. The administrator fills in the form and presses the Add Category
button, and the page redisplays with the new record. If any of the three fields are not
filled in, the page displays an error message.
$dsn = "$phptype://$username:$password@$hostspec/$database";
} else {
$net8name = 'www';
$dsn = "$phptype://$username:$password@$net8name";
}
// establish the connection
$db = DB::connect($dsn);
if (DB::isError($db)) {
die ($db->getMessage( ));
}
?>
Example 8-4. Backend administration page


require_once('db_login.php');
?>
<br /><?php <br />// print the window title <a href="/letters-from-your-co-presidents.html">and the topmost body heading </a><br />$doc_title = 'Category Administration'; <br />echo "$doc_title\n"; <br />?> <br />



echo "$doc_title\n";
?>


// add category record input section
// extract values from $_REQUEST
$Cat_ID = $_REQUEST['Cat_ID'];
$Cat_Title = $_REQUEST['Cat_Title'];
Example 8-3. Database connection abstraction script (db_login.php) (continued)
,ch08.16110 Page 205 Wednesday, March 13, 2002 11:44 AM


This is the Title of the Book, eMatter Edition
Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.
206
|
Chapter 8: Databases
$Cat_Desc = $_REQUEST['Cat_Desc'];
$add_record = $_REQUEST['add_record'];
// determine the length of each input field
$len_cat_id = strlen($_REQUEST['Cat_ID']);
$len_cat_tl = strlen($_REQUEST['Cat_Title']);
$len_cat_de = strlen($_REQUEST['Cat_Desc']);
// validate and insert if the form script has been
// called by the Add Category button
if ($add_record == 1) {
if (($len_cat_id > 0) and ($len_cat_tl > 0) and ($len_cat_de > 0)){
$sql = "insert into categories (category_id, title, description)";
$sql .= " values ('$Cat_ID', '$Cat_Title', '$Cat_Desc')";
$result = $db->query($sql);
$db->commit( );
} else {
echo "
Please make sure all fields are filled in ";
echo "and try again.
\n";
}
}
// list categories reporting section
// query all records in the table after any
// insertion that may have occurred above
$sql = "select * from categories";
$result = $db->query($sql);
?>






// display any records fetched from the database
// plus an input line for a new category
while ($row = $result->fetchRow( )){
echo "\n";
}
?>




Cat ID Title Description
$row[0]$row[1]$row[2]

Example 8-4. Backend administration page (continued)
,ch08.16110 Page 206 Wednesday, March 13, 2002 11:44 AM


This is the Title of the Book, eMatter Edition
Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Download 6,9 Mb.

Do'stlaringiz bilan baham:
1   ...   59   60   61   62   63   64   65   66   ...   69




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish