<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[controllo dati che non funziona]]></title><description><![CDATA[<p dir="auto">ciao,</p>
<p dir="auto">nel DB ho 2 tipi di prodotti:</p>
<ul>
<li>prodotti normali</li>
<li>abbonamenti</li>
</ul>
<p dir="auto">per questioni di spese di spedizione devo fare in modo che se all'interno del carrello ho un prodotto normale, non si può aggiungere un abbonamento e viceversa.<br />
per distinguere un prodotto da un abbonamento ho aggiunto un campo ENUM nella tabella prodotti, in cui se è un prodotto normale viene identificato come 'N' (default), mentre se è un abbonamento viene indentificato con un 'S'.</p>
<p dir="auto">Nella funzione addToCart() che è quella che gestisce l'inserimento, ho aggiunto il codice per provare a fare un controllo che però non funziona bene.<br />
mi visualizza il messaggio solo se inserisco 2 prodotti (o abbonamenti) uguali. altrimenti il controllo non funziona.</p>
<p dir="auto">funzione completa:</p>
<pre><code class="language-php">function addToCart()
{

        // make sure the product id exist
    if (isset($_GET['p']) &amp;&amp; (int)$_GET['p'] &gt; 0) {
        $productId = (int)$_GET['p'];
    } else {
        header('Location:home.php');
    }

    // does the product exist ?
    $sql = "SELECT pd_id, pd_qty
            FROM tbl_product
             WHERE pd_id = $productId";
               $result = dbQuery($sql);

    if (dbNumRows($result) != 1) {
        // the product doesn't exist
        header('Location: home.php?page=cart');
    }

// INIZIO CODICE PER IL CONTROLLO
$sql = "SELECT ct.pd_id, pd.pd_id, abbonamento
                                   FROM tbl_cart ct, tbl_product pd
                                   WHERE ct.pd_id = pd.pd_id
                                   AND pd.pd_id =$productId";
    $result = dbQuery($sql);
while ($row = dbFetchAssoc($result)) {
    extract($row);


          if ($abbonamento == 'N' &amp;&amp; $_GET['pd'] =='N') {
            echo "il prodotto che stai per inserire è dello stesso tipo presente nel carrello, cioè NON è un abbonamento"; exit;
  } elseif ($abbonamento == 'S' &amp;&amp; $_GET['pd'] =='S') {
            echo "il prodotto che stai per inserire è dello stesso tipo presente nel carrello, cioè è un abbonamento";exit;
  } elseif ($abbonamento == 'N' &amp;&amp; $_GET['pd'] =='S') {
             echo "il prodotto che stai per inserire non è dello stesso tipo. Nel carrello hai un prodotto normale, il tuo è un abbonamento";exit;
  } elseif ($abbonamento == 'S' &amp;&amp; $_GET['pd'] =='N') {
            echo "il prodotto che stai per inserire non è dello stesso tipo. Nel carrello hai un abbonamento, il tuo è un prodotto normale";exit;
  }
}
// FINE CODICE PER IN CONTROLLO

    // current session id
    $sid = session_id();

    // check if the product is already
    // in cart table for this session
    $sql = "SELECT pd_id
            FROM tbl_cart
            WHERE pd_id = $productId AND ct_session_id = '$sid'";
    $result = dbQuery($sql)or die(mysql_error());;

    if (dbNumRows($result) == 0) {
        // put the product in cart table
        $sql = "INSERT INTO tbl_cart (pd_id, ct_qty, ct_session_id, lang_name, ct_date)
                VALUES ($productId, 1, '$sid', '{$_POST["lingua"]}', NOW())";
        $result = dbQuery($sql)or die(mysql_error());
    } else {
        // update product quantity in cart table
        $sql = "UPDATE tbl_cart
                SET ct_qty = ct_qty + 1
                WHERE ct_session_id = '$sid' AND pd_id = $productId";

        $result = dbQuery($sql)or die(mysql_error());
    }

}
</code></pre>
<p dir="auto">cosa c'è che non va?:x  sono ad un passo dal suicidio!:x</p>
]]></description><link>https://dev.connect.gt/topic/20359/controllo-dati-che-non-funziona</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 14:51:16 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/20359.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 03 Nov 2006 10:52:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to controllo dati che non funziona on Fri, 03 Nov 2006 15:45:56 GMT]]></title><description><![CDATA[<p dir="auto">ho risolto...mannaggia! io mi accanivo sul resto mentre l'errore era nella query<br />
<img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/f326511b-d45b-4ba6-95c4-bc78698deebc-mavieni.gif?v=bb61372b9dc" class="not-responsive emoji emoji-customizations emoji--vai" style="height:1.4em;width:auto;vertical-align:middle" title=":vai:" alt="" /></p>
]]></description><link>https://dev.connect.gt/post/391209</link><guid isPermaLink="true">https://dev.connect.gt/post/391209</guid><dc:creator><![CDATA[tool]]></dc:creator><pubDate>Fri, 03 Nov 2006 15:45:56 GMT</pubDate></item></channel></rss>