Ehm... posso continuare qui anche se non è per le categorie? Più o meno è la stessa cosa, invece delle categorie è per la gestione delle immagini...
Cooomunque... devo poter caricare delle immagini alle quali assegnare categoria e autore (gestione categoria e autori già fatta e funzionante).
newimage.php
imglist.phpcodice:<?php include("include/database.php"); if (isset($_POST['immagine'])): $aid = $_POST['aid']; $immagine = $_POST['immagine']; $cats = $_POST['cats']; if ($aid == '') { exit(' You must choose an author for this image. Click "Back" and try again.</p>'); } $sql = "INSERT INTO immagini SET immagine='$immagine', authorid='$aid'"; if (mysql_query($sql)) { echo ' New image added</p>'; } else { exit(' Error adding new image: ' . mysql_error() . '</p>'); } $jid = mysql_insert_id(); if (isset($_POST['cats'])) { $cats = $_POST['cats']; } else { $cats = array(); } $numCats = 0; foreach ($cats as $catID) { $sql = "INSERT IGNORE INTO photocategory SET imgid=$jid, categoryid=$catID"; $ok = mysql_query($sql); if ($ok) { $numCats = $numCats + 1; } else { echo " Error inserting image into category $catID: " . mysql_error() . '</p>'; } } ?> Image was added to <?php echo $numCats; ?> categories.</p> Add another image</p> Return to image search</p> <?php else: // Allow the user to enter a new image $authors = mysql_query('SELECT id, name FROM author'); if (!$authors) { exit(' Unable to obtain author list from the database.</p>'); } $cats = mysql_query('SELECT id, name FROM category'); if (!$cats) { exit(' Unable to obtain category list from the database.</p>'); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Enter the new image: <form enctype="multipart/form-data" action="".$_SERVER['PHP_SELF']."" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="300000" /> <input type="file" name="immagine" size="40" /> Author: <select name="aid" size="1"> <option selected value="">Select One</option> <option value="">---------</option> <?php while ($author = mysql_fetch_array($authors)) { $aid = $author['id']; $aname = htmlspecialchars($author['name']); echo "<option value='$aid'>$aname</option>\n"; } ?> </select></p> Place in categories: <?php while ($cat = mysql_fetch_array($cats)) { $cid = $cat['id']; $cname = htmlspecialchars($cat['name']); echo "<label><input type='checkbox' name='cats[]' value='$cid' />$cname</label> \n"; } ?> </p> <input type="submit" value="SUBMIT" /> </form> <?php endif; ?>
imgsearch.phpcodice:<?php include("include/database.php"); // The basic SELECT statement $select = 'SELECT DISTINCT id, immagine'; $from = ' FROM immagini'; $where = ' WHERE 1=1'; $aid = $_POST['aid']; line 21 if ($aid != '') { // An author is selected $where .= " AND authorid='$aid'"; } $cid = $_POST['cid']; line 26 if ($cid != '') { // A category is selected $from .= ', photocategory'; $where .= " AND id=imgid AND categoryid='$cid'"; } ?> Immagini: <?php $imms = mysql_query($select . $from . $where); if (!$imms) { echo '</p>'; exit(' Error retrieving images from database! '. 'Error: ' . mysql_error() . '</p>'); } while ($imm = mysql_fetch_array($imms)) { echo "</p>\n"; $id = $imm['id']; echo "$imm"; echo "Edit | " . "Delete"; echo "</p>\n"; } ?> </p> New search</p>
Allora, gli errori sono:codice:Insert New Image</p> <?php include("include/database.php"); $authors = @mysql_query('SELECT id, name FROM author'); if (!$authors) { exit(' Unable to obtain author list from the database.</p>'); } $cats = @mysql_query('SELECT id, name FROM category'); if (!$cats) { exit(' Unable to obtain category list from the database.</p>'); } ?> <form action="imglist.php" method="post"> View images satisfying the following criteria:</p> <label>By author: <select name="aid" size="1"> <option selected value="">Any Author</option> <?php while ($author = mysql_fetch_array($authors)) { $aid = $author['id']; $aname = htmlspecialchars($author['name']); echo "<option value='$aid'>$aname</option>\n"; } ?> </select></label> <label>By category: <select name="cid" size="1"> <option selected value="">Any Category</option> <?php while ($cat = mysql_fetch_array($cats)) { $cid = $cat['id']; $cname = htmlspecialchars($cat['name']); echo "<option value='$cid'>$cname</option>\n"; } ?> </select></label> <input type="submit" value="Search" /> </form> Return to home page</p>
Notice: undefined index: aid in imglist.php on line 21
Notice: undefined index: cid in imglist.php on line 26
e poi quando eseguo la pagina imglist.php mi da la lista delle immagini ma NON stampa l'immagine, scrive:
Array Edit | Delete
Sicuramente ci sono degli errori perchè era un codice per dei files di testo e io l'ho riadattato per le immagini... ma non so davvero cos'altro fare!

Rispondi quotando