473,769 Members | 3,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem to store and retrive image in php

6 New Member
The below code can't take the images.plz tell that what is the problem in that code
[php]
<?php

// Connect to database

$errmsg = "";
if (! @mysql_connect( "localhost","ro ot","sreeni") ) {
$errmsg = "Cannot connect to database";
}
@mysql_select_d b("my_db1");

// First run ONLY - need to create table by uncommenting this
// Or with silent @ we can let it fail every sunsequent time ;-)

$q = <<<CREATE
create table pix (
pid int primary key not null auto_increment,
name varchar(20),ema il varchar(30),cit y varchar(20),sta te varchar(20),zip int(7),country varchar(20),mon th varchar(20),dat e int(3),imgdata longblob)
CREATE;
@mysql_query($q );

// Insert any new image into database
if ($_REQUEST[completed] == 1) {
// Need to add - check for large upload. Otherwise the code
// will just duplicate old file ;-)
// ALSO - note that latest.img must be public write and in a
// live appliaction should be in another (safe!) directory.
move_uploaded_f ile($_FILES['upload']['tmp_name'],"latest.img ");
$instr = fopen("latest.i mg","rb");
$image = addslashes(frea d($instr,filesi ze("latest.img" )));
if (strlen($instr) < 149000) {
mysql_query ("insert into pix13(name,emai l,city,state,zi p,country,month ,date,upload) values ('\"". $_POST[name] . "\",\"".$_P OST[email]. "\",\"".$_P OST[city]. "\",\"".$_P OST[state]. "\",\"".$_P OST[zip]. "\",\"".$_P OST[country]. "\",\"".$_P OST[month]. "\",\"".$_P OST[date]. "\",\"". $_POST[whatsit] . "\", \"". $image . "\")");
} else {
$errmsg = "Too large!";
}
}
$gotten = @mysql_query("s elect * from pix order by pid desc limit 1");
if ($row = @mysql_fetch_as soc($gotten)) {
$name = htmlspecialchar s($row[name]);
$email = htmlspecialchar s($row[email]);
$city = htmlspecialchar s($row[city]);
$state = htmlspecialchar s($row[state]);
$zip = htmlspecialchar s($row[zip]);
$country = htmlspecialchar s($row[country]);
$month = htmlspecialchar s($row[month]);
$date = htmlspecialchar s($row[date]);
$bytes = $row[upload];
} else {
$errmsg = "There is no image in the database yet";
// Put up a picture of our training centre
$instr = fopen("latest.i mg","rb");
$bytes = fread($instr,fi lesize("latest. img"));
}
// If this is the image request, send out the image

if ($_POST[gim] == 1) {
header("Content-type: image/jpeg/jpg/zip");
print $bytes;
exit ();
}

?>[/php]

Before you continue: Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that. - moderator
Mar 3 '08 #1
3 2088
bonski
53 New Member
The below code can't take the images.plz tell that what is the problem in that code
what exactly you want to do? upload image file and display it on a webpage?
Mar 3 '08 #2
bonski
53 New Member
ok... i checked your script... for me.. i think you sql statement is having some errors or cant successfully insert the data.. because you lack some single quotes in your $_POST[]...

i think this one
[PHP]mysql_query ("insert into pix13(name,emai l,city,state,zi p,country,month ,date ,upload) values ('\"". $_POST[name] . "\",\"".$_P OST[email]. "\",\"".$_P OST[city]. "\",\"".$_P OST[state]. "\",\"".$_P OST[zip]. "\",\"".$_P OST[country]. "\",\"".$_P OST[month]. "\",\"".$_P OST[date]. "\",\"". $_POST[whatsit] . "\", \"". $image . "\")");[/PHP]


should look like this

[PHP]mysql_query ("INSERT INTO pix13(name, email, city, state, zip, country, month, date, upload) VALUES('".$_POS T['name']."', '".$_POST['email']."', '".$_POST['city']."', '".$_POST['state']."', '".$_POST['zip']."', '".$_POST['country']."', '".$_POST['month']."', '".$_POST['date']."', '".$_POST['whatsit']."', '".$image."')") ;[/PHP]

and for uploading files, you can have a look at this
file uploads
Mar 3 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
The below code can't take the images.plz tell that what is the problem in that code
That is not a clear description of your problem. Please describe it in more detail and let's not make a puzzle of it.

Ronald
Mar 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2320
by: Patrick F | last post by:
Hi, i have a resourcefile with my project that contains a jepg image. Now i want to retrive that image to a Image m_Image in my program. Whats the best way to do this?
0
978
by: chpatel | last post by:
hello, I have serious problem. that must be solved as quickly as possible. I store image (gif, bmp, jpeg) in access database as OLEOBJECT.. Now i want to retrive that image(stored in access) and then insert that image in word document. Well, i already created bookmark in word.But now problem is how can i take that image and put that image in word document. Can any one please help me out??
8
12234
by: hemashiki | last post by:
hi i need help..how can i store image in mysql database and i want to retrive that image can anyone suggest plz
2
1662
by: soma.gunasekaran | last post by:
Hi All , I've stored the Image file..... But i want to retriving the Image files from MSACCSS 2003 (JPEG,bmp,Gif and etc....) So Pls help me........ help me............... Thanking you, Somasundaram G
1
1511
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I have the following code that I used in my application to retive image from database: Dim cnn As New SqlConnection("Data Source=localhost;Initial Catalog=Husam;Integrated Security=True") Dim cmd As SqlCommand Dim sql As String cnn.Open()
1
3358
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title>
2
1623
by: keerthisreenu | last post by:
hai to all...!! iam working with Ms Access 2000. iam saving an image in the database. After that i want to retrive the same image from database and displaying it in the picture box. but its not working. why it is happening? please help me. iam sending the code. when button1 clicks it store in database. when button2 clicks it should display in picturebox.
2
1774
by: Eminosoft | last post by:
I am new to the php. plz tell that code for "how to store image in mysql database and also retrive that image"
0
1923
by: ramuygl | last post by:
want to create store procedure that. want to send the table name as argument and retrive the data of that argument. and want to store data in temperary table using the insert query. HERE I AM ATTACHING A SAMPLE PROCEDURE IT WAS NOT WORKING PERFECTLY. HELP ME --exec SP_Generate_Insert_Statements tbl_Attachment,1 --select * from tbl_Attachmenttesting --exec SP_Generate_Insert_Statements tbl_Attachmenttesting,1 ALTER PROCEDURE .
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.