SQL-Anfrage

Ich glaube bis jetzt waren die double Punkte vor CURRENT das problem, ich habe die entfernt,keine Fehlermeldung mehr, leider funktioniert die Anfrage es nicht richtig.
was ein user erstellt ist nicht sichbar, dh keine kann es sehen, aber ist in dei Datenbank sichbar, nur was der Administrator erstellt ist sichbar von allen.

ich wiederhole an dieser Stelle, was ich gern von der Anfrage haben will ist, dass :

Wenn ein User eine oder mehrere Variante erstellt, diese sollte von diese User und der Administrateur sichbar, alle andere User dürfen es nicht sehen.
aber was der Administrator erstellt sollte von allen sichbar
 
Ich glaube bis jetzt waren die double Punkte vor CURRENT das problem
Nein.
http://php.net/manual/en/pdo.prepared-statements.php

ich habe die entfernt,keine Fehlermeldung mehr, leider funktioniert die Anfrage es nicht richtig.
You don't say. Du hast ja den Parameter entfernt. :rolleyes:

was ein user erstellt ist nicht sichbar, dh keine kann es sehen, aber ist in dei Datenbank sichbar, nur was der Administrator erstellt ist sichbar von allen.
Kann ich nicht nachvollziehen. Warum gibst du eigentlich nie Code? Sollen wir hier hin- und herraten, was dein Code gerade tut oder wie stellst du dir das vor?

ich wiederhole an dieser Stelle, was ich gern von der Anfrage haben will ist, dass :
Das scheint mit dir ein wiederkehrendes Motiv zu sein. Wie oft muss ich noch sagen, dass wir den Code sehen müssen?
Du klatschst immer einen winzigen Ausschnitt hin, der wahrscheinlich nicht einmal das Problem ist, und wiederholst dann einfach so lange, was dein Problem ist, bis das Thema wieder geschlossen wird, weil du dich unkooperativ verhältst.
Also langsam müsstest du es eigentlich verstanden haben.

Gruss
cwriter
 
wenn ich die beide punkten wieder einfüge bekomme ich die Fehlermeldung
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2031 ' in C:\xampp\htdocs\kant\variants.php:210 Stack trace: #0 C:\xampp\htdocs\kant\variants.php(210): PDO->query('\nSELECT\n id,\n...') #1 C:\xampp\htdocs\kant\index.php(72): require_once('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\kant\variants.php on line 210

Zeile 210 : $req2 = $dbConnect->query($variants);

schon in phpmyadmin kann man die Anfrage nicht druchführen, wegen die double punkte
http://www.bilder-upload.eu/show.php?file=97a1bb-1479716708.png
 
Zuletzt bearbeitet:
wenn ich die beide punkten wieder einfüge bekomme ich die Fehlermeldung
Und was sagt uns die? RTFM.

Warum nutzt du query() mit PDO? Nutze doch entsprechend prepare() und execute().
Mithilfe von Google wärst du übrigens auch auf die Lösung gestossen.
Mal abgesehen davon hast du immer noch keinen Code geliefert. Fehlermeldung ist gut, Fehlermeldung + Code wäre besser...

Gruss
cwriter
 
hey cwriter,
so sieht das script aus
PHP:
<?php

require_once __DIR__ . '/connection.php';

$product = 'SELECT * FROM product WHERE id = '.$prodId;
$currentUser = 1234;
$req = $dbConnect->query($product);
$req->bindParam(':CURRENT_USER', $currentUser, PDO::PARAM_INT);
$req->execute();
$prod    = $req->fetch(PDO::FETCH_ASSOC);


?>

<div id="produits">

  <div class="produit h-product" id="produit_<?php echo $prod['id'] ?>" align="center" style="margin-right:58%">
        <form method="post" action="formular.php" autocomplete="off" name="<?php echo $prod['id'] ?>">
            <input type="hidden" name="id" value="<?php echo $prod['id'] ?>">
         <table border="0" cellpadding="0">
                  <tr>
            <td style="  color:#FFFFFF ; background-color:#860000; width:0%; height:13px; border:3px solid #860000;">PRODUKT</td>
                  </tr>                   
          <tr class="row9">
                    <td class="column0 style24 null style27" colspan="4" rowspan="8">
                        <img style=" z-index: 1; left: 40px; top: 10px; width: 220px; height: 220px;"
                             src="images/<?php echo $prod['path'] ?>"><input type="hidden" name="selected_photo"
                                                                             value="<?php echo $prod['path'] ?>"></td>
                    <td class="column4 style10 s">a</td>
                    <td class="column5 style19 n" style="font-size:15px"><input type="text" name="a" size="6" maxlength="4"  value="<?php echo $prod['a'] ?>"></td>

                </tr>
                <tr class="row10">
                    <td class="column4 style11 s">b</td>
                    <td class="column5 style20 n" style="font-size:15px"><input type="text" name="b" size="6" maxlength="4"  value="<?php echo $prod['b'] ?>"></td>

                </tr>
                <tr class="row11">
                    <td class="column4 style11 s">c</td>
                    <td class="column5 style20 null" style="font-size:15px"><input type="text" name="c" size="6" maxlength="4"  value="<?php echo $prod['c'] ?>">
                    </td>

                </tr>
                <tr class="row12">
                    <td class="column4 style11 s">d</td>
                    <td class="column5 style20 null" style="font-size:15px"><input type="text" name="d" size="6" maxlength="4"  value="<?php echo $prod['d'] ?>">
                    </td>

                </tr>
                <tr class="row13">
                    <td class="column4 style11 s">e</td>
                    <td class="column5 style20 null" style="font-size:15px"><input type="text" name="e" size="6" maxlength="4"  value="<?php echo $prod['e'] ?>">
                    </td>

                </tr>
            <tr class="row17" >
                    <td class="column0 style14 s" style="font-size:14px; text-align:center;font-weight:bold"><input type="reset" name="affacer_donnée" value="effacer"></td>
                    <td class="column1 style40 n style42" colspan="2"></td>
                    <td class="column3 style15 s" style="font-weight:bold">
                    <input type="checkbox" name="variant"> Ajouter une Variante </td>
                    <td class="column4 style40 n style41" colspan="2">
                    <input type="submit" name="save_product" value="Sauvegarder">
                    </td>
                </tr>   
       
                </tbody>
            </table>
        </form>
    </div>   

<?php
   
  // Variante
$variants = '
SELECT
   id,
   img_id,
   user_id,
   a,
   b,
   c,
   d,
   e 
FROM
   variants
   JOIN users USING(user_id)
