Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-13-2009, 02:59 PM insert images....
Junior Talker

Posts: 2
Trades: 0
Hi, i have wrote forms that allow me to upload images and save into the folder and send image file path name to the database, i have run it and test is works fine when save images into the folder but is not sending data to the mysql database. i'm not sure what went wrong but the result is not telling us the errors. it said it has send to database but the truth is not sending to database.
This is mysql table name
please create folder name images
Code:
CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo VARCHAR(30))
this index.php form page
Code:
<form enctype="multipart/form-data" action="add.php" method="POST"> 
Name: <input type="text" name="name"><br> 
E-mail: <input type="text" name = "email"><br> 
Phone: <input type="text" name = "phone"><br> 
Photo: <input type="file" name="photo"><br> 
<input type="submit" value="Add"> 
</form>
this is retrieve information from index.php page
Code:
<?php 
//This is the directory where images will be saved 
$target = "images/"; 
$target = $target . basename( $_FILES['photo']['name']); 
//This gets all the other information from the form 
$name=$_POST['name']; 
$email=$_POST['email']; 
$phone=$_POST['phone']; 
$pic=($_FILES['photo']['name']); 
// Connects to your Database 
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()) ; 
mysql_select_db("Database_Name") or die(mysql_error()) ; 
//Writes the information to the database 
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 
//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{ 
//Tells you if its all ok 
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
} 
else { 
//Gives and error if its not 
echo "Sorry, there was a problem uploading your file."; 
} 
?>
and this final step to view it.
Code:
<?php 
// Connects to your Database 
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()) ; 
mysql_select_db("Database_Name") or die(mysql_error()) ; 
//Retrieves data from MySQL 
$data = mysql_query("SELECT * FROM employees") or die(mysql_error()); 
//Puts it into an array 
while($info = mysql_fetch_array( $data )) 
{ 
//Outputs the image and other data
Echo "<img src=http://www.yoursite.com/images/".$info['photo'] ."> <br>"; 
Echo "<b>Name:</b> ".$info['name'] . "<br> "; 
Echo "<b>Email:</b> ".$info['email'] . " <br>"; 
Echo "<b>Phone:</b> ".$info['phone'] . " <hr>"; 
}
?>
please help thanks.
AM
Alidad@comcast. is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-13-2009, 05:30 PM Re: insert images....
Corey's Avatar
Super Talker

Latest Blog Post:
Pre-Pop Offers
Posts: 142
Name: Corey
Location: United States
Trades: 0
Add
PHP Code:
or die(mysql_error()); 
to the end of all your MySQL querys.

I tested that script and every thing inserted into the DB.
__________________

Please login or register to view this content. Registration is FREE

Phone: 888-400-4359 || AIM S/N: CoreyPeerFly
Launched in 2008 - Daily Payments by PayPal

Last edited by Corey; 09-13-2009 at 05:46 PM..
Corey is offline
Reply With Quote
View Public Profile Visit Corey's homepage!
 
Old 09-15-2009, 03:09 AM Re: insert images....
Experienced Talker

Posts: 46
Trades: 0
Just out of curiosity why are you storing your photos in the database? Just store them in a folder on your webserver...

If you really have to store them in the database I think you need to increase the size of your photo field in the database.
__________________

Please login or register to view this content. Registration is FREE
-> Home of the crasher squirrel
jeff_oneil is offline
Reply With Quote
View Public Profile Visit jeff_oneil's homepage!
 
Old 09-16-2009, 04:24 PM Re: insert images....
Junior Talker

Posts: 3
Name: Jay
Trades: 0
Quote:
Originally Posted by jeff_oneil View Post
Just out of curiosity why are you storing your photos in the database? Just store them in a folder on your webserver...

If you really have to store them in the database I think you need to increase the size of your photo field in the database.
Wouldn't that script copy the images to a folder and the URL to the database?
FRAZL is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to insert images....
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22376 seconds with 12 queries