Imenik
$svi = array('prezime', 'telefon', 'mobtel', 'mobtel2', 'worktel', 'worktel2', 'email', 'adresa', 'grad', 'drzava');
if (isset($_GET['akcija'])) {
echo "
";
// zakaci se na bazu, trebace
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
$baza = mysql_select_db('imenik', $link);
if (!$baza) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
switch ($_GET['akcija']) {
case "pretrazi":
$izraz=$_GET['izraz'];
$sqldod='';
// napravi ispravan sql kod za regexp upit po svemu
foreach ($svi as $sta)
{
$sqldod .= ' OR '.$sta.' regexp "'.$izraz.'"' ;
}
//napravi select upit
$sqlkod='SELECT id, ime, prezime, telefon, mobtel, mobtel2, worktel, worktel2, email, adresa, grad, drzava from ljudi where ime regexp "'.$izraz.'"';
$sqlkod .=$sqldod;
// echo $sqlkod;
//uradi upit
$rez = mysql_query($sqlkod);
if (mysql_num_rows($rez) == 0)
{
echo "Nema nijednog takvog u bazi";
}
else
{
// iscitaj sta si dobio
echo '
';
echo 'Izmena | Brisanje | Ime i Prezime | Telefoni | E-mail | Adresa |
';
while ($row = mysql_fetch_assoc($rez)) {
?>
&akcija=izmeni">Izmeni | &akcija=obrisi">Obriši |
echo $row["ime"] .' ' . $row["prezime"] .' | Kućni tel. ' . $row["telefon"] .' Mobilni ' . $row["mobtel"] .', ' . $row["mobtel2"] .' Na poslu ' . $row["worktel"] .', ' . $row["worktel2"] .' | ' ;
echo '' . $row["email"] . ' | ' . $row["adresa"] . ', ' . $row["grad"] .', ' . $row["drzava"];
?>
|
} //kraj while iz baze
echo '
';
mysql_free_result($result);
}
break;
case "unesi":
?>
break;
case "unesibaza":
$sqlkod = "INSERT INTO ljudi (id, ime, prezime, telefon, mobtel, mobtel2, worktel, worktel2, email, adresa, grad, drzava) VALUES ('','". $_GET['ime'] ."', '". $_GET['prezime']."', '". $_GET['telefon']."', '". $_GET['mobtel']."', '". $_GET['mobtel2']."', '". $_GET['worktel']."', '". $_GET['worktel2']."', '". $_GET['email']."', '". $_GET['adresa']."', '". $_GET['grad']."', '". $_GET['drzava']."')";
$rez = mysql_query($sqlkod);
if (!$rez) {
die('Invalid query: ' . mysql_error()); }
echo "Podaci su uspešno uneti u bazu!";
break;
case "izmeni":
$sqlkod = 'SELECT id, ime, prezime, telefon, mobtel, mobtel2, worktel, worktel2, email, adresa, grad, drzava from ljudi where id = '.$_GET['id'];
//echo $sqlkod;
$rez = mysql_query($sqlkod);
$row = mysql_fetch_assoc($rez);
// print_r($row);
?>
break;
case "izmenibaza":
// print_r($_GET);
$sqlkod = "UPDATE ljudi SET ime = '". $_GET['ime'] ."', prezime = '". $_GET['prezime']."', telefon = '". $_GET['telefon']."', mobtel = '". $_GET['mobtel']."', mobtel2 = '". $_GET['mobtel2']."', worktel = '". $_GET['worktel']."', worktel2 = '". $_GET['worktel2']."', email = '". $_GET['email']."', adresa = '". $_GET['adresa']."', grad = '". $_GET['grad']."', drzava = '". $_GET['drzava']."' where id = ".$_GET['id'];
// echo $sqlkod;
$rez = mysql_query($sqlkod);
if (!$rez) {
die('Invalid query: ' . mysql_error()); }
echo "Podaci su uspešno izmenjeni!";
break;
case "obrisi":
$sqlkod = 'DELETE FROM ljudi WHERE id = '. $_GET['id'];
// echo $sqlkod;
$rez = mysql_query($sqlkod);
if (!$rez) {
die('Invalid query: ' . mysql_error()); }
echo "Podaci su uspešno obrisani!";
break;
}
mysql_close($link);
}
?>