|
| |||||||
![]() | Welcome to iWEBTOOL Talk, where you talk about
webmaster-related stuff.
1 Register
2 Browse the board
3 Discuss whatever may interest you! | |||||||||||||
![]() |
| | Thread Tools | Search this Thread | Display Modes |
| | #1 |
| Retired Member Join Date: Dec 2005
Posts: 139
![]() | This is how I learned to do these things; works very well and all methods are very flexible. CONNECTING TO DATABASE ---------------------------- PHP Code: INSERTING INTO A DATABASE TABLE ------------------------------------- PHP Code: MODIFYING A DATABASE TABLE -------------------------------- PHP Code: RETRIEVING FROM A DATABASE TABLE --------------------------------------- The more complex part of database interaction... we're also going to set up the variables to USE the values we retrieve in a list, etc. PHP Code: That was the most complex part of this actually simple process. DELETING A ROW FROM A TABLE --------------------------------- PHP Code: CLOSING DATABASE CONNETION --------------------------------- PHP Code: Questions? Examples needed? "How would I" questions? Reply... -Matt
__________________ Retired Moderator/Member/Friend/Helper - it was great working with all of you! |
| | |
|
| |||||||
| | #2 |
| Contributor Join Date: Jun 2006 Location: Denver
Posts: 4,459
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | hey, thanks for that, you included some info I never seen in the several tutorials I've read so far. Good info, I'll refer back to it alot. Thanks again. |
| | |
| | #3 |
| Contributor Join Date: Jun 2006 Location: Denver
Posts: 4,459
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | How would I...Take information in a form, pass it to the php script, and use that information with a table..okay, heres the deal. I want to enter a name into a form, and a file to upload. The name will be selected from a pre-determined drop list. So, when entering these into a new table, how do I use the table.row's primary key as part of the new filename? So.. I enter: grumpy.gif - image to upload and: oldpeople - save file as(from a drop down) submit find oldpeople entry on the directory table point to the table that contains all the oldpeople image info insert the form data in the next available row(what row number?)-this is where I need help. How do you tell what the next available row is going to be in the selected table? from there: move the image to an image folder with the name"oldpeople_$nexttablerow.$fileextension" and send that new file name to the oldpeople table Also, is there a simple way to extract the file extension so I can rename the file appropriately? |
| | |
| | #4 | ||||
| Retired Member Join Date: Dec 2005
Posts: 139
![]() | First, your form tag should look like this: <form method="post" action="php_file_name.php"> Usually you use POST. When you press a submit button, it loads the form action file. If you add a "name" attribute to your form elements (e.g. <input name="put_name_here">), those names turn into PHP variables. They're in an array as in: $_POST['put_name_here'], but you can access them just like any other variable: $put_name_here, and work with them that way. So, if you have a dropdown list named "name", then the PHP variable will be $name. If you are uploading a file, don't forget the following in the FORM tag!! <form method="post" action="php_file_here.php" enctype="multipart/form-data"> I BELIEVE that is the correct enctype but I'm not 100% sure. Maybe somebody could verify this. You can upload images into a database, but it is more recommended that you do it into the file system. As for what you say here: Quote:
I'd rather you just tell me what you want to do, rather than what procedures you take. It'll be easier for me to "get". Quote:
Quote:
SELECT * FROM table_name ORDER BY id DESC LIMIT 1 That is, if you are using IDs. If you aren't, well, it's a little more difficult. Nothing better comes to mind. Quote:
__________________ Retired Moderator/Member/Friend/Helper - it was great working with all of you! | ||||
| | |
| | #5 |
| Contributor Join Date: Jun 2006 Location: Denver
Posts: 4,459
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I can verify that that's the right encryption type. The table I am accessing has a primary key thats set auto_increment. The name of the primary field is id. I am not changing the extension of the image, I want to change the file name, so I want to strip the original name out, and replace it with a common name with the tables id # concantenated at the end...like this.... thisgif_01.gif - thisgif_02.gif - thisgif_03.gif - thisgif_04.jpg and so on. Okay, so what I got so far is a form like following name: keywords: metadescription: imagename: description: In php, I want to put most of that into a table row that corresponds to the name: form field. In other words a table named $name. The name tables have all already been created, and the name: field is a drop down list. So...most of it will be easy, cause I just have to put the correct info into the correct field of the table. The hard part is changing the images original name to be $name.$idnumberintable.'.'.$originalextension. For example...I upload an image named boogy.jpg and the name field is harlem_globetrotters. The next available id# is 3, sooo....I want it to be renamed "harlem_globetrotters_03.jpg" Also, i inserted the code you gave me from above.. $var=mysql_query('SELECT BY DESC ORDER');, is there a way to echo the contents of that varialble if their isnt any records in the table yet? |
| | |
| | #6 |
| Member Join Date: Dec 2005
Posts: 132
![]() | use var_dump() function. But as it doesn't contain any value, it will most probably be a null value. Frankly, I didn't really understand what you intended to do, but I gave my answer on the basis of whatever I did understand.
__________________ Eat healthy, Stay Fit, Die Anyway. --==-- If there is a man who knows everything about women, there is a Windows distribution without bugs. |
| | |
| | #7 |
| Contributor Join Date: Jun 2006 Location: Denver
Posts: 4,459
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I apologize, I still am new to this, so explaining myself can be difficult. I appreciate you taking the time to dredge through my nonsense and coming up with the best answer you could. If anyone has tips as to how to explain myself better, I am all ears. |
| | |
| | #8 | |
| Retired Member Join Date: Dec 2005
Posts: 139
![]() | Quote:
And, no, if there's nothing in the table it can't be displayed...
__________________ Retired Moderator/Member/Friend/Helper - it was great working with all of you! | |
| | |
| | #9 |
| Contributor Join Date: Jun 2006 Location: Denver
Posts: 4,459
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | SELECT * FROM table_name ORDER BY id DESC LIMIT 1 Sorry, I wasn't being literal. I used the exact query you gave me, I will be more specific next time. So I did all the stuff I was asking, would it help others if I posted how I did it? |
| | |
| | #10 |
| Retired Member Join Date: Dec 2005
Posts: 139
![]() | In a new thread, yeah, they'd find that helpful.
__________________ Retired Moderator/Member/Friend/Helper - it was great working with all of you! |
| | |
| | #11 |
| Contributor Join Date: Jun 2006 Location: Denver
Posts: 4,459
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Okay, I will do that then. I am going to fine tune the whole script, then post it probably tonight or tommorow. |
| | |
| | #12 |
| Newcomer Join Date: Oct 2006
Posts: 1
![]() | You should extend this list, seems pretty useful so far. I find print_r() one of the most useful functions (to display the contents of an array or object).
__________________ http://www.pipeten.com/resellers.html |
| | |
| | #13 |
| Smurf Join Date: Jun 2006 Location: Maine
Posts: 31
![]() | Double quotes must be parsed for variables; I diligently use single quotes so that I am in the habit of writing "faster by default". Original PHP Code: PHP Code: I also define table names for scalability. This can save a LOT of time if an application starts to get big and muddy and you need to change a table name. PHP Code: Note: Of course only define table names once in a header/config file.
__________________ phpLinkBid - The #1 bid for position script |
| | |
| | #14 |
| Smurf Join Date: Jan 2008
Posts: 9
![]() | I do professional MySQL and PHP programming. If you need some assistance please feel free to ask.
__________________ I rely on http://www.countryipblocks.net/ for added security |
| | |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MSSQL or MySQL? | loon | Web Hosting | 3 | 11-20-2006 10:43 AM |
| Remotely Accessing MySQL Database? | compuXP | MySQL | 4 | 08-31-2006 05:05 AM |
| MySql | jumpenjuhosaphat | PHP | 6 | 07-10-2006 10:04 PM |
| Common domain status codes | kenni | Domain Name | 1 | 12-31-2005 05:25 AM |