Treceți la conținutul principal

o aplicatie php acedb

//ace.sql

create database acedb;
use acedb;
grant all privileges on acedb.* to ace@localhost identified by 'ace2';

drop table if exists pets;
drop table if exists owners;

create table pets (id int auto_increment primary key, name char(60), marks char(255), lostdate date, reward int, owner_id int, picture blob);
create table owners (id int auto_increment primary key, name char(60), address char(255), phone char(40), picture blob);

//connect.php

<?php

function petRedir() {
    header("Location: pets.php");
    exit();
}

function ownerRedir() {
    //header("Location: owners.php");
    exit();
}

function scalepicture($orig) {
    $needx = $needy = 250;

    $rx = imagesx($orig);
    $ry = imagesy($orig);

    if($rx > $needx) {
        $ry *= $needx/$rx;
        $rx = $needx;
    }

    if($ry > $needy) {
        $rx *= $needy/$ry;
        $ry = $needy;
    }

    $res = imagecreate($rx, $ry);
    imagecopyresized($res, $orig, 0, 0, 0, 0, $rx, $ry,
 imagesx($orig), imagesy($orig));

    $tn = tempnam("img", "/tmp");
    imagejpeg($res, $tn);
    $content = addslashes(fread(fopen($tn, "r"), filesize($tn)));
    unlink($tn);

    return $content;
}
                                       error_reporting (E_ALL ^ E_NOTICE);
mysql_connect("localhost", "root", "") or die("Could not connect");
mysql_select_db("ACEDB") or die("Could not select database");

?>



//design_bottom.inc

    </td>

    <td width="222" height="100%" valign="top" background="images/ace_back.jpg">
 <img src="images/ace.jpg">
    </td>
</tr>
</table>

<table cellpadding=0 cellspacing=0 border=0>
<tr align="center"><td><img src="images/bottom.gif"></td></tr>
</table>

</body>

//design_top.inc

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FCE9C5">

<table width="780" cellpadding="0" cellspacing="0" border="0">
<tr><td width="780" height="87"><img src="images/logo.gif"></td></tr>
</table>

<table width="780" cellpadding="0" cellspacing="0" border="0">
<tr>
    <td width="558" valign="top">
        <table width="558" height="22" cellpadding="0" cellspacing="0" border="0">
        <tr bgcolor="#C70000" width="490"><td align="center">
     <table border=0 cellspacing=0 cellpadding=0>
     <tr>
  <td><a href="owners.php"><img src="images/ownerslist.gif" border=0></a></td>
  <td><a href="pets.php"><img src="images/petslist.gif" border=0></a></td>
     </tr>
     </table>
 </td></tr>
 </table>

//fetchimage.php

<?php

require "connect.php";

$r = mysql_query("select picture from $src where id = $id");

if($row = mysql_fetch_assoc($r)) {
    header("Content-type: image/jpeg");
    echo($row["picture"]);
    flush();
}

?>

//index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FCE9C5">

<table width="780" cellpadding="0" cellspacing="0" border="0">
<tr><td width="780" height="87"><img src="images/logo.gif"></td></tr>
</table>

<table width="780" cellpadding="0" cellspacing="0" border="0">
<tr>
    <td width="558" valign="top">
        <table width="558" height="22" cellpadding="0" cellspacing="0" border="0">
        <tr bgcolor="#C70000" width="490"><td align="center">
     <table border=0 cellspacing=0 cellpadding=0>
     <tr>
  <td><a href="owners.php"><img src="images/ownerslist.gif" border=0></a></td>
  <td><a href="pets.php"><img src="images/petslist.gif" border=0></a></td>
     </tr>
     </table>
 </td></tr>
 </table>
   </td>

    <td width="222" height="100%" valign="top" background="images/ace_back.jpg">
 <img src="images/ace.jpg">
    </td>
</tr>
</table>

<table cellpadding=0 cellspacing=0 border=0>
<tr align="center"><td><img src="images/bottom.gif"></td></tr>
</table>

</body>

</HTML>

//owneradd.php

<?php

require "connect.php";

if(!empty($back)) {
    ownerRedir();
}

