Visualizzazione dei risultati da 1 a 4 su 4

Discussione: php-mysql

  1. #1
    Utente di HTML.it
    Registrato dal
    May 2012
    Messaggi
    11

    php-mysql

    salve ho una tabella in un db di nome carrello contenente i campi idcarrello (pk)
    prezzotot e idiutente(fk) e 3 pagine in php funzione.php carrello.php e login.php
    ho bisogno che cliccando su acquista nella pagina carrello.php mi venga inserito nella tab carrello $somma che si trova in funzione.php come prezzotot e idutente che si trova in login.php come idutente(fk). qualcuno puo dirmi come fare scrivendomi l intero procedimento??
    i tre file:
    carrello.php

    <?php
    @session_start();
    @require('mysql.php');
    @require('config.php');
    @require('funzioni.php');
    $carrello = $_SESSION['carrello'];
    if(@isset($_GET['action']))
    {
    $action = $_GET['action'];

    switch ($action)
    {
    case 'aggiungi':
    if ($carrello)
    {
    $carrello .= ','.$_GET['id'];
    }else{
    $carrello = $_GET['id'];
    }
    break;

    case 'cancella':
    if ($carrello)
    {
    $prodotti = @explode(',',$carrello);
    $acquisto = '';
    foreach ($prodotti as $prodotto)
    {
    if ($_GET['id'] != $prodotto)
    {
    if ($acquisto != '')
    {
    $acquisto .= ','.$prodotto;
    }else{
    $acquisto = $prodotto;
    }
    }
    }
    $carrello = $acquisto;
    }
    break;

    case 'aggiorna':
    if ($carrello)
    {
    $acquisto = '';
    foreach ($_POST as $key=>$value)
    {
    if (@stristr($key,'quantita'))
    {
    $id = @str_replace('quantita','',$key);
    $prodotti = ($acquisto != '') ?
    @explode(',',$acquisto) : @explode(',',$carrello);
    $acquisto = '';

    foreach ($prodotti as $prodotto)
    {
    if ($id != $prodotto)
    {
    if ($acquisto != '')
    {
    $acquisto .= ','.$prodotto;
    }else{
    $acquisto = $prodotto;
    }
    }
    }

    for ($i=1;$i<=$value;$i++)
    {
    if ($acquisto != '')
    {
    $acquisto .= ','.$id;
    }else{
    $acquisto = $id;
    }
    }
    }
    }
    }
    $carrello = $acquisto;
    break;
    }
    }

    $_SESSION['carrello'] = $carrello;

    ?>

    <html>
    <head>
    <title>carrello</title>
    <script type="text/javascript">
    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    body {
    background-color: #93BBF7;
    color: #FFFFFF;
    }
    .testo {
    color: #FFF;
    font-size: large;
    }
    .testo1 {
    color: #F00;
    font-size: xx-large;
    }
    .nonon {
    color: #93BBF7;
    }
    .nnvedi {
    color: #93BBF7;
    }
    .nnvedi {
    color: #93BBF7;
    }
    </style>
    </head>
    <body onLoad="MM_preloadImages('PULSANTE2.png','torna allo shop 2.png')">
    <h1 class="testo1">Il tuo carrello</h1>

    <?php

    echo usaCarrello();session_start();
    echo $somma;
    ?>
    <h1 class="testo">inserisci la quantità dei cd che vuoi acquistare e aggiorna il carrello prima di proseguire all' acquisto o tornare allo shop per inserire nuovi cd</h1>




    <?php
    echo mostraCarrello();
    ?>
    </p>


    <span class="nnvedi">kdkdkd</span>[img]PULSANTE2tornaalloshop.png[/img]<span class="nnvedi">kzikkdkdkdkdkdkdkdkdkdkkdkdkkkkl</span> [img]PULSANTE.png[/img]</p>


    </p>
    <div align="left"></div>

    </body>
    </html
    login.php

    <?php require_once('Connections/negoziomusica.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    }

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }
    }
    ?>
    <?php
    // *** Validate request to login to this site.
    if (!isset($_SESSION)) {
    session_start();
    }

    $loginFormAction = $_SERVER['PHP_SELF'];
    if (isset($_GET['accesscheck'])) {
    $_SESSION['PrevUrl'] = $_GET['accesscheck'];
    }

    if (isset($_POST['idutente'])) {
    $loginUsername=$_POST['idutente'];
    $password=$_POST['password'];
    $MM_fldUserAuthorization = "";
    $MM_redirectLoginSuccess = "index2.php";
    $MM_redirectLoginFailed = "ok.php";
    $MM_redirecttoReferrer = true;
    mysql_select_db($database_negoziomusica, $negoziomusica);

    $LoginRS__query=sprintf("SELECT idutente, password FROM cliente WHERE idutente=%s AND password=%s",
    GetSQLValueString($loginUsername, "int"), GetSQLValueString($password, "text"));

    $LoginRS = mysql_query($LoginRS__query, $negoziomusica) or die(mysql_error());
    $loginFoundUser = mysql_num_rows($LoginRS);
    if ($loginFoundUser) {
    $loginStrGroup = "";
    if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;

    if (isset($_SESSION['PrevUrl']) && true) {
    $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
    }
    else {
    header("Location: ". $MM_redirectLoginFailed );
    }
    }

    ?>
    <style type="text/css">
    .USER {
    font-family: "Lucida Console", Monaco, monospace;
    }
    .USER {
    font-family: "Comic Sans MS", cursive;
    font-weight: bold;
    font-style: italic;
    font-size: large;
    color: #00C;
    }
    .USER .USER .USER {
    font-size: large;
    }
    .USER .USER .USER {
    color: #00C;
    font-weight: bold;
    font-style: italic;
    }
    .NOVEDI {
    color: #CCC;
    }
    body {
    background-color: #CCC;
    }
    </style>
    <form action="<?php echo $loginFormAction; ?>" method="POST">


    <span class="USER"><span class="USER"><span class="USER">Username</span></span></span>
    <input type="text" name="idutente">
    </p>


    <span class="USER">Password</span>
    <input type="password" name="password">
    </p>



    <input name="button" type="submit" class="USER" id="button" value="Invia" />
    </p>

    </form>
    funzioni.php
    <?php
    function usaCarrello()
    {
    $carrello = $_SESSION['carrello'];
    if (!$carrello)
    {
    return 'Il carrello è vuoto.
    ';
    }else{
    $prodotti = @explode(',',$carrello);
    return 'Ci sono <a href="carrello.php">'.
    @count($prodotti). ' prodotti nel carrello.</a>
    ';
    }
    }

    function mostraCarrello()
    {
    global $db;
    $carrello = $_SESSION['carrello'];
    $somma = 0;
    if ($carrello)
    {
    $prodotti = @explode(',',$carrello);
    $acquisti = array();
    foreach ($prodotti as $prodotto)
    {
    $acquisti[$prodotto] = (@isset($acquisti[$prodotto])) ? $acquisti[$prodotto] + 1 : 1;
    }
    $result[] = '<form action="carrello.php?action=aggiorna" method="post" id="cart">';
    $result[] = '<table>';

    foreach ($acquisti as $id=>$quantita)
    {
    $sql = 'SELECT * FROM prodotti WHERE id = '.$id;
    $res = $db->query($sql);
    $f = $res->fetch();
    @extract($f);
    $result[] = '<tr>';
    $result[] = '<td>Cancella</td>';
    $result[] = '<td>'.$titolo.' by '.$artista.'</td>';
    $result[] = '<td>&euro;'.$prezzo.'</td>';
    $result[] = '<td><input type="text" name="quantita'.$id.'" value="'.$quantita.'" size="3"></td>';
    $result[] = '<td>&euro;'.($prezzo * $quantita).'</td>';
    $somma += $prezzo * $quantita;
    $result[] = '</tr>';
    }

    $result[] = '</table>';
    $result[] = 'Totale: &euro;'.$somma.'</br>';
    $result[] = '<button type="submit">Aggiorna il carrello</button>';
    $result[] = '</form>';
    }else{
    $result[] = 'Il carrello è vuoto.
    ';
    } return @join('',$result);
    }
    ?>

  2. #2
    Perdonami, ma abbi pietà. Indenta il codice ed inseriscilo negli appositi TAG.
    "Mai discutere con un idiota. Ti trascina al suo livello e ti batte con l'esperienza." (Oscar Wilde)

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2012
    Messaggi
    11
    perodnami tu ma non so come si fa puoi spiegarmelo grazie

  4. #4
    Devi racchiudere il codice tra i tag (PHP) e (/PHP) con le parentesi quadre al posto di quelle tonde e comunque cerca di indentarlo.
    "Mai discutere con un idiota. Ti trascina al suo livello e ti batte con l'esperienza." (Oscar Wilde)

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.