Inserting path of image in SQL without embedding in code

Hi. I understand that there are a good few questions already asked about how to insert an image into the database. After looking through the answers the best solution seems to insert the path of the image into the database. This makes sense and this is how I intend to do it.

However every example seems to involve using the INSERT INTO statement in PHP code. I don't want to insert the path of an image embedded in code. I want to just insert it through the normal SQL interface. Is this possible or must all inserts of paths of images be through code like PHP etc?

Also I'm using XAMPP. Where should I store my images?
graziaziAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tsmgeekCommented:
download MySQL Administrator Tools or HeidiSQL  and you can edit tables/data  from Windows/Linux, it also admins the server
0
graziaziAuthor Commented:
With XAMPP I have a way of executing SQL statements through the web browser. I'm just not sure how to insert the path for an image
0
Dave BaldwinFixer of ProblemsCommented:
If you're talking about 'phpmyadmin', go to the database and table that you want to modify and click on the Insert tab at the top.  That will bring up a form with the fields for that table where you can enter the path info in the correct field.  You will also need to know the info for the rest of the fields when you do that.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dave BaldwinFixer of ProblemsCommented:
Note that 'phpmyadmin' is PHP code for administering MySQL databases.  The MySQL server uses other programs to interact with the database.  Even the 'mysql' command line is just a program that talks to the server software, it is not part of the server itself.  

As for 'INSERT statements in PHP', that is the method commonly used to make a page where the web site users or admins can add info to the database.  By adding it 'behind the scenes' yourself, that means the web sites users don't have a method to add or change the info themselves.  Which is fine if that's what you want.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
graziaziAuthor Commented:
Thanks for that. Could you me an example of a path? And is it in quotes?
0
Dave BaldwinFixer of ProblemsCommented:
The path depends on how you are going to use it.  A path tells a program where to find the file.  If you are using it in a web page, you could make it a 'relative' path like 'image/mypic.jpg' or an absolute path like 'http://www.mysite.com/image/mypic.jpg'.  If you are using it in a desktop program, the path for the same pic might be 'C:\\Inetpub\wwwroot\images\mypic.jpg'.

If you are using the form in phpmyadmin, you don't need to use quotes.  If you are building an INSERT statement in PHP, you need to use single quotes because it is text and not a number.
0
graziaziAuthor Commented:
Ok, attached is my code that retrieves the image id and an attempt to retrieve to the image from the database. When I tried it I got the actual path. Excuse my ignorance. What am I doing wrong here that stops the image from displaying?
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("project", $con);

$result = mysql_query("SELECT * FROM image");

echo "<table border='1'>
<tr>
<th>id</th>
<th>image</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['idImage'] . "</td>";
  echo "<td>" . $row['path'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

Open in new window

0
graziaziAuthor Commented:
This was the insert statement I used...........

INSERT INTO `project`.`image` (`idImage`, `path`) VALUES ('1', '\\xampp\\img\\status4.gif')

0
Dave BaldwinFixer of ProblemsCommented:
You are saving the path in the operating system instead of the path thru the web server.  Try this instead.
INSERT INTO `project`.`image` (`idImage`, `path`) VALUES ('1', 'img/status4.gif')

Open in new window

0
Dave BaldwinFixer of ProblemsCommented:
In addition, the 'web root' where the web pages are stored in XAMPP is 'C:\\xampp\htdocs'.  Web servers normally do not allow access to files outside the 'web root'.  Your 'img' directory needs to be in the directory where your web pages are stored.
0
graziaziAuthor Commented:
I created a folder called img in htdocs and executed your INSERT statement. What is returned is img/status4.gif'. I think there's something fundamental I'm doing wrong
0
Dave BaldwinFixer of ProblemsCommented:
Actually, that sounds right to me.  How are you getting to that page?  What are you typing in your browser?
0
graziaziAuthor Commented:
0
Dave BaldwinFixer of ProblemsCommented:
The row with the path needs to have it inside an 'img' tag for the image to be displayed.  Like this:
echo "<td><img src='" . $row['path'] . "'/></td>";

Open in new window

0
graziaziAuthor Commented:
Success! Dave thanks very much for your patience. This will get the ball rolling
0
Dave BaldwinFixer of ProblemsCommented:
Good, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.