Hi, can anyone show a very simple way to upload values into a database by clicking a button in a php file?
Can someone show me a very simple way
Started by thesquirrel16, Apr 22 2007 06:43 PM
6 replies to this topic
#1
Posted 22 April 2007 - 06:43 PM
|
|
|
#2
Posted 22 April 2007 - 08:54 PM
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.
I'll show you the simplest way to do it, you can then continue further with the code.
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.
<!-- 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.
$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.
#3
Posted 22 April 2007 - 09:15 PM
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
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
#4
Posted 22 April 2007 - 09:21 PM
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?
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?
#5
Posted 22 April 2007 - 09:42 PM
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.
Yes.
All the uploading stuff is in the PHP-file.
"thesquirrel16" said:
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?
#6
Posted 22 April 2007 - 10:31 PM
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?
#7
Posted 23 April 2007 - 04:04 AM
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.
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.


Sign In
Create Account


Back to top









