Help, how do I save the image path in my bank?

Asked

Viewed 26 times

-1

I wanted to create an imagem_prod field and do the Insert, as I do?

images are in this folder C:/xampp/htdocs/(project/img/products)?

CREATE TABLE produtos (
  id int NOT NULL auto_increment primary key,
  nome varchar(255) NOT NULL,
  preco decimal(10,2) NOT NULL
) ENGINE=InnoDB; 


INSERT INTO produtos (nome, preco) VALUES
('Presente Amor Completo', '139.99'),
('Arranjo Luz e Amor', '89.99'),
('Buquê 12 Rosas Vermelhas', '119.99'),
('Arranjo Nobre de Orquideas Lilases', '150.00');

  • A string containing the full text of the path to the image?

  • You could show how the structure looks with a field like this?

  • 1

    varchar path(1024).

  • and how it looks in the?

  • It is a text like any other text.

  • could you write, please? I don’t know how the structure of a field’s Insert looks like.

  • INSERT INTO products (name, price, image) VALUES ('Present Complete Love', 139.99, 'C:/xampp/htdocs/project/img/products/prodx.jpg'); or something similar.

  • thanks, I’ll test.

Show 3 more comments

1 answer

0

You could do it this way;

CREATE TABLE produtos (
  id int NOT NULL auto_increment primary key,
  nome varchar(255) NOT NULL,
  preco decimal(10,2) NOT NULL,
  url_imagem TEXT
) ENGINE=InnoDB; 


INSERT INTO produtos (nome, preco, url_imagem ) VALUES
('Presente Amor Completo', '139.99','C:/xampp/htdocs/projeto/img/produtos/presente.jpg'),
('Arranjo Luz e Amor', '89.99','C:/xampp/htdocs/projeto/img/produtos/arranjo.jpg'),
('Buquê 12 Rosas Vermelhas', '119.99','C:/xampp/htdocs/projeto/img/produtos/buque.jpg'),
('Arranjo Nobre de Orquideas Lilases', '150.00','C:/xampp/htdocs/projeto/img/produtos/orquideas.jpg');

I used the Field url_image of the kind TEXT so that this column can receive a larger number of characters if the file path is too large.

I hope I’ve helped.

  • But when I display by php on the screen appears only as text, which I’m missing?

  • You have the way in the bank, when redeem this amount you have to put it in a tag <img>. An example "<img src='". $data['url_image']." ' />"; in this way you will pass the path to an image element.

  • I’ll test this way

  • <?php "<img src='". $product['path']." ' />" ? > --- I put it like this, but the database image does not appear

  • Come on. First what method are you doing to recover the database data? you’re using php from what I’ve seen. Show me the loop you’re doing to display the products. Just to confirm, when you access the image paths through the browser they are displayed?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.