if(!empty($name)) {
    if($mode == "add") {
 $q = "insert into owners (name, phone, address) values ('".
     mysql_escape_string($name)."', '".
     mysql_escape_string($phone)."', '".
     mysql_escape_string($address)."')";

    } else if($mode == "update") {
 $q = "update owners set name='".
     mysql_escape_string($name)."', phone='".
     mysql_escape_string($phone)."', address='".
     mysql_escape_string($address)."' where id=$id";
    }

    if(!empty($photo) && $photo != "none") {
 $orig = @imagecreatefromstring(fread(fopen($photo, "r"), filesize($photo)));
 if(empty($orig)) {
     $msg = "The picture format is unknown or unsupported.";
 }
    }

    if(empty($msg) && mysql_query($q)) {
 if($id = mysql_insert_id()) {
     if(!empty($orig)) {
  $content = scalepicture($orig);
  mysql_query("update owners set picture = '$content' where id = $id");
     }
 }

 mysql_query("commit");
 header("Location: ownerdetails.php?id=".$id);
 exit;
    } else {
 $row["name"] = $name;
 $row["address"] = $address;
 $row["phone"] = $phone;
 if(empty($msg)) {
     $msg = "Your input is incorrect. Please check all the fields.";
 }
    }
}

if($mode == "add") {
    $action = "Add";
    $title = "Add an owner";

} else if($mode == "update") {
    $action = "Update";
    $title = "Modify an owner";

    $r = mysql_query("select name, phone, address from owners where id = $id")
 or ownerRedir();

    $row = mysql_fetch_assoc($r)
 or ownerRedir();
} else {
    ownerRedir();

}

?>

<html>

<head>
<title>Ace Ventura's personal database: Add an owner</title>
</head>

<?php include "design_top.inc"; ?>

<form enctype="multipart/form-data" method="post">

<input type="hidden" name="mode" value="<?= $mode ?>">
<input type="hidden" name="id" value="<?= $id ?>">

<table align="center" width="100%">

    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Name</b></td>
 <td><input type="text" size="50" name="name" value="<?= htmlspecialchars($row["name"]) ?>"></td>
    </tr>

    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Phone</b></td>
 <td><input type="text" size="50" name="phone" value="<?= htmlspecialchars($row["phone"]) ?>"></td>
    </tr>

    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Address</b></td>
 <td><textarea name="address" cols=48 rows=3><?= $row["address"] ?></textarea></td>
    </tr>

    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Upload photo</b></td>
 <td><input type="file" size=50 name="photo"></td>
    </tr>

    <tr>
 <td colspan=2 align="center">
     <?= $msg ?><br>
     <input type="submit" value="<?= $action ?>">
     <input type="submit" name="back" value="Back">
 </td>
    </tr>

</table>
</form>

<?php include "design_bottom.inc"; ?>

</html>

//ownerdetails.php

<?php

require "connect.php";

$r = mysql_query("select * from owner where id = $id");

if ($row = mysql_fetch_assoc($r)) {

?>

<html>

<head>
<title>Ace Ventura's personal database: Owner's details</title>
</head>

<?php include "design_top.inc"; ?>

<table align="center" width="100%">
    <tr>
 <td bgcolor="#FCD893" width="30%"><font color="#000000" face="Arial" size="2"><b>Name</b></td>
 <td><?= $row["name"] ?></td>
 <td align="right">
     <?php if($row["haspic"]) { ?>
  <img src="fetchimage.php?src=owners&id=<?= $id ?>" title="<?= $row["name"] ?>">
     <?php } else { ?>
  <img src="images/no_owner.gif" title="no picture available">
     <?php } ?>
 </td>
    </tr>
    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Phone</b></td>
 <td><?= $row["phone"] ?></td>
    </tr>
    <tr>
 <td bgcolor="#FCD893" valign="top"><font color="#000000" face="Arial" size="2"><b>Address</b></td>
 <td><?= $row["address"] ?></td>
    </tr>
    <tr>
 <td bgcolor="#FCD893" valign="top"><font color="#000000" face="Arial" size="2"><b>List of the lost pets</b></td>
 <td>

<?php

$r = mysql_query("select id, name, lostdate, reward from pets where owner_id = ".$id);
while ($arow = mysql_fetch_assoc($r)) {

?>
     <a href="petdetails.php?id=<?= $arow["id"] ?>"><?= $arow["name"] ?></a><br>
<?php } ?>

 </td>
    </tr>

    <tr>
 <td colspan=3 align="right">
     <a href="owneradd.php?mode=update&id=<?= $id ?>"><img src="images/update.jpg" border=0></a>
 </td>
    </tr>
</table>

<?php include "design_bottom.inc"; ?>

</html>

<?php

} else {
    header("Location: owners.php");
}

?>

//owners.php

<html>

