SnakeFox Posted June 25, 2008 Share Posted June 25, 2008 I have a table listing products, and each row corresponds to one product's data. One cell of the row is reserved for the product's image. I want the administrator to have the possibility to edit the table by adding products' data through a form, and, in that form, upload an image which would be saved in a folder. Its path would be saved in the database's table for the images, which has a foreign key that links each image to the respective product. When i click the button that sends all the information to the database, the image also uploads correctly. Only, its path isn't saved in the database. And i have absolutely no idea how to assign the foreign key to the image AND display it in the table right away at the same time the rest of the data from the product is registered in the db. Here's the code, most of the names are in portuguese, but what's important is translated: The form: <form enctype="multipart/form-data" action="inserir_produto.php" method="post"> <table> <tr><td>Name:</td> <td><input type="text" name="nome"></td></tr> <tr><td>Category:</td> <td><select name="categorias" value="Categorias"> </select></td> <td><input type="submit" name="button_categoria" value="Inserir nova categoria"></td> </tr> <tr><td>Supplier:</td> <td><select name="fornecedores"> </select></td></tr> <tr><td>Label:</td> <td><input type="text" name="marca"></td></tr> <tr><td>Supplier's price:</td> <td><input type="text" name="preco_fornecedor"></td></tr> <tr><td>Final price:</td> <td><input type="text" name="preco_final"></td></tr> <tr><td>Quantity:</td> <td><input type="text" name="quantidade"></td></tr> <tr><td>Image:</td> <input type="hidden" name="tamanho_max" value="100000"> <td><input type="file" name="imagem"></td></tr> </table> <br /><input type="submit" value="Insert data" name="Insert_button"> </form> When "Insert_button" is clicked: if($_POST['insert_button']){ $path="Imagens/"; $path=$path.basename($_FILES['imagem']['name']); $FILES['imagem']['tmp_name']; if(move_uploaded_file($_FILES['imagem']['tmp_name'], $path)) { echo "O ficheiro ". basename( $_FILES['imagem']['name']). " foi guardado";} else{echo "Erro, tente de novo!";} $image_query=mysql_query("INSERT INTO imagens (path) VALUES($path)",$connection); $adicionar=mysql_query("INSERT INTO produtos (nome,marca,fornecedor,preco,preco_fornecedor,quantidade_stock,categoria) VALUES('$nome','$marca','$fornecedor','$preco_final','$preco_fornecedor','$quantidade','$categoria')",$connection); } So i ask why isn't the file's path registered in the database, and how do I assign the foreign key to the product that has just been added and display the image in that product's row all the once through the click on the "Insert_button"? Link to comment https://forums.phpfreaks.com/topic/111892-insert-database-image-in-table-cell/ Share on other sites More sharing options...
SnakeFox Posted June 25, 2008 Author Share Posted June 25, 2008 Can somebody help me, please? If i'm not making myself very clear, do say so - I'm not a native english speaker, so my proficiency is a bit floppy. But please, it's really important - it's for a school project that counts 10% of my high school grade point average, and i have only 2 days to finish it... Link to comment https://forums.phpfreaks.com/topic/111892-insert-database-image-in-table-cell/#findComment-574464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.