Page 1 of 1

switch..case not detecting empty field

Posted: Tue May 23, 2006 6:03 pm
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?

Re: switch..case not detecting empty field

Posted: Tue May 23, 2006 6:14 pm
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']?

Posted: Tue May 23, 2006 6:20 pm
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";

Posted: Tue May 23, 2006 6:24 pm
by John Cartwright
do a var_dump on both variable and compare them

hmmm

Posted: Tue May 23, 2006 6:28 pm
by Milan
i got NULL NULL

Posted: Tue May 23, 2006 6:30 pm
by Milan
my bad

it's string(0) "" NULL

Posted: Wed May 24, 2006 2:02 am
by xpgeek
use

Code: Select all

$testrx = basename($_FILES['file']['name']);

Re: switch..case not detecting empty field

Posted: Wed May 24, 2006 2:04 am
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;

Posted: Wed May 24, 2006 2:06 am
by Milan
i'll try it! thanks guys!