PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Uploading Pictures to mysql Posted by sweeney on 7 Mar 2005 at 2:19 PM
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:\www\wishing\images\actionfigures.jpg but in the mysql database there are no \. here is the code I have so far:

Html Add New Prod

<html>
<head>
<title> Insert New Product </title>
</head>

<p><b> This Page Will Allow You To Insert A New Product </b></p>
<p><a href="Adminpage.html">Press To Go Back To Admin Page! </a></p>
<form action="InsertnewProd.php" method="POST">
<p> Product Name: <input type="text" name="prodname">
<p> Product Discription: <textarea name="proddiscript"></textarea>
<p> Product Cost: <input type="text" name="prodcost">
<p> Product Picture <input type="file" name="pic">
<p><input type="submit" value="Add Product" style="background: #ff3600; font-weight: bold"> <input type="reset" value="Clear" style="background: #fff862; font-weight: bold">
</form>

</body>
</html>

Php Add New Prod

<html>
<head>
<title> Insert New Product </title>
</head>

<body>

<p><a href="Adminpage.html">Press To Go Back To Admin Page! </a></p>
<?
//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";

?>

</body>
</html>

View Products php

<html>
<head>
<title> View Products </title>
</head>

<body>
<p><a href="Adminpage.html">Press To Go Back To Admin Page! </a></p>
<table border="1" cellspacing ="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif"> Product ID </font></th>
<th><font face="Arial, Helvetica, sans-serif"> Product Name </font></th>
<th><font face="Arial, Helvetica, sans-serif"> Product Discription </font></th>
<th><font face="Arial, Helvetica, sans-serif"> Product Cost </font></th>
<th><font face="Arial, Helvetica, sans-serif"> Product Picture </font></th>
<?

$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");

?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $prodID; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $prodname; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $proddis; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $prodcost; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><img src="<? print $prodpic;?>"></font></td>
<tr>
<?

// Incroment Counter
$i++;

} // End While Loop

?>
</body>
</html>

Thank You For Reading This, and I hope Someone Has The Answer
Report
Re: Uploading Pictures to mysql Posted by treshr on 11 Mar 2005 at 1:07 AM
This message was edited by Moderator at 2005-3-11 1:7:17

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:
<?php
	define("HOSTNAME", "localhost");
	define("USERNAME", "gebruiker");
	define("PASSWORD", "gebruiker99");
?>


Hope this helps you a bit.

Good luck,

--=][tReShR][=--






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.