WHERE
   user_id = :CURRENT_USER
   OR user_id IN(
        SELECT user_id
        FROM users
        WHERE ROLE = \'admin\');';

    $req2 = $dbConnect->prepare($variants);

    while ($variant = $req2->fetch(PDO::FETCH_ASSOC)) {
   
    ?>
        <div class="produit" id="produit_<?php echo $variant['id'] ?>" align="center" style="margin-right:68%">
            <form method="post" action="formular.php" name="<?php echo $variant['id'] ?>">
                <input type="hidden" name="id" value="<?php echo $variant['id'] ?>">
                <table border="0" cellpadding="0">   
        <td style="  color:#FFFFFF ; background-color:#004B27; width:0%; height:13px; border:3px solid #004B27;">VARIANTE</td>
       
        <tr class="row9">
                        <td class="column0 style24 null style27" colspan="4" rowspan="8">
                            <img style=" z-index: 1; left: 40px; top: 10px; width: 220px; height: 220px;" src="images/<?php echo $prod['path'] ?>"><input type="hidden" name="selected_photo" value="<?php echo $prod['path'] ?>" ></td>
                        <td class="column4 style10 s">a</td>
                        <td class="column5 style19 n"style="font-size:15px"><input type="text" name="a" size="6" maxlength="4" value="<?php echo $variant['a'] ?>" ></td>

                    </tr>
                    <tr class="row10">
                        <td class="column4 style11 s">b</td>
                        <td class="column5 style20 n"style="font-size:15px"><input type="text" name="b" size="6" maxlength="4" value="<?php echo $variant['b'] ?>" ></td>

                    </tr>
                    <tr class="row11">
                        <td class="column4 style11 s">c</td>
                        <td class="column5 style20 null"style="font-size:15px"><input type="text" name="c" size="6" maxlength="4" value="<?php echo $variant['c'] ?>" ></td>

                    </tr>
                    <tr class="row12">
                        <td class="column4 style11 s">d</td>
                        <td class="column5 style20 null"style="font-size:15px"><input type="text" name="d" size="6" maxlength="4" value="<?php echo $variant['d'] ?>" ></td>

                    </tr>
                    <tr class="row13">
                        <td class="column4 style11 s">e</td>
                        <td class="column5 style20 null" style="font-size:15px"><input type="text" name="e" size="6" maxlength="4" value="<?php echo $variant['e'] ?>" ></td>

                    </tr>
         
               
                    <tr class="row17">
                        <td class="column0 style14 s" style="font-size:14px; text-align:center;font-weight:bold">

                            <input type="reset" name="daten_loeschen" value="Zurücksetzen">

                            </td>
                        <td class="column1 style40 n style42" colspan="2">

                        </td>
                        <td class="column3 style15 s">
                        </td>
                        <td class="column4 style40 n style41" colspan="2">
                        <input type="submit" name="save_variant" value="Speichern">
                        </td>
                    </tr>
              

                    </form>

                   <tr class="row17">
                        <td class="column0 style14 s"></td>

                        <td class="column1 style40 n style42" colspan="2">
                       
                         <form method="post" action="delete_variant.php" name="delete_<?php echo $variant['id'] ?>">
                            <input type="hidden" name="id" value="<?php echo $variant['id'] ?>">
                            <input type="hidden" name="img_id" value="<?php echo $prod['id'] ?>">
                            <input type="hidden" name="img_path" value="<?php echo $prod['path'] ?>">
                            <input type="hidden" name="type" value="variant">
                            <input type="hidden" name="location" value="<?php echo $_SERVER['REQUEST_URI'] ?>">
                            <input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id'] ?>">
                            <input type="hidden" name="sessionID" value="<?php echo $_SESSION['sessionID'] ?>">
                            <input type="hidden" name="time" value="<?php echo $_SESSION['time'] ?>">
                            <input type="submit" name="select_variant" value="Löschen" style="align:center">
                        </form>
                      
                        </td>
                        <td class="column3 style15 s" style="font-size:14px; text-align:center;font-weight:bold">
                        <form method="post" action="drucker.php" name="<?php echo $variant['id'] ?>">
                            <input type="hidden" name="id" value="<?php echo $variant['id'] ?>">
                            <input type="hidden" name="img_id" value="<?php echo $prod['id'] ?>">
                            <input type="hidden" name="img_path" value="<?php echo $prod['path'] ?>">
                            <input type="hidden" name="type" value="variant">
                            <input type="hidden" name="location" value="<?php echo $_SERVER['REQUEST_URI'] ?>">
                            <input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id'] ?>">
                            <input type="hidden" name="sessionID" value="<?php echo $_SESSION['sessionID'] ?>">
                            <input type="hidden" name="time" value="<?php echo $_SESSION['time'] ?>">
                            <input type="submit" name="select_variant" value="Auswählen" style="align:center">
                        </form>
                        </td>
                        <td class="column4 style40 n style41" colspan="2">
                        </td>
                    </tr>
                    </tbody>
                </table>

        </div>
        <?php
       
    }

?>
 
Zuletzt bearbeitet:
Gemäss Doku zu PDO->prapare, muss ein execute folgen in dem die Paramter übergeben werden.
Oder schöner, du bindest vorher ein Wert/Variable an dein Parameter
PHP:
$currentUser = 1234;
$req = $dbConnect->query($product);
$req->bindParam(':CURRENT_USER', $currentUser, PDO::PARAM_INT);
$req->execute();
//TODO Mit fetch() über dieDaten iterieren
 
Gemäss Doku zu PDO->prapare, muss ein execute folgen in dem die Paramter übergeben werden.
Oder schöner, du bindest vorher ein Wert/Variable an dein Parameter
PHP:
$currentUser = 1234;
$req = $dbConnect->query($product);
$req->bindParam(':CURRENT_USER', $currentUser, PDO::PARAM_INT);
$req->execute();
//TODO Mit fetch() über dieDaten iterieren

danke für den Vorschlag, aber leider werden die variantes nicht sichbar, werden zwar erstellen aber nur in der Datenbank sichbar
 
Hä? Dein Script von weiter oben erstellt gar nix in der Datenbank.
Wahrscheinlich hast du mein Beispiel falsch umgesetzt. Etwa in Zeile 37b432Hji443254. Ja, da müsste der Fehler sein,
 
Hä? Dein Script von weiter oben erstellt gar nix in der Datenbank.
Wahrscheinlich hast du mein Beispiel falsch umgesetzt. Etwa in Zeile 37b432Hji443254. Ja, da müsste der Fehler sein,

so wurde es in meinem Script umgesetzt kann du noch mal bitte das ganze Script oben schauen
PHP:
<?php

require_once __DIR__ . '/connection.php';

$product = 'SELECT * FROM product WHERE id = '.$prodId;
$currentUser = 1234;
$req = $dbConnect->query($product);
$req->bindParam(':CURRENT_USER', $currentUser, PDO::PARAM_INT);
$req->execute();
$prod    = $req->fetch(PDO::FETCH_ASSOC);


?>
 
Zurück