<head>
<title>Ace Ventura's personal database: Owners list</title>
</head>

<?php include "design_top.inc"; ?>

<form action="remove.php">
<input type="hidden" name="src" value="owners">

<table width="558" cellpadding="5" cellspacing="0" border="0">
<tr>
    <td bgcolor="#FCD893" width="125" height="22"><font color="#000000" face="Arial" size="2"><b>Name</b></td>
    <td bgcolor="#FCD893" width="158" height="22"><font color="#000000" face="Arial" size="2"><b>Phone</b></td>
</tr>

<?php

    require "connect.php";
    $r = mysql_query("select id, name, phone from owner");
    while ($row = mysql_fetch_assoc($r)) {

?>

    <tr>
 <td>
     <?php if($mode == "remove") { ?>
  <input type="checkbox" name="<?= $row["id"] ?>">
     <?php } ?>

     <a href="ownerdetails.php?id=<?= $row["id"] ?>"><?= $row["name"] ?></a>
 </td>
 <td><?= $row["phone"] ?></td>
    </tr>

<?php
    }

?>

</table>

<table align="right" cellspacing="0" cellpadding="0" border="0">
    <tr>
<?php if($mode == "remove") { ?>

 <td><input type="submit" value="Remove checked"></td>
 <td><input type="submit" value="Back" name="back"></td>

<?php } else { ?>

 <td><a href="owneradd.php?mode=add"><img src="images/add.gif" border=0></a></td>
 <td><a href="owners.php?mode=remove"><img src="images/remove.gif" border=0></a></td>

<?php } ?>

    </tr>

</table>
</form>

<?php include "design_bottom.inc"; ?>

</html>

//petadd.php

<?php

require "connect.php";

if(!empty($back)) {
    petRedir();
}

if(!empty($name)) {
    $dname = mysql_escape_string($name);
    $dmarks = mysql_escape_string($marks);

    if(!empty($lostdate)) {
 list($day, $month, $year) = sscanf($lostdate, "%d.%d.%d");

 if(checkdate($month, $day, $year)) {
     $dlostdate = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
 } else {
     $msg = "The date entered is invalid. Please correct it.";
 }
    }

    if(empty($msg)) {
 if($mode == "add") {
     $q = "insert into pets (name, marks, lostdate, owner_id, reward)
  values ('$dname', '$dmarks', '$dlostdate', $owner, $reward)";
 } else if($mode == "update") {
     $q = "update pets set name='$dname', marks='$dmarks', lostdate='$dlostdate', owner_id=$owner, reward=$reward
  where id=$id";
 }

 if(!empty($photo) && $photo != "none") {
     $orig = @imagecreatefromstring(fread(fopen($photo, "r"), filesize($photo)));
     if(empty($orig)) {
  $msg = "The picture format is unknown or unsupported.";
     }
 }
    }

    if(empty($msg) && mysql_query($q)) {
 if($id = mysql_insert_id()) {
     if(!empty($orig)) {
  $content = scalepicture($orig);
  mysql_query("update pets set picture = '$content' where id = $id");
     }
 }

 mysql_query("commit");
 header("Location: petdetails.php?id=$id");
 exit;
    } else {
 $row["name"] = $name;
 $row["marks"] = $marks;
 $row["lostdate"] = $lostdate;
 $row["owner_id"] = $owner;
 $row["reward"] = $reward;

 if(empty($msg)) {
     $msg = "Your input is incorrect. Please check all the fields.";
 }
    }
}

if($mode == "add") {
    $action = "Add";
    $title = "Add a pet";

} else if($mode == "update") {
    $action = "Update";
    $title = "Modify a pet";

    $r = mysql_query("select name, marks, date_format(lostdate, '%d.%m.%Y') as lostdate, owner_id, reward from pets where id = $id")
 or petRedir();

    $row = mysql_fetch_assoc($r)
 or petRedir();

    if($row["lostdate"] == "00.00.0000")
 $row["lostdate"] = "";

} else {
    petRedir();

}

?>

<html>

<head>
<title>Ace Ventura's personal database: <?= $title ?></title>
</head>

<?php include "design_top.inc"; ?>

<form enctype="multipart/form-data" method="post">

<input type="hidden" name="mode" value="<?= $mode ?>">
<input type="hidden" name="id" value="<?= $id ?>">

<table align="center" width="100%">

    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Name</b></td>
 <td><input type="text" size="50" name="name" value="<?= htmlspecialchars($row["name"]) ?>"></td>
    </tr>

    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Owner</b></td>
 <td>
     <select name="owner">
  <option value="0">No owner

