Jump to content

need help with shoping script for my class project


marina

Recommended Posts

i need some help with shoping cart script for my class project.

 

this is my code

 

if there is anyone that can explain this code to me i would be gratefull

 

<?php

 

 

function insert_narudzba($detalji_nar)

{

extract($detalji_nar);

 

$conn = db_connect();

 

$query = "select kupacid from kupci where ime='$ime' and adresa='$adresa'

  and grad='$grad' and zip='$zip' and drzava='$drzava'";

 

$rezultat = $conn->query($query);

 

if($rezultat->num_rows > 0)

{

$kupac = $rezultat->fetch_object();

$kupacid = $kupac->kupacid;

}

else

{

$query = "insert into kupci values ('', '$ime', '$adresa', '$grad', '$zip', '$drzava')";

$rezultat = $conn->query($query);

if(!$rezultat)

return false;

}

 

$kupacid = $conn->insert_id;

 

$datum = date('Y-m-d');

$query = "insert into narudzbe values

            ('', $kupacid, ".$_SESSION['total_price'].", '$datum', 'PARTIAL')";

 

$rezultat = $conn->query($query);

  if (!$rezultat)

    return false;

 

//this is a part of code that i realy don't understand for what purpose it is

 

$query = "select narudzbaid from narudzbe where

              kupacid = $kupacid and

              iznos > ".$_SESSION['total_price']."-.001 and

              iznos < ".$_SESSION['total_price']."+.001 and

              datum = '$datum' and

              status_nar = 'PARTIAL'";

             

 

  $rezultat = $conn->query($query);

  if($rezultat->num_rows > 0)

  {

    $narudzba = $rezultat->fetch_object();

    $narudzbaid = $narudzba->narudzbaid;

  }

  else

    return false;

 

 

  foreach($_SESSION['cart'] as $sifra => $kolicina)

  {

    $detalji = get_disc_detalji($sifra);

 

    $rezultat = $conn->query($query);

    $query = "insert into stavke_nar values

              ('$narudzbaid', '$sifra', ".$detalji['cijena'].", $kolicina)";

    $rezultat = $conn->query($query);

    if(!$rezultat)

      return false;

  }

 

  return $narudzbaid;

}

 

 

 

?>

 

tnx

 

Marina

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.