Visualizzazione dei risultati da 1 a 5 su 5

Discussione: creazione carrello

  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2006
    Messaggi
    49

    creazione carrello

    ciao a tutti...ho bisogno di creare un carrello per un sito per un progetto scolastico...ci sono un certo numero di oggetti da vendere e conun pulsante puoi aggiungere questi oggetti al carrello...alla fine è possibile acquistare il tutto tramite pagamento con carta di credito etc...
    tenendo conto che conosco poco sia php che mysql avrei bisogno di un aiuto a artire da zero!
    grazie a tutti
    ho gia cercato in rete ma non ho trovato nulla che mi possa dare una mano anche perchè molti non riesco neanche a configurarli!

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2006
    Messaggi
    49
    allora alla fine sono riuscito a trovare quello che mi serviva...o meglio quasi....ho trovato questo script che gestisce il carrello e un catalogo come interessava a me, l'unico problema è che l'elenco dei prodotti viene gestito tramite un array e a me interessava avere l'elenco gestito da un database!
    riuscite a darmi il codice esatto...vi posto il mio codice! grazie
    [PHP]<?php
    session_start();
    if (!isset($_SESSION['cart'])) {
    $_SESSION['cart'] = array();
    }
    if (isset($_GET['buy'])) {
    // Add item to the end of the $_SESSION['cart'] array
    $_SESSION['cart'][] = $_GET['buy'];
    header('location: ' . $_SERVER['PHP_SELF'] . '?' . SID);
    exit();
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Product catalog</title>
    <meta http-equiv="content-type"
    content="text/html; charset=iso-8859-1" />
    </head>
    <body>


    Your shopping cart contains <?php echo count($_SESSION['cart']); ?> items.</p>


    View your cart</p>
    <?php
    $items = array(
    'Canadian-Australian Dictionary',
    'As-new parachute (never opened)',
    'Songs of the Goldfish (2CD Set)',
    'Ending PHP4 (O\'Wroxey Press)');
    $prices = array(24.95, 1000, 19.99, 34.95);
    ?>
    <table border="1">
    <thead>
    <tr>
    <th>Item Description</th>
    <th>Price</th>
    </tr>
    </thead>
    <tbody>
    <?php
    for ($i = 0; $i < count($items); $i++) {
    echo '<tr>';
    echo '<td>' . $items[$i] . '</td>';
    echo '<td>$' . number_format($prices[$i], 2) . '</td>';
    echo '<td><a href="' . $_SERVER['PHP_SELF'] .
    '?buy=' . $i . '">Buy</a></td>';
    echo '</tr>';
    }
    ?>
    </tbody>
    </table>


    All prices are in imaginary dollars.</p>
    </body>
    </html>
    [PHP]
    QUESTO E' QUELLO DEL CATALOGO MENTRE ADESO VI POSTO QUELLO DEL CARRELLO:
    [PHP]
    <?php
    session_start();
    if (!isset($_SESSION['cart'])) {
    $_SESSION['cart'] = array();
    }
    if (isset($_GET['empty'])) {
    // Empty the $_SESSION['cart'] array
    unset($_SESSION['cart']);
    header('location: ' . $_SERVER['PHP_SELF'] . '?' . SID);
    exit();
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Shopping cart</title>
    <meta http-equiv="content-type"
    content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <h1>Your Shopping Cart</h1>
    <?php
    $items = array(
    'Canadian-Australian Dictionary',
    'As-new parachute (never opened)',
    'Songs of the Goldfish (2CD Set)',
    'Ending PHP4 (O\'Wroxey Press)');
    $prices = array( 24.95, 1000, 19.99, 34.95 );
    ?>
    <table border="1">
    <thead>
    <tr>
    <th>Item Description</th>
    <th>Price</th>
    </tr>
    </thead>
    <tbody>
    <?php
    $total = 0;
    for ($i = 0; $i < count($_SESSION['cart']); $i++) {
    echo '<tr>';
    echo '<td>' . $items[$_SESSION['cart'][$i]] . '</td>';
    echo '<td align="right">$';
    echo number_format($prices[$_SESSION['cart'][$i]], 2);
    echo '</td>';
    echo '</tr>';
    $total = $total + $prices[$_SESSION['cart'][$i]];
    }
    ?>
    </tbody>
    <tfoot>
    <tr>
    <th align="right">Total:</th>

    <th align="right">$<?php echo number_format($total, 2); ?></th>
    </tr>
    </tfoot>
    </table>


    Continue Shopping or
    Empty your cart</p>
    </body>
    </html>
    [PHP]

  3. #3
    c'è la sezione offro lavoro/collaborazione per questo

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2006
    Messaggi
    49
    a me serve solo una parte di codice php che collega il mio database al mio sito...tutto qua...

  5. #5
    Utente di HTML.it
    Registrato dal
    Apr 2006
    Messaggi
    49
    rieccomi qua...sono riuscito a creare qualcosa che assomiglia ad un carrello...adesso mi interessava fare in modo di eliminare un oggetto dal carrello...vi posto il mio codice così potet darmi una mano...grazie ciao
    Codice PHP:
    <?php if (isset($_GET['joke'])): // If the user wants to add a joke ?>
    <?php 
    else: // Default page display

      // Connect to the database server
      
    $dbcnx = @mysql_connect('localhost''root''');
      if (!
    $dbcnx) {
        exit(
    '

    Unable to connect to the ' 
    .
            
    'database server at this time.</p>');
      }

      
    // Select the jokes database
      
    if (!@mysql_select_db('ecommerce')) {
        exit(
    '

    Unable to locate the utenti ' 
    .
            
    'database at this time.</p>');
      }

      
    // If a joke has been submitted,
      // add it to the database.
      
    if (isset($_POST['codice'])) {
        
    $codice $_POST['codice'];
        
    $carta $_POST['carta'];
        
    $modello $_POST['modello'];
        
    $email $_POST['email'];
        
    $nome $_POST['nome'];
        
    $cognome $_POST['cognome'];
        
    $telefono $_POST['telefono'];
        
    $indirizzo $_POST['indirizzo'];
        
        
    $sql "INSERT INTO utenti SET
            codice='
    $codice',
            carta='
    $carta',
            modello='
    $modello',
            email='
    $email',
            nome='
    $nome',
            cognome='
    $cognome',
            telefono='
    $telefono',
            indirizzo='
    $indirizzo',
            data=CURDATE()"
    ;        
        if (@
    mysql_query($sql)) {
          echo 
    '











    <h3>[b]La Tua Richiesta è Stata Elaborata con Successo[/b]</h3>
    </p>'
    ;
        } else {
          echo 
    '

    Error adding submitted joke: ' 
    .
              
    mysql_error() . '</p>';
        }
      }

      echo 
    '

    </p>'
    ;

      
    $query="select * from utenti order by modello";
    $resultmysql_query($query);
    $numfields mysql_num_fields($result);

    echo 
    "<table>\n<tr>";
    for (
    $i=0$i $numfields$i++) 
      { 
       echo 
    '<th>'.mysql_field_name($result$i).'</th>'
       }
       echo 
    "</tr>\n";
       
       while (
    $row mysql_fetch_row($result)) 
      { 
       echo 
    '<tr><td>'.implode($row,'</td><td>'). "</td></tr>\n"
      }
      echo 
    "</table>\n";

      
    // Display the text of each joke in a paragraph
      
    while ($row mysql_fetch_array($result)) {
        echo 
    '

    $row['modello'] . '</p>';
      }

      
    // When clicked, this link will load this page
      // with the joke submission form displayed.
      
    echo '

    <a href="' 
    $_SERVER['PHP_SELF'] .
          
    '?joke=1">
    <div align="center">
      <h1>[b]---&gt; compra un prodotto &lt;--- [/b]
      </h1></a></p>'
    ;

    endif;
    ?>
    dimenticavo...tra la prima e la second riga c'è un'intera pagina html...nella pagina c'è un form da compilare con tutti i dati relativi all'oggetto che verranno poi inseriti nel database e visualizzati!non è il massimo ma è quello che sono riuscito a fare! ora mi interessava come eliminare gli oggetti dal carrello...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.