<?php
$r = mysql_query("select id, name from owners");

while ($orow = mysql_fetch_assoc($r)) {
    if($orow["id"] == $row["owner_id"])
 $flg = "selected"; else $flg = "";

?>
  <option value="<?= $orow["id"] ?>" <?= $flg ?>><?= $orow["name"] ?>
<?php
}
?>

     </select>
 </td>
    </tr>

    <tr>
 <td bgcolor="#FCD893" valign="top"><font color="#000000" face="Arial" size="2"><b>Distinctive marks</b></td>
 <td><textarea name="marks" cols=48 rows=3><?= $row["marks"] ?></textarea></td>
    </tr>

    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Upload photo</b></td>
 <td><input type="file" size=50 name="photo"></td>
    </tr>

    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Lost on (DD.MM.YYYY)</b></td>
 <td><input type="text" size=10 maxlength=10 name="lostdate" value="<?= $row["lostdate"] ?>"></td>
    </tr>

    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Reward</b></td>
 <td><input type="text" size="4" name="reward" value="<?= $row["reward"] ?>"></td>
    </tr>

    <tr>
 <td colspan=2 align="center">
     <?= $msg ?><br>
     <input type="submit" value="<?= $action ?>">
     <input type="submit" name="back" value="Back"'>
 </td>
    </tr>

</table>
</form>

<?php include "design_bottom.inc"; ?>

</html>

//petdetails.php

<?php

require "connect.php";

