Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Accesso a DB con JScript tramite query SQL

    Salve ho un problema, non riesco a impostare la query giusta per selezionare solo i recordset che hanno la spunta nella colonna admin di una tabella. La tabella si chiama "users" e dovrei riuscire a impostare diverse tabbelle risultanti a seconda del fatto che chi fa l'accesso sia un normale client o un admin, oltre a una tabella base per chi non è loggato. Questo è il codice che ho provato a scrivere:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="it">
    <head>
    <title>Pagina dei prodotti</title>
    <% @ language="JavaScript" %>

    <script type="text/javascript" src="verifiche.js">
    </script>
    </head>
    <body>
    <div id="header">

    </div>
    <div id="menu">

    </div>
    div id="content">
    <%
    var con = Server.CreateObject("ADODB.Connection");
    var conString = "Provider=Microsoft.Jet.OLEDB.4.0; "+ "Data Source=" +Server.MapPath("./shop.mdb");
    con.Open(conString);
    var rstp = Server.CreateObject("ADODB.Recordset");
    var nick=String(Session("utente"));
    var sSQLString2= "Select * from users where nick=" +nick+"";
    rstp= con.Execute(sSQLString2);

    if (nick==undefined){
    var rst= Server.CreateObject("ADODB.Recordset");
    var sSQLString= "Select * from prods";
    rst= con.Execute(sSQLString);
    %>
    <h1>Tabella dei prodotti presenti nel nostro negozio:</h1>
    <table class="listaProdotti">
    <tr>
    <th class="listaProdotti">Nome prodotto</th>
    </tr>
    <%
    while(!rst.EOF){
    Response.Write("<tr><td class='listaProdotti'>"+rst("pname")+"</td></tr>");
    rst.MoveNext();
    }
    %>
    </table>
    <%
    } else if(rstp("admin")){
    var rst= Server.CreateObject("ADODB.Recordset");
    var sSQLString= "Select * from prods";
    rst= con.Execute(sSQLString);
    %>
    <table class="listaProdotti">
    <tr>
    <th class="listaProdotti"> Nome prodotto </th>
    <th class="listaProdotti"> Prezzo unitario in centesimi di euro</th>
    <th class="listaProdotti"> Quantit&agrave; disponibile</th>
    <th class="listaProdotti"> Quantit&agrave; selezionata</th>
    </tr>
    <%

    while(!rst.EOF){
    Response.Write("<tr><td class='listaProdotti'>"+rst("pname")+"</td><td class='listaProdotti'>" +rst("price")+"</td><td class='listaProdotti'>"+rst("qty")+"</td><td class='listaProdotti'><input type='text' size='3' maxlength='2' name='qta' value='0'></td>");
    rst.MoveNext();
    }


    %>
    </table>
    <form name="newProd" action="nuovoProdotto.asp" method="get">



    Nome nuovo prodotto:<input type="text" name="nomeP" value="" size="12">
    Quantit&agrave; del nuovo prodotto<input type="text" name="qtaP" value="0" size="5">
    Prezzo del prodotto<input type="text" name="prezzoP" value="0" size="7">
    </p>


    <input type="submit" value="Crea">
    <input type="reset" value="Cancella">
    </p>
    </form>
    <form name="deleteProd" action="cancellaProdotto" method="get">



    <select name="delete">
    <%
    rst.MoveFirst();
    while (!rst.EOF){
    Response.Write("<option value='"+rst("pname")+"'> "+rst("pname")+"</option>");
    rst.MoveNext();
    }
    %>
    </select>
    </p>


    <input type="submit" value="Elimina">
    </p>
    </form>
    <%
    } else{
    var rst= Server.CreateObject("ADODB.Recordset");
    var sSQLString= "Select * from prods";
    rst= con.Execute(sSQLString);
    %>
    <table class="listaProdotti">
    <tr>
    <th class="listaProdotti"> Nome prodotto </th>
    <th class="listaProdotti"> Prezzo unitario in centesimi di euro</th>
    <th class="listaProdotti"> Quantit&agrave; disponibile</th>
    <th class="listaProdotti"> Quantit&agrave; selezionata</th>
    </tr>
    <%

    while(!rst.EOF){
    Response.Write("<tr><td class='listaProdotti'>"+rst("pname")+"</td><td class='listaProdotti'>" +rst("price")+"</td><td class='listaProdotti'>"+rst("qty")+"</td><td class='listaProdotti'><input type='text' size='3' maxlength='2' name='qta' value='0'></td></tr>");
    rst.MoveNext();
    }
    %>
    </table>

    <%
    }
    rstp.Close();
    rst.Close();
    con.Close();
    rstp=null;
    rst=null;
    con=null;
    %>
    </div>
    <div id="footer">

    </div>
    </body>


    Vi ringrazio per l'attenzione!
    </html>

  2. #2

    solved

    ho risolto giocando con gli apici racchiudendo i singoli apici nei doppi nella scrittura della stringa sql:
    ...nick="+"'"+nick+"'"+"";

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.