switch..case not detecting empty field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

switch..case not detecting empty field

Post by Milan »

Code: Select all

$testrx = $_POST['file'];
		switch ($testrx) {

   case "" :
   if ($row_userinfo['Logo']=="nologo.gif"){
   $logox = "nologo.gif";
   }
   else
      $logox = $_COOKIE['USERNAME'].".jpg";
   break;
   }

I have a input filed type="file" but script always writes the

Code: Select all

$logox = $_COOKIE['USERNAME'].".jpg";
Did i do something wrong?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: switch..case not detecting empty field

Post by RobertGonzalez »

Milan wrote:

Code: Select all

<?php
$testrx = $_POST['file'];
switch ($testrx) {
   case "" :
      if ($row_userinfo['Logo']=="nologo.gif"){
         $logox = "nologo.gif";
      }
      else
      {
         $logox = $_COOKIE['USERNAME'].".jpg";
      }
      break;
}
?>
Where does the array var $row_userinfo['Logo'] get set? What is it's value and how does it relate to $_POST['file']?
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

Post by Milan »

$row_userinfo['Logo'] get's it's value from the database ( table users, field - logo)

$_POST['file'] get's it's value from the form1 textbox (<input name="file" type="file" class="text3" value="" size="32"> )

i want to do the following; in case the "file" field has not changed script will leave the old user logo and in case the filed
has changed it will write the USERNAME + extension from a cookie

Code: Select all

$logox = $_COOKIE['USERNAME'].".jpg";
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

do a var_dump on both variable and compare them
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

hmmm

Post by Milan »

i got NULL NULL
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

Post by Milan »

my bad

it's string(0) "" NULL
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post by xpgeek »

use

Code: Select all

$testrx = basename($_FILES['file']['name']);
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: switch..case not detecting empty field

Post by jmut »

Milan wrote:

Code: Select all

$testrx = $_POST['file'];
		switch ($testrx) {

   case "" :
   if ($row_userinfo['Logo']=="nologo.gif"){
   $logox = "nologo.gif";
   }
   else
      $logox = $_COOKIE['USERNAME'].".jpg";
   break;
   }

I have a input filed type="file" but script always writes the

Code: Select all

$logox = $_COOKIE['USERNAME'].".jpg";
Did i do something wrong?
I would have done it like this.


Code: Select all

$testrx = isset($_POST['file']) ? trim($_POST['file']) : "";
switch ($testrx) {

   case "" :
   // ....
   break;

or even

Code: Select all

$testrx = isset($_POST['file']) ? trim($_POST['file']) : "";
switch (true) {

   case (empty($testrx)) :
   // ....
   break;
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

Post by Milan »

i'll try it! thanks guys!
Post Reply