$r = mysql_query("select
 p.name as pname, p.marks, date_format(p.lostdate, '%d.%m.%Y') as lostdate,
 p.reward, not isnull(p.picture) and p.picture != '' as haspic, o.name as oname, p.owner_id
    from pets p, owners o
    where p.id = $id and o.id = p.owner_id");

if(!($row = mysql_fetch_assoc($r))) {
    $r = mysql_query("select name as pname, marks,
     date_format(lostdate, '%d.%m.%Y') as lostdate, reward,
     not isnull(picture) and picture != '' as haspic
 from pets
 where id=$id");

    $row = mysql_fetch_assoc($r) or
 petRedir();
}

if($row["lostdate"] == "00.00.0000")
    $row["lostdate"] = "";

?>

<html>

<head>
<title>Ace Ventura's personal database: Pet's details</title>
</head>

<?php include "design_top.inc"; ?>

<table align="center" width="100%">
    <tr>
 <td bgcolor="#FCD893" width="30%"><font color="#000000" face="Arial" size="2"><b>Name</b></td>
 <td><?= $row["pname"] ?></td>
 <td align="right">

 <?php if($row["haspic"]) { ?>
     <img src="fetchimage.php?src=pets&id=<?= $id ?>" title="<?= $row["pname"] ?>">
 <?php } else { ?>
     <img src="images/no_pet.gif" title="no picture available">
 <?php } ?>

 </td>
    </tr>
    <tr>
 <td bgcolor="#FCD893" valign="top"><font color="#000000" face="Arial" size="2"><b>Distinctive marks</b></td>
 <td colspan=2><?= $row["marks"] ?></td>
    </tr>
    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Lost on date</b></td>
 <td colspan=2><?= $row["lostdate"] ?></td>
    </tr>
    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Reward promised</b></td>
 <td colspan=2><?= $row["reward"] ?></td>
    </tr>
    <tr>
 <td bgcolor="#FCD893"><font color="#000000" face="Arial" size="2"><b>Owner</b></td>
 <td colspan=2><a href="ownerdetails.php?id=<?= $row["owner_id"] ?>"><?= $row["oname"] ?></a></td>
    </tr>

    <tr>
 <td colspan=3 align="right">
     <a href="petadd.php?mode=update&id=<?= $id ?>"><img src="images/update.jpg" border=0></a>
 </td>
    </tr>
</table>

<?php include "design_bottom.inc"; ?>

</html>

//pets.php

<html>

<head>
<title>Ace Ventura's personal database: Pets list</title>
</head>

<?php include "design_top.inc"; ?>

<form action="remove.php">
<input type="hidden" name="src" value="pets">

<table width="558" cellpadding="5" cellspacing="0" border="0">
<tr>
    <td bgcolor="#FCD893" width="125" height="22"><font color="#000000" face="Arial" size="2"><b>Name</b></td>
    <td bgcolor="#FCD893" width="158" height="22"><font color="#000000" face="Arial" size="2"><b>Lost on</b></td>
    <td bgcolor="#FCD893" width="110" height="22"><font color="#000000" face="Arial" size="2"><b>Reward</b></td>
</tr>

<?php

    require "connect.php";

    $r = mysql_query("select id, name,
 date_format(lostdate, '%d.%m.%Y') as lostdate, reward
 from pets");

    while ($row = mysql_fetch_assoc($r)) {
 if($row["lostdate"] == "00.00.0000")
     $row["lostdate"] = "";
     
?>

    <tr>
 <td>
     <?php if($mode == "remove") { ?>
  <input type="checkbox" name="<?= $row["id"] ?>">
     <?php } ?>

     <a href="petdetails.php?id=<?= $row["id"] ?>"><?= $row["name"] ?></a>
 </td>
 <td><?= $row["lostdate"] ?></td>
 <td>$<?= $row["reward"] ?></td>
    </tr>

<?php
    }

?>

</table>

<table align="right" cellspacing="0" cellpadding="0">

    <tr>
 <td width="100%"></td>

<?php if($mode == "remove") { ?>

 <td><input type="submit" value="Remove checked"></td>
 <td><input type="submit" value="Back" name="back"></td>

<?php } else { ?>

 <td><a href="petadd.php?mode=add"><img src="images/add.gif" border=0></a></td>
 <td><a href="pets.php?mode=remove"><img src="images/remove.gif" border=0></a></td>

<?php } ?>

    </tr>

</table>
</form>

<?php include "design_bottom.inc"; ?>

</html>

//remove.php
<?php

if(empty($back)) {
    require "connect.php";
    $del = "";

    foreach($_GET as $id => $val) {
 if($id != "src") {
     if($del != "") $del .= " or ";
     if($upd != "") $udp .= " or ";

     $del .= "id = $id";
     $upd .= "owner_id = $id";
 }
    }

    mysql_query("delete from $src where $del");

    if($src == "owners")
 mysql_query("update pets set owner_id = 0 where $upd");

    mysql_query("commit");
}

header("Location: $src.php");

?>

//select.sql

 select * from owners;


Comentarii

Postări populare de pe acest blog

program principal cpp

#include "clasa.h" #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define DELAY 9000000 void delay() { for(long i=0;i<DELAY;i++); } //constructor cu initializare de la tastatura BigInt::BigInt() {char x; signed char t[400]; int i; printf("\nNumarul cu semn "); do s=getche(); while((s!='+')&&(s!='-')); n=0; do {x=getche(); t[n]=x-'0'; n++; } while((x>='0')&&(x<='9')); n--; for(i=0;i<n;i++) nr[i]=t[n-i-1]; } //constructor cu initializare prin parametri BigInt::BigInt(char semn,signed char numar[],int dim) {int i; s=semn; n=dim; for(i=0;i<n;i++) nr[i]=numar[n-i-1]; } //transform un int negativ in pozitiv int BigInt::Pozitiv(int x) {int a,vb; a=0; vb=0; while(vb==0) if((x+a)==0) vb=1; else a=a+1; x=a; return x; } //constructor dintr-un nr int obisnuit BigInt::BigInt(int x) {int i; if(x>=0) s='+'…

NUMERE PRIME ALGORITM C++

// NUMERE PRIME ALGORITM C++//  reediting from scratch //on this page is just the study for a next algoritm for generating the parime nr series like Fibonnaci or ....if possibile

74111121313417374414124343447 if u know the red part you can generate the orange part
1 0 1 111112222 1 1 23

o aplicatie php localitati romania

//APLICATIA SE REFERA LA BAZA DE DATE SIRUTA

//dragtable.js


/* dragtable v1.0 June 26, 2008 Dan Vanderkam, http://danvk.org/dragtable/ http://code.google.com/p/dragtable/ \Bsortabledraggable\B Instructions: - Download this file - Add <script src="dragtable.js"></script> to your HTML. - Add class="draggable" to any table you might like to reorder. - Drag the headers around to reorder them. This is code was based on: - Stuart Langridge's SortTable (kryogenix.org/code/browser/sorttable) - Mike Hall's draggable class (http://www.brainjar.com/dhtml/drag/) - A discussion of permuting table columns on comp.lang.javascript Licensed under the MIT license. */ // Here's the notice from Mike Hall's draggable script: //***************************************************************************** // Do not remove this notice. // // Copyright 2001 by Mike Hall. // See http…