php.de

Zurück   php.de > Webentwicklung > PHP Einsteiger > PHP Tipps 2004

 
 
LinkBack Themen-Optionen Thema bewerten
Alt 23.09.2004, 12:25  
Gast
 
Beiträge: n/a
Standard [Erledigt] Hilfe - Problem mit Warenkorb

Stecke in Riesenkrise, weil ich einfach den Fehler nicht finde und keine Idee mehr habe.

Habe Problem mit meinem Warenkorb. Dieser basiert auf dem Buch "WebDatenbankApplikationen".
In der Datenbank gibt es u.a. die Tabellen "cart_orders" für Bestellung/cart und "cart_items" für die einzelnen Positionen des Warenkorbs.

Abriss der Tabellen:
[cart_orders]: user_id | order_id | date | note
[cart_items]: user_id | order_id | item_id | article_id | qty | date

Legt ein Benutzer (egal ob bekannter oder nicht) Waren in seinen Warenkorb, wird eine Zeile in _orders angelegt (user_id=-1) und entsprechende Zeilen in _items.

Wer eingeloggt ist kann dann auf "bestellen" klicken und dann soll nachfolgendes Script die user_id in o.g. Tabellen richtig einstellen, die nächste verfügbare order_id des benutzers ermitteln und jeweils setzen.

Problembeschreibung:
Beim ersten Mal durchlaufen funktioniert alles. Beim zweiten Mal scheint er sich bei der Abarbeitung des Scripts "aufzuhängen". Bekomme nur eine weiße Seite mit "Error", ohne Fehlermeldung. Auch in den Logs ist nichts zu finden.

Habe den Verdacht als ob es mit dem Locking der Tabellen zu tun hat, oder mit Prozessen die nicht beendet werden. Kann mir jemand bitte Feedback & Rat geben. Hänge schon viel zu lang an dem Problem und komm nicht einfach weiter.

btw: die Session-Verwaltung findet ebenfalls innerhalb dieser Datenbank in einer Tabelle "re_sessions" statt.

Code:
   // This script finalises a purchase
   // It expects that a cart has contents and that the
   // user is logged in

// Einbindung des gesamten Include-Sets
require("INC_global_includeset.inc");

// Einbindung des Session-Management
require_once 'INC_session.inc';
session_start();

set_error_handler("errorHandler");


   // Get the cust_id using loginUsername
   //   function getCustomerID($loginUsername, $connection)
   function getCustomerID($authenticatedUser, $connection)  
  {
      global $db;
      global $user;
      global $pass;
      global $host;

      $open = false;

      // If a connection parameter is not passed, then 
      // use our own connection to avoid any locking problems
      if (!isset($connection))
      { 
          if (!($connection = @ mysql_connect($host, 
                                             $user, 
                                             $pass)))
             showerror();

          if (!mysql_select_db($db, $connection))
             showerror();

          $open = true;
      }

      // We find the cust_id through the users table, using the
      // session variable holding their loginUsername.
      $query = "SELECT user_id 
                FROM users 
                WHERE user_name = \"$authenticatedUser\"";
  
      if (($result = @ mysql_query ($query, $connection)))
         $row = mysql_fetch_array($result);         
      else
         showerror();
 
      if ($open == true)
         @ mysql_close($connection);
  
     return($row["user_id"]);
   }


   // Check if a cart exists - this should never fail
   // unless the script is run directly
   if (!session_is_registered("order_no"))
   {
      session_register("message");
      $message = "In Ihrem Warenkorb befinden sich keine Artikel!";

      // Redirect the browser back to the calling page
      header("Location: $HTTP_REFERER");
      exit;
   }      

   // Check if the user is logged in - this should never fail
   // unless the script is run directly
   if (!session_is_registered("authenticatedUser"))
   {
      session_register("message");
      $message = "Sie müssen eingeloggt sein um eine Bestellung aufgeben zu können!";

      // Redirect the browser back to the calling page
      header("Location: $HTTP_REFERER");
      exit;
   }      
   
   // Open a connection to the DBMS
   if (!($connection = @ mysql_pconnect($host, 
                                        $user, 
                                        $pass)))
      showerror();                                     

   if (!mysql_select_db($db, $connection))
      showerror();

   // Several tables must be locked to finalise a purchase.
   // We avoid locking four other tables by
   // using another DBMS connection to produce the wine
   // information
   $query = "LOCK TABLES cart_orders WRITE, cart_items WRITE, re_sessions WRITE, users READ";

   // LOCK the tables
   if (!(@ mysql_query ($query, $connection)))
      showerror();   



   if (empty($message))
   {
      // Everything is ok - let's proceed then!         

      // First of all, find out the user's cust_id and
      // the next available order_id for this customer.
      $custID = getCustomerID($authenticatedUser, NULL);

      $query = "SELECT max(order_id) 
                FROM cart_orders 
                WHERE user_id = " . $custID;

      if (($result = @ mysql_query ($query, $connection)))
         $row = mysql_fetch_array($result);         
      else
         showerror();

      $newOrder_no = $row["max(order_id)"] + 1;
      
      // Now, change the cust_id and order_id of their cart!
      $query = "UPDATE cart_orders 
                SET user_id = $custID , " . 
                "order_id = " . $newOrder_no .
               " WHERE order_id = $order_no";

      if (!(@ mysql_query ($query, $connection)))
         showerror();

      $query = "UPDATE cart_items 
                SET user_id = $custID , " . 
               "order_id = " . $newOrder_no .
               " WHERE order_id = $order_no" .
	       " AND user_id = -1";

      if (!(@ mysql_query ($query, $connection)))
         showerror();

      // Officially empty the cart
      session_unregister("order_no");
   }


   
   // Last, UNLOCK the tables
   $query = "UNLOCK TABLES";
   if (!(@ mysql_query ($query, $connection)))
     showerror();

   // Redirect to the email confirmation page if everything is ok
   // (supply the custID and orderID to the script)
   // otherwise go back to the cart page and show a message
   if (empty($message))
   {
      header("Location: http://roth.webefacts.com/index.php?custID=$custID&orderID=$newOrder_no");
      exit;
   }
   else
      header("Location: cart_view.php");
 
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 26.11.2004, 11:32  
Gast
 
