Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP






SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Using Empty()


I was under the (possibly mistaken) impression that if you check an array using empty() it will *never* be empty, however, this script reports that the array is not empty: PHP Code:

$tmp = array();
if (empty($tmp)) {
  echo 'shiver me timbers!  it *is* empty!'
} else {
  echo 'i told you so! na na na na na na!'
}

I tested this on a php5 server. Is there a difference in how empty works on php4 and php5. More importantly, is it considered the *correct* way to see if an array has any elements or not.




View Complete Forum Thread with Replies
Sponsored Links:

Related Messages:
Ftp_nlist Returns False For Empty Directory Instead Of Empty Array
In an application installed with PHP5 it looks like ftp_nlist() returns
false if the directory is empty, instead of an empty array as it should
according to the manual. On the original server with PHP4 it works as
expected.

Is this a bug, or an undocumented change in PHP5, or a setting that
could be changed somewhere?

View Replies !   View Related
PHP Session Is Empty And Session File Is Empty
I am trying to save a SESSION variable which looks to succeed because right after I print it out to verify it. I do so as follows:

session_start();
<snip>
$_SESSION['security_code'] = $code;

The problem is that I submit a form on the same page and I need to check if the $_SESSION['security_code'] == $_POST['security_code'] however this condition is always false because $_SESSION['security_code'] is empty.  I also checked the security files that are created in the PHP 'save_path' directory and it appears to be creating an empty session file.

Can anyone suggest anything here?  Also prior to the condition, I also do a session_start() and that doesn't help either.

I got this code from a open source area and on that web site, if I test it it works fine.  On my localhost it does not work.  I'm not sure if I'm missing some configuration or whether PHP 5.2.2 has problems with sessions.

View Replies !   View Related
Using Empty And &&
Im checking to see if all of these are empty I have to do something:

