Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.