Beiträge: n/a
Standard

erledigt. Danke.
 
 


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Suchfunktion mit Blätterfunktion auf Ergebnisseite?! Hilfe! nicobischof PHP Tipps 2008 1 31.01.2008 13:42
Arrays, Session, Warenkorb Problem Shaft2002 PHP Tipps 2006 6 29.11.2006 12:28
datensätze defekt oder problem mit dem einlesen? Ministry Datenbanken 4 06.07.2006 18:42
Ewiges Problem mit den Sessions / Warenkorb max-dhom PHP Tipps 2006 12 13.04.2006 18:04
warenkorb Artikelanzahl verringern Mach!N3 PHP Tipps 2006 59 30.03.2006 08:09
warenkorb & mysql Mach!N3 PHP Tipps 2006 16 27.03.2006 21:18
Problem mit cp und "Argument list too long" Server, Hosting und Workstations 9 11.10.2005 22:17
Bildergallery - Problem - HILFE! PHP Tipps 2005-2 2 21.08.2005 20:54
Problem mit osCommerce brauche dringend Hilfe... PHP Tipps 2005 12 13.05.2005 08:40
Brauche hilfe bei komplexem problem mit PHP und MySQL Dragon26mFR PHP Tipps 2005 2 02.05.2005 13:58
anleitung für warenkorb bratwurstschorsch PHP Tipps 2004 1 25.10.2004 21:59
Artikelsuche - Warenkorb PHP Tipps 2004 9 12.10.2004 12:48
Problem mit $_SESSION PHP-Fortgeschrittene 10 19.08.2004 22:14
Problem bei Tabellenerstellung, bitte um Hilfe Datenbanken 4 01.07.2004 15:19
Problem mit Warenkorb PHP Tipps 2004 6 25.06.2004 00:54

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
oscommerce warenkorb, oscommerce warenkorb funktioniert nicht, oscommerce warenkorb aktualisieren, oscommerce session problem, warenkorb oscommerce, oscommerce warenkorb geht nicht, oscommerce anzahl im warenkorb, warenkorb php, oscommerce warenkorb problem, oscommerce kein warenkorb, oscommerce warenkorb mysql, osc warenkorb zerschossen, oscommerce keine artikel im warenkorb, oscommerce kategorieansicht warenkorb, warenkorb funktioniert nicht, osc warenkorb, oscommerce warenkorb langsam, oscommerce session warenkorb, osc warenkorb funktioniert nicht, problematik des warenkorbs

Alle Zeitangaben in WEZ +1. Es ist jetzt 15:21 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.