if (empty($_POST['phhome'] && $_POST['phcell'] && $_POST['phwork'] &&
$_POST['email'])) {

But this isnt working and putting empty() around each didnt either. What
I'm I not seeing?

View Replies !   View Related
Help With Empty()
this is my php:

$pro1=addslashes($_POST['pro1']);
$pro2=addslashes($_POST['pro2']);
$pro3=addslashes($_POST['pro3']);
$pro4=addslashes($_POST['pro4']);
$pro5=addslashes($_POST['pro5']);

for ($i=1;$i==5;$i++){
if (!empty(${'pro'.$i}))
$pros.=${'pro'.$i}."";
}
echo nl2br($pros);

$pros return nothing, although $pro1 and $pro2 contain certain value...

View Replies !   View Related
Using If Empty
I am trying to use the if empty statment to make sure that every input box has been filled, the code looks like this. Code:

if(empty($inputbox)){
print "you did not fill in a box.";}

This works fine but there is about 20 input boxes and there must be an easier way to insted of repeating this 20 times.

View Replies !   View Related
Empty If / Else ?
I have never done this, but I have an if/else statement, and if I don't want anything to happen in the if statement, should I leave it empty or is there something that I could add???

A simple example (my actual code is much longer):
<?php
if(empty($_POST['fname'])){

}else{
     $name = $_POST['fname']
     mysql_query("INSERT INTO name(`first`) VALUES ('$name'));
}?>

View Replies !   View Related
Empty &lt;p&gt;&lt;/p&gt; How To Get Rid Of
I'm setting up a home made Content Management System, running a loop that outputs every line of an external text file with <p> in front and </p> at the end. If a line is empty it outputs <p></p>. An empty line is created each time I hit the return key twice.

My validator in Safari ("SafariTidy (http://zappatic.net/safaritidy/)") complains and gives warning about inaccurate code, saying an empty <p> is not allowed. I'm using html 4.01 strict as DTD.

Questions:

1. Should I just ignore the warning? (feels bad to not see the green check mark anymore)

2. Is there a way to skip empty lines? I tried FILE_SKIP_EMPTY_LINES (http://www.php.net/file) but it did not work - perhaps I used it wrongly. On the other hand I read that it's a bug (http://www.mail-archive.com/php-bugs@lists.php.net/msg97959.html) in PHP... I'm testing all locally running PHP 5.22 on Macintosh Tiger 10.4.10.

3. Is there a way to erase the string <p></p> before writing the loop to the output file?

I'm using a plain text file (created by TextMate (http://www.macromates.com/), a Macintosh application) using LF line feeds (my server is Apache) which I include in a page:

<?php
error_reporting(E_ALL);
$arr_content = file('text.txt', FILE_SKIP_EMPTY_LINES);
foreach($arr_content as $p) {
echo '<p>'.$p."</p>";
}
?>

View Replies !   View Related
Empty Value - Set A Value
The variable $new_course is not set a value but my below error checking doesn't seem to when the value is empty. It continues on with the rest of the code. Why is this?

if(!isset($new_course) || ($new_course != ""))
{
   echo '<p>Please enter a new course</p>'     
   echo '<p><a href="javascript:history.back(1)">Return</a></p>'
   exit;
}

View Replies !   View Related
An Empty Value
I have a problem which Ido not know how to solve in php, I'll explain. I have built a registration form , and set required fields. now what I wanna do is I want it to check if all the fields are filled in , and to send a message to him if one or more isn't , and deny the registration. like, in pascal , the empty value goes like: if X=' ' then.
does anyone know how it goes in php? I've tried that and it isn't really working. In addition , what i get when trying this is "Not all required fields are filled" , even when they all are . here's my code. PHP Code:

<?php
$con = mysql_connect("xxx","xxx","xxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("regist",$con);

$sql="INSERT INTO person (name, lastname, username, password, email, gender, notes)
.............

View Replies !   View Related
Empty($bla
Are these two statements exactly the same?

if (empty($bla)){
echo "this is empty"
}
&

if ($bla == ""){
echo "this is empty"
}

View Replies !   View Related
Empty Value
if (empty($var)) { ... }

the same as this:

PHP Code:

if ($var == '') { ... }

View Replies !   View Related
SQL Empty Of Now
I've got a sql line ,

"SELECT * from mytable where user = $user"

View Replies !   View Related
Empty()
Its use is in part cleaning vars before DB insertion. I have this but is there a better more performance focused way of writing the snippet bellow.

$strValue=($strValue==&#390;')?&#390;zero':$strValue;
$strValue=(empty($strValue))?'NULL':$strValue;
$strValue=($strValue==&#390;zero')?&#390;':$strValue;

View Replies !   View Related
Testing For Empty Set?
basically, i want to query my db and see if the user has input a valid #.... if it matches a record im my table 'plu_coupons' then i will execute the code that allows a user to proceed... if the number input by the user does not match any of my records, he/she will be redirected to the sign-in page...

View Replies !   View Related
How To Empty An Array?
I've got a nested array, which I populate while processing and formatting results from a query. When I print the contents of the array I want to clear it so that I can use it again in the next iteration of the loop without the stuff I've printed still in it. Is there a straight forward way to do this? I've tried re-declaring it but that doesn't empty it.

View Replies !   View Related
Empty Sessions
When sessions are created by my message board or any other script. The sessions I can see inside the /tmp folder but when I open em up with pico I see NOTHING! no session variables or anything!!

I have been tryin to figure this out forever here is my php.ini configuration for sessions

[Session]
session.save_handler = files ; handler used to store/retrieve data
session.save_path = /tmp ; argument passed to save_handler
; in the case of files, this is the
; path where data files are stored
session.use_cookies = 1 ; whether to use cookies
session.name = PHPSESSID
; name of the session
; is used as cookie name
session.auto_start = 1 ; initialize session on request startup
session.save_handler = files ; handler used to store/retrieve data
session.save_path = /tmp ; argument passed to save_handler
; in the case of files, this is the
; path where data files are stored
session.use_cookies = 1 ; whether to use cookies
session.name = PHPSESSID
; name of the session
; is used as cookie name
session.auto_start = 1 ; initialize session on request startup
session.cookie_lifetime = 0 ; lifetime in seconds of cookie
; or if 0, until browser is restarted
session.cookie_path = / ; the path the cookie is valid for
session.cookie_domain = ; the domain the cookie is valid for
session.serialize_handler = php ; handler used to serialize data
; php is the standard serializer of PHP
session.gc_probability = 1 ; percentual probability that the
; 'garbage collection' process is started
; on every session initialization
session.gc_maxlifetime = 1440 ; after this number of seconds, stored
; or if 0, until browser is restarted
session.cookie_path = / ; the path the cookie is valid for
session.cookie_domain = ; the domain the cookie is valid for
session.serialize_handler = php ; handler used to serialize data
; php is the standard serializer of PHP
session.gc_probability = 1 ; percentual probability that the
; 'garbage collection' process is started
; on every session initialization
session.gc_maxlifetime = 1440 ; after this number of seconds, stored
; data will be seen as 'garbage' and
; cleaned up by the gc process
session.referer_check = ; check HTTP Referer to invalidate
; externally stored URLs containing ids
session.entropy_length = 0 ; how many bytes to read from the file
session.entropy_file = ; specified here to create the session id
; session.entropy_length = 16
; session.entropy_file = /dev/urandom
session.cache_limiter = nocache ; set to {nocache,private,public} to
; determine HTTP caching aspects
; cleaned up by the gc process
session.referer_check = ; check HTTP Referer to invalidate
; externally stored URLs containing ids
session.entropy_length = 0 ; how many bytes to read from the file
session.entropy_file = ; specified here to create the session id
; session.entropy_length = 16
; session.entropy_file = /dev/urandom
session.cache_limiter = nocache ; set to {nocache,private,public} to
; determine HTTP caching aspects
session.cache_expire = 180 ; document expires after n minutes
session.use_trans_sid = 1 ; use transient sid support if enabled
; by compiling with --enable-trans-sid

PLEASE I NEED HELP!!

my /tmp is chmoded to 777 and I have tried everything...

I know it isnt my forums because they worked on another server I transfered from and also it affects more than just the forums... every scripts that uses sessions is affected...

View Replies !   View Related
Empty Array?
I have a query that selects some data from a table based on the current ID
selected.

If the query does not return any results, I want it to continue to another
query that will insert a record into the table.

Below is what I have...but it will not insert anything if the first query...

View Replies !   View Related
PHP_AUTH_USER Is Empty
I use basic authentication in Apache. I like to use the global variable
$_SERVER['PHP_AUTH_USER']. Unfortunately this variable is empty/no
availabe. Same with PHP_AUTH_PW. AUTH_TYPE is working and states
"Basic".

View Replies !   View Related
PHP Variables Are Always Empty
I'm trying to write a PHP script which allows to enter an username and a
password and to click two buttons.
If I start my PHP scripts 'mytest.php' I see the two input fields and the
two buttons. However if I enter something to the input fields and press a
button the echo commands show nothing.

======

PHP script 'mytest.php'
-----------------------

<?php
session_start();

if (!isset($_SESSION['auth_ok'])) {
$_SESSION['auth_ok'] = false;
}

echo "$user <br>";
echo "$pass <br>";
echo "$button1 <br>";
echo "$button2 <br>";
echo "$auth_ok <br>";

if (isset($button1)){
echo "Button 1 has been pressed<br>";
$auth_ok = true;

View Replies !   View Related
Php Shows Up Empty
I havea problem with a php page, everytime I call it it presents me
with an empty page, with only

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-
1252"></HEAD>
<BODY></BODY></HTML>

as if have only made an empty php-page, I cannot figure out what the
problem is, can anyone help me. (I have made a test page with only <?php ?> run it and it gave me the exact same result)

View Replies !   View Related
Empty Variables In 4.2.1+
I have a site where I check to see if a variable isset to see which file I include on a page - the URL would be something like: http://www.domain.com/?s

Then in the PHP file I check to see: PHP Code:

View Replies !   View Related
Htaccess Must Be Empty
I am moving some php scripts to a new host. While getting to know the
server, I ran into a strange problem.

If I add a .htaccess file, or more specifically: a .htaccess with
content, to a folder, requesting (html and php) files from that folder
results in internal server error messages.
If I upload an empty .htaccess file, all is fine. Then phpinfo() tells
me I am using Apache/1.3.27.

View Replies !   View Related
$_POST Of Empty Vs 0 Value
working on LINUX I found that both empty($_POST['foo']) where $foo = 0 or &foo = empty gives me TRUE. I.e. I can not distingush between 0 and empty value - I need it for the text box value. What is the solution?

View Replies !   View Related
Empty The Database
Is there a command that will empty or delete all the information in a database but keep the structure of the database so new information can be added to it?

View Replies !   View Related
Empty Lines
i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines.

View Replies !   View Related
Empty Form
Say I have a form, a really long form, is there a way to check if all the fields in the form are empty without saying a million if statements?

View Replies !   View Related
Empty Vs. Isset
I have a user form where users input float values or integers. If I want to see if no value has been input, I use the empty() function.  But if I want to see if users HAVE input a value that is a float or an integer, what function should I use?

View Replies !   View Related
How To Empty An Array??
I have an array being created a number of times with in a loop, before it is created I want to check if it empty and if it isn't then clear it down. How do I do this?

View Replies !   View Related
If Statement And Empty
i have my form and what i want to happen is when ALL the values are not empty i want to process the form but if just one of the values is empty i want top redisplay the form i have 15 values in my form, i know thats quite a lot but i need them all
so how would i do this? Code:

View Replies !   View Related
Using If Empty With Two Items
I am trying to say if $_Post and $_Session are empty set the variable $dcparent to equal 1, but it doesn't like what I am doing. 

if(isset($_POST['dcparent'])) {
$dcparent = mysql_real_escape_string($_POST['dcparent']);
}

if(isset($_SESSION['dcparent'])) {
$dcparent = mysql_real_escape_string($_SESSION['dcparent']);
}

if(empty($_POST['dcparent']) && (empty($_SESSION['dcparent'])) {
$dcparent = 1;
}

View Replies !   View Related
Empty Query
How can I tell if a query is empty:

I need to test this

$get_buddys = mysql_query($query_get_buddys) or die ("Invalid query". mysql_error());

View Replies !   View Related
Empty Spaces
Everytime I retrieve text from database into this Textarea, it creates empty spaces before and after the text. When I fill in the text in the textarea I make sure it has no spaces, but still when I retrieve it back into the textarea it show spaces. Database is very simple:

num, Smallint(1)
mytext, Text

Code to retrieve data:
<textarea name="mytext" cols="75" rows="15" class="FormFieldText" style="border:1 solid #999999">
         <?PHP
           if ($row[0] =='') //test for empty fields
           {echo "Sorry, Thought of the Week not defined yet!";}
            else
           {echo $row[0];}
         ?>
</textarea>...

View Replies !   View Related
Retrieve Empty Row
I'm trying to retieve all the rows in my table product_data where the column pd30 has no value inputed (Nul). I cannot syntax my recordset properly. Should I use !empty to locate the nul values or something else. here is where I'm at (I know this is wrong and doesnt work, but it gives the idea of what I'm trying to do): PHP Code:

SELECT * FROM product_data WHERE product_data.pd30 = !empty

guide me to fixing this?

View Replies !   View Related
Ignore If Empty
i have a script that enters details into a database table from another table, but i want it to ignore a insert command if a field is empty. E.g query customer database then if email field is not empty the script should then enter the email address in another table, but if the email field is empty it should ignore inserting email address (as its empty) into another table.

View Replies !   View Related
Empty Variables
is there a bether way to do this? PHP Code:

function validateEmpty($theinput,$description = '') {
                if (empty($theinput)) {
                        $this->errors[] = $description;
                        return false;
                } else {
                        return true;
              .....

View Replies !   View Related
Empty $FILES
I have tryed to implement some file upload on a webpage. I have a form
containing:

<input type="hidden" name="MAX_FILE_SIZE" value="102400">
<input name="userfile" type="file">

and on the action-script I have:
print_r($_FILES);

The result is:
Array ( )

If I check $_POST the userfile contains the correct path to the selected
file, but somehow the file is newer uploaded, or???

View Replies !   View Related
Empty Substring
I am recieving the following errors:

Warning: substr_count() [function.substr-count]: Empty substring. in /home/ventajas/public_html/contacto/send.php on line 3

Warning: main(error.) [function.main]: failed to open stream: No such file or directory in /home/ventajas/public_html/contacto/send.php on line 27

Warning: main() [function.include]: Failed opening 'error.' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ventajas/public_html/contacto/send.php on line 27

Its a php mail script. When I visit the URL http://<domainname>/contacto.php and fill the email form, it is redirected to send.php with the avobe errors.

View Replies !   View Related
Empty An Array
I have elements in a array and I want to clear it so that it only returns Array () (empty array), whats the easiest way to do this?

View Replies !   View Related
Directory Is Empty
I am trying to delete a directory I keep getting an error saying that the directory is not empty and can not be delete. I want to put an error check into my code to check if the directory is empty or not but the problem is that i do not know how to write something like this.

View Replies !   View Related
Query Was Empty!?!
I designed a page, and as usual, i echo the output queries until i am happy, then i will remove that and run the queries for the finished page. Code:

View Replies !   View Related
Trim() Or Empty()
i have this to test if a field has been filled in. Code:

View Replies !   View Related
Set Variable = 0, If Empty.
I am trying to get info from the database in a query and match it to a different table and then insert back into the main table. The issue I'm having is some of the fields are empty/don't match, so the variable $team1 or $team2 is empty and that causes an error in the insert query. Code:

View Replies !   View Related
!isset() Or Empty()
Consider the following:

<?

$gid = $_POST['gid'];
$id = $_POST['id'];

if(!isset($gid && $id)) {

exit();

}

?>

Now , would it be better to use !isset as above , or empty when trying to check if a form variable has been passed.

View Replies !   View Related
Isset() OR !empty()
Which do you use and why as in my trail of thought although very minor, the more that twists and turns, the longer the script takes to execute. Lately i've seen it popping up quite alot... the use of !empty() , working with my theory is it not easier/better to just use isset(). Are the any minor differences in the triggers of each that give the empty function an advantage is it just personal habbits and what people get used to?

View Replies !   View Related
$_post Empty In IIS 6?
I installed PHP on IIS 6.0 - Everything was working fine until I tried to submit a form. The PHP $_POST super global is always empty.

I've checked to ensure that my form has method="post", and I don't think it's a coding error, since the same exact script is working fine on my other machine.

View Replies !   View Related
Empty HTTP_ACCEPT_LANGUAGE
I have a problem, because site processed like that is loosing it's language variable. Pice of code, which is selecting langage, doesn't work, because variable $_SERVER['HTTP_ACCEPT_LANGUAGE'] is empty. Maybe someone know why?

code .....

View Replies !   View Related
Empty A Column
How do you empty a column (all rows) on information?

I know its possible to "TRUNCATE" a table, is it possible to do the same with just a column?

View Replies !   View Related
Drop Down Box Is Empty
I have a form which contains a drop down box. The values from the drop down box is retrieved from a table. The script runs but the drop down box is empty.

The fields in the table are: ....

View Replies !   View Related
Empty String For Avi
when using mime_content_type("/path/to/my/video.avi") I get an empty string every time
When I am supposed to get video/x-msvideo What is going on?

View Replies !   View Related
Empty Cells
I am using the is NOT NULL, to select fields that have something in them. However when some of the data is dumped in the NULL is not getting put in there.

I have the cell set to default NULL, but sometime is puts nothing in there. Is there another way to select only the fields that have something in them.

View Replies !   View Related
If Variable Is Empty
how to ignore lines of PHP code if the applicable variable is empty. For example in the code below. . . .  if the variable $r is empty. . ..   I would like the entire line:

echo "http://www.mysite.com/images/$r/1" to be ignored. Can you tell that I am very novice!!!!  I am learning though.

<?

// SET GALLERY OPTIONS HERE
// -----------------------
// Set Gallery options by editing this text:
$q =$_POST['q'];
$r =$_POST['r'];


echo "http://www.mysite.com/images/$q/1"
echo "http://www.mysite.com/images/$r/1"

View Replies !   View Related
Textbox Is Empty
I am trying to test if the txt box txt_matrl from the previous page has anything in it. It always falls into the loop even if the text box is empty? I tried isset also. Can you see an obvious mistake?

if(($_POST['txt_matrl'])!= " ")
{
$mtrl = $_POST['txt_matrl'];
if ($strWhereSet == "Yes")
{
$strWHERE = $strWHERE." AND material like '".$mtrl."'";
}
else
{
$strWHERE = "Where material like '".$mtrl."'";
$strWhereSet = "Yes";
}

}

View Replies !   View Related

Copyright © 2005-08 www.BigResource.com, All rights reserved