Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > Database & Database Programming

Database & Database Programming MySQL, Oracle, SQL, PL/SQL, ABAP, Smart Forms, and other databases and languages. A database is an organized body of related information used in many websites (including CC).

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-22-2007, 10:43 PM
thesquirrel16 thesquirrel16 is offline
Newbie
 
Join Date: Apr 2007
Posts: 12
Rep Power: 0
thesquirrel16 is on a distinguished road
Default Can someone show me a very simple way

Hi, can anyone show a very simple way to upload values into a database by clicking a button in a php file?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-23-2007, 12:54 AM
v0id's Avatar   
v0id v0id is online now
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,635
Last Blog:
CherryPy(thon)
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

It's actually pretty easy to upload files, using PHP.
First of all, you need a form. The form have to have a enctype set to multipart/form-data. The input-tag you're using is gonna have file as type.
Code:
<!-- upload.php (could even be upload.htm, because here's no PHP) -->

<form method="post" action="uploaded.php" enctype="multipart/form-data">
    <b>Your file:</b><br />
    <input type="file" name="file" /><br />
    <input type="submit" value="Upload file" />
</form>
Now the easiest part is over, and we're going to use PHP - to do the rest.
I'll show you the simplest way to do it, you can then continue further with the code.
Code:
$upload_path = "uploads/";
$upload_path = $upload_path . basename($_FILES["file"]["name"]);
$status = move_uploaded_file($_FILES["file"]["tmp_name"], $upload_path);

if($status)
    echo "<b>" . basename($_FILES["file"]["name"]) . "</b> uploaded!<br />";
else
    echo "Error while uploading <b>" . basename($_FILES["file"]["name"]) . "</b><br />";
Try using Google, or check out www.php.net.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-23-2007, 01:15 AM
thesquirrel16 thesquirrel16 is offline
Newbie
 
Join Date: Apr 2007
Posts: 12
Rep Power: 0
thesquirrel16 is on a distinguished road
Default

Thank you for the reply, I have a couple questions: How does the code know what it is submitting when the button is clicked?

is the second part of code the upload.php file? or does that go into the base file?

I am trying to have a string of texts from a textbox uploaded into a database table when the submit button is clicked. This shows how to upload a file? <-- big newb here, you gotta type slow for me =p
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-23-2007, 01:21 AM
thesquirrel16 thesquirrel16 is offline
Newbie
 
Join Date: Apr 2007
Posts: 12
Rep Power: 0
thesquirrel16 is on a distinguished road
Default

Ok ok, on the <form method="post" action="uploaded.php" enctype="multipart/form-data"> line, the action= "uploaded.php" actually has nothing to do with the data being uploaded? its just the page that is called after the button is clicked?

And the post method, how does it know what to post?

And lol if you have more than one button how do you specify different actions for each?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-23-2007, 01:42 AM
v0id's Avatar   
v0id v0id is online now
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,635
Last Blog:
CherryPy(thon)
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

If the input-tag's type is set to file, like in my example, the browser will create an input-box AND a button, which the user press and a pop-up with all you files in it, and then the user can choose. The only thing the forms does is sending the filename to the next-page, nothing else.
All the uploading stuff is in the PHP-file.

Quote:
Originally Posted by thesquirrel16
action= "uploaded.php" actually has nothing to do with the data being uploaded? its just the page that is called after the button is clicked?
Yes.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-23-2007, 02:31 AM
thesquirrel16 thesquirrel16 is offline
Newbie
 
Join Date: Apr 2007
Posts: 12
Rep Power: 0
thesquirrel16 is on a distinguished road
Default

Ah ok, that clears things up a lot, one last thing, if I want to pass a value such as $Title to my updated.php to upload into a database, how do i do that?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-23-2007, 08:04 AM
v0id's Avatar   
v0id v0id is online now
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,635
Last Blog:
CherryPy(thon)
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

If you're gonna insert something into some database, you aren't going to do it in that way. Most databases, if not all, have some kind of API or framework to communicate with PHP - or another programming language. F.ex. PHP and MySQL.

I've only experience with PHP and the MySQL-database, but try take a search with Google or some other search engine to find information about the database you're using and/or programming language.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Project: ionFiles - Joomla Simple File Download Jordan Community Projects 324 11-10-2008 08:34 PM
Project: ionFiles - Joomla Simple File Download - Mirror 2 Jordan ionFiles 6 11-06-2008 01:24 PM
Simple Hex-Editing TcM Tutorials 31 11-01-2008 10:51 AM
Simple gallery Jaan PHP Tutorials 27 05-19-2008 05:56 PM
[Solved] yes/no box missing show release date rolandd ionFiles 4 07-26-2007 01:44 PM


All times are GMT -5. The time now is 12:15 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads