Uploading Pictures to mysql - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Uploading Pictures to mysql

sweeneysweeney Posts: 117Member
Hi, I am developing a website for a magazine shop! and In the admin page i have add new product, the product has 5 fields, ProdID is an auto increment, ProdName, ProdDiscrip, ProdCost and ProdPic. The Problem I am having is with the ProdPic, This is to hold the picture of the magazine, I have tried saving it as a blob, then saving it as text but its just keeps coming up with the box with a red x. I am using a brows button to find the file and write it to the php page. I echo what the value of the brows feild, for example my images are saved in an image folder, U:wwwwishingimagesactionfigures.jpg but in the mysql database there are no . here is the code I have so far:

Html Add New Prod



Insert New Product

This Page Will Allow You To Insert A New Product

Press To Go Back To Admin Page!

Product Name:

Product Discription:

Product Cost:

Product Picture







Php Add New Prod



Insert New Product




Press To Go Back To Admin Page!

<?
//Get Values From HTML Form
$prodname = $_POST['prodname'];
$proddiscript = $_POST['proddiscript'];
$prodcost = $_POST['prodcost'];
$prodpic = $_POST['pic'];
echo $prodpic;

$user = "root";
$password = "no";
$database = "wishingwell";


// Connect to Database
mysql_connect("localhost",$user);
@mysql_select_db($database) or die("Please Contact A Member Of Adminatration!");

// Query
$query = "INSERT INTO tblproducts VALUES('','$prodname','$proddiscript','$prodcost','$prodpic')";
mysql_query($query);

// Close Database
mysql_close();
// Message
echo "New Product Added";

?>




View Products php



View Products

Press To Go Back To Admin Page!








<?

$user = "root";
$password = "no";
$database = "wishingwell";

// Connect To The Database
mysql_connect("localhost",$user);
@mysql_select_db($database) or die("Try Again If This Message comes up conntact Adminatration!");

// Query
$query = "Select * From tblproducts";
mysql_query($query);

//number of records
$result = mysql_query($query);
$num = mysql_numrows($result);

// print number of records
echo "<b> There Are $num Products Saved";

// Close database
mysql_close();

// Inizialise counter
$i=0;

//Create A While loop so that it will loop through all records puting the values under the headings
while ($i < $num)
{ // Start While loop

//Put all values from database into varables
$prodID=mysql_result($result,$i,"ProdID");
$prodname=mysql_result($result,$i,"ProdName");
$proddis=mysql_result($result,$i,"ProdDiscrip");
$prodcost=mysql_result($result,$i,"ProdCost");
$prodpic=mysql_result($result,$i,"ProdPic");

?>








<?

// Incroment Counter
$i++;

} // End While Loop

?>



Thank You For Reading This, and I hope Someone Has The Answer
Product ID Product Name Product Discription Product Cost Product Picture
<? echo $prodID; ?> <? echo $prodname; ?> <? echo $proddis; ?> <? echo $prodcost; ?> image">

Comments

  • treshrtreshr Posts: 326Member
    [b][red]This message was edited by Moderator at 2005-3-11 1:7:17[/red][/b][hr]
    The thing you could do is to create a config file that holds a constant that refers to the directory that holds the pictures. Together with only the name of the file saved into a field in the database with the path picked up from the constant should show you the picture.

    I created a conf file that looks like this:
    [code]
    <?php
    define("HOSTNAME", "localhost");
    define("USERNAME", "gebruiker");
    define("PASSWORD", "gebruiker99");
    ?>
    [/code]

    Hope this helps you a bit.

    Good luck,

    --=][tReShR][=--



Sign In or Register to comment.