This is a discussion on "Coding help: Combine Insert into and If/else statement!" within the PHP Forum section. This forum, and the thread "Coding help: Combine Insert into and If/else statement! are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Coding help: Combine Insert into and If/else statement!
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Coding help: Combine Insert into and If/else statement!
Hi, I´m in need of coding help, again
The PHP file I´m working with has three <php ...?> sections. #1 - First code is for a Captcha code. #2 - Second code takes an image from the previous page, saves it to a directory and sends it´s path to a database. #3 - Third code saves input data from the previous page to a database. Right now, these ALL work separately. But when combined I´m having two issues (due to lack of knowledge). Problem A) I added a IF/ELSE statement to the #2 code that is not working ('if' @ line 22. 'else' @ line 27 and 'else' closes at line 194) . That´s no surprise as I´m a beginner. What I want with this IF/ELSE statement is: IF there is no image uploaded (if (empty($img_name)) then the string "No image" should be inserted into the database/table (column = Mynd). ELSE continue with the code that possesses the image and insert it´s path to the database/table. Problem B) If I skip the IF/ELSE statement the image is uploaded correctly and the path is inserted into my database. But as a seperate INSERT function from #3. So there are two lines that get inserted into the database instead of one. I know that in the below code I´m connecting TWICE to the database but I tried combining the connection and INSERT to table function with no luck. Here is the code from my PHP file:
P.s.: The code is very ugly right now.... still a lot of work to do. Last edited by skuliaxe; Jan 23rd, 2008 at 16:50. |
|
|
|
||||
|
Re: Coding help: Combine Insert into and If/else statement!
I don't see $img_name defined anywhere before that if statement, so it should always evaluate to true.
this should work instead:
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
|||
|
Re: Coding help: Combine Insert into and If/else statement!
Thanks for that information.
I've updated the code from my first post (and fixed other small errors). I now did get a "No picture" string to my database when there was no picture uploaded. But the SAME thing happens even if I insert a picture in the upload field/form (and no files are added to the server). So the ELSE statement is not running instead of the IF statement. And there´s still problem B, I´m getting two lines in the database in stead for ONE. I know that the code connects twice and inserts twice to the database. But I just don´t know how to combine this whole code to make it one insertion to the database (without making it worse). |
|
||||
|
Re: Coding help: Combine Insert into and If/else statement!
$_FILES not $_Files. PHP is case sensitive.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
|||
|
Re: Coding help: Combine Insert into and If/else statement!
I actually had that one right in my code (noticed the coloring). I just wrote it wrong here in the post.
Anyway, Right now I still have the two main problems. Whether there is an image uploaded or not, I always get the image path in the database (or only part of the path if there is no image). And then there is the joining of the whole code so there will only be ONE 'insert into' function to the database. |
|
||||
|
Re: Coding help: Combine Insert into and If/else statement!
Possibly:
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Combine two javascript | longcroft | JavaScript Forum | 6 | Jun 3rd, 2008 14:51 |
| Date & Time [Combine] | doctypedeclaration | JavaScript Forum | 3 | Mar 12th, 2008 01:22 |
| [SOLVED] combine 2 onlick events. | AdRock | JavaScript Forum | 1 | Oct 15th, 2007 06:03 |
| Coding redirect in an else statement after the header | BRONIC | PHP Forum | 2 | Apr 19th, 2007 03:46 |
| How can I combine two columns into one column using SQL | gecastill | Databases | 2 | Jun 3rd, 2005 18:23 |