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




Empty Variables In Forms


I have some functions that check to see if certain form variables are empty. If they are empty then the function returns a 0. All of that is working just fine. BUT, I cant get the script to see the 0. PHP Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Empty Fields In Forms
I'm working on a script for a form for people to submit their info ( Name, e-mail, AIM, website URL etc). Now it is possible that some people don't have AIM or a website. I'm using a html table to display the info on the member page and empty fields make the table look strange. Is there a way to set some default value (like N/A) that would be displayed in case a field is left empty?

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;

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:

Testing For Empty Variables
I am retreiving the results from a randomized multiple choice quiz sent from a another php page using:

foreach($_POST AS $field=>$value){

How do I check to see which questions were not checked?

Empty Variables And 4.21 (POST/GET)
With global variables set to on, I always had the following in my script to make sure variables had a default value:

if (empty($var)) {
$var = 1;}

Now with 4.21, I changed it to:

if (empty($_GET['var'])) {
$var = 1;}

The problem is sometimes I use GET and sometimes I use POST. With global variables on it didn't matter. Now it does. Is there a way to do this? When I try if (empty($_GET['var']) || empty($_POST['var'])), it doesn't work because one or the other will always be empty at any one time.

Checking For Empty Variables
Can I use empty() to check to see if variables actually have data? Basically I want the script or something to check to see if there is data in the variables. If there is no data, give the user some instructions on writing some data (link to a form or admin panel). If there is data, then continue with writing to the database.

Passing My Variables With Forms Variables
how to carry variables onto the next page along with the forms variables. I need to carry my own over too, but when I press submit on the form page only the forms variables carry over, not my own ?? I have two drop down menues on my form that provide two values "start & end" which I require to go with my own variables.I have tried "a href=" link which carries my variables but not the forms variables.

<?php
echo"<form method=get action=somepage.php?one=$one&two=$two&three=$three&four=$four>";?>
also tried
<a href=somepage.php?one=$one&two=$two&three=$three&four=$four&start=$start&end=$end

If(empty) Statements/session Variables
1. I have a 2 page form. When the user fills out the info on page form he is directed to the 2nd page of the form. A session variable has been created in the 2nd form to hold all the data from the 1st page. When the 2nd page is submitted all the data (stored from page 1 and new from page 2) are sent to the database.

2. Here is the problem. On page 1, I have several form fields (like combo boxes) that need to work together. For example: I have a text field (name=phylum) in which investigators add new phylum names which are eventually sent to database field "phylum" of the same name. Next to that is a select box (name=newphylum) that has all the names that the investigors have previously entered and that are dynamically retrieved from the database field "phylum".

So when a researcher fills out page 1 of the form he/she can either add a new name or select an already existing name from the select box. But just one of these values can be sent to the database, not both.

QUESTION 1: How can I say and where would I put something that basically says the following: if the phylum text field is left EMPTY (i.e. they don´t add a new name) and they select instead from the select box, that it is the value from the select box and not the text box that gets sent to the database.

QUESTION 2: How do I pass the statement from question 1 into the session variable on page 2 of my form?

Creating Empty Variables For Input Data
I am creating a script that will be taking data from a POST and submitting
the data to variables which are placed within a hash for string to data
association. Then, using HTML::Table and Mail::Sendmail, the data is parsed
into an html table and then an email is created and send to a recipient.
So, my question is this; How do I take the input from a post form and have
the variables pick up the data and process it into a hash?

my $name = ;
my $instock = ;
my describe = ;
# Hash to hold inventory data
my %table_data = (
model ='$modelnumber',
item ='$name',
available ='$instock',
description ='$describe',
);

This is all the code I have written thus far, any pointers or suggestions
for this project?

Firefox Causing Empty PHP Form Variables??
This is really weird, and I would never believe it possible if it
weren't actually happening to me.

I've a customer database in mySQL, using PHP to create the forms, yadda
yadda.
All of a sudden, every time I edit a customer, when I submit the form
using Firefox 1.0.2 on Linux (Fedora Core 3) it sends empty form fields
to the database.

BUT, if I use Firefox on Windows, or Opera on Fedora Core 3, it works
perfectly fine.

Any ideas what in the world could cause this?
Firefox on Linux worked fine to up until...the last few days I think.
The only think I can think of, is I may have installed a couple of
extensions during that time.

Forms And URL Variables
I wanted to create a cool form processor for my site and I didn't want to use any JavaScript nor did I want to tell the user to use the back button!

What I did is have my script validate required fields, and if one of them is proven empty or something the script redirects the user using this code:
PRINT "<meta http-equiv='Refresh' content=&#390; URL=$url'>";

Now the $URL contains the variables like form.php?name=myname&email=myemail etc... using name=$name etc.. But I used this code to replace spaces with a "+" or the URL will be cut short and loose data: $name = str_replace (" ", "+", "$name");

And now for the fields in my form I have these little codes:
<? if (isset ($name))
print "$name";?>

I also went a step further and highlighted the tables that the empty field was in by changing the table background color! with this code:
IF (isset ($name) && ($name == "")) {
$name_color = "#CC0000";} else {
$name_color = "#FFFFFF";}

And of course the <? echo $name_color; ?> in the html... This works very well, I tested it in NS and IE my only concern is, is this a smart way of doing this? I mean using the URL to fill out the form so the user won't have to retype everything? Maybe their is a way or a better command than REFRESH? Does anyone know of the limit of characters that can be in the URL? I've tried up to 568 so far (Just testing for the heck of it). Any input on this method of form validation would be appreaciated

Posting Variables From Forms
With a form, I have two buttons.

One of them says:
- pay here

The other says
- pay somewhere else

Now, can I change the location to which the variables from the Form are
posted, depending on the button that they click? or am I always restricted
to the location specified in the action (e.g. <form method="post"
action="mynewpage.php">)

Session Variables And Forms
I have a mailing list manager script that allows viewing of subscribers and unsuscribers on several different mailing lists. I have a multi-selection drop down menu containing the names of the mailing lists. I want to change a session variable onchange() of the drop-down, so that the last query gets resent for the newly selected mailing lists(s) that the administrator is requesting to view.

Then I tried making the page reload() when the drop-down menu selections were changed, but I couldn't figure out how to retrieve the variables from the form considering I'm just reloading the page. I can't think of a good way to do this. So, basically, I am wanting to resend the last sent query changing only the mailing lists that I am searching.

PHP Not Getting Variables In HTML Forms
Just installed PHP, and Apache. Am having problems with the PHP to
get form data from an HTML file. Specifically, I can not obtain the
variable "tireqty" in a PHP file called by an HTML file. The files'
contents are listed as follow:

-----------------------------
The following is the HTML file
-----------------------------
<form action="processorder.php" method=post>
<table border=0>
<tr bgcolor=#cccccc>
<td width=150>Item</td>
<td width=15>Quantity</td>
</tr>
<tr>
<td>Tires</td>
<td align=center><input type="text" name="tireqty" size=3
maxlength=3></td>
</tr>
<tr>
<td colspan=2 align=center><input type=submit value="Submit
Order"></td>
</tr>
</table>
</form>
-----------------------------
The following is the PHP file 'processorder.php'
-----------------------------
<html>
<head>
<title>abcd</title>
</head>
<body>
<?
echo $tireqty." tires<br>";
?>
</body>
</html>
-----------------------------
I know PHP and Apache are working becasue I am able to to have an HTML
page to load a PHP page to do a for loop and use the "echo" function
to print the loop iterations. So I'm not sure why PHP can't access
the variable "tireqty". Is there some settings in the PHP engine that
I need to check for this?

Forms And Passing Variables
I am trying to use a PHP variable and pass it every time I call the page. The variable is $rn that should be a called randomly using rand() if the value of it is empty. However, the following code does not work.

if (isset($guess)) {
    $rn = rand(1, 100);
   }

The form in the page calls itself so it reloads and I am wondering how I pass this variable in the form each time and when the variable is sert to a value, not have rand() overwrite the value. Here is all my code:

Making Forms Set Variables
A pretty simple question: How do I make HTML forms set Variables? And... How do I make those set variables set in a cookie?

Passing Variable Variables Through Forms
I´ve spent the last few hours trying to figure out why my code doesn´t work, cos I had it working already, then made a few changes which actually cannot have anything to do with my variables, and now just one of them is passed (strange, eh?).
OK, here´s the code ( a bit chaotic, I suppose, anyway...)

<FORM action="bestell_mail.php" method="post">
<?php
$namensliste = array(Name, Vorname, Strasse, Postleitzahl, Ort, Mail);
$laenge = array(12,12,12,5,12,20);

for($p=0; $p<6 ; $p++) {
//20
echo"<TR>
<TD nowrap>
{$namensliste[$p]}:
</TD>
<TD>
<INPUT TYPE=TEXT NAME={$namensliste[$p]} SIZE={$laenge[$p]} maxlength={$laenge[$p]} >
</TD>
</TR>";
}

?>
<TR>
<TD colspan=2 align=center>
<INPUT TYPE=submit NAME=submit VALUE=abschicken>
</FORM>

so actually, I should be able to use my variables, (the names of which I have in the array called $namensliste) in the file "bestell_mail.php".
I tried this using a loop to read the variable names from an array again, and I also tried it using simple code like this

echo "$Vorname";

I had it working already, as I mentioned before, so u can imagine this is driving me mad right now. So with ur help, maybe I can still get some peace of mind this night.

Passing Variables From HTML Forms
I'm using Apache 1.3.27 as a local host to develop my site offline, since I only have a 56k and cant be online all the time. The problem is that when I try to pass variables from a HTML form to a php file, it doesnt recognise the variable names here are the lines of code concerned: on the HTML form:

<input type="text" size="16" maxlength="20" name="email">

in the php file:

print ("Your email address is $email");

It works when hosted online, but not when offline i've turned global variables ON in php.ini, but that didnt help can anyone else suggest anything?

HTML Forms Sending Variables To PHP Scripts
I'm using some HTML script to post some variables (see attached HTML code) to a PHP script. When I click on the Submit button a 'File Download' window pops up and when I click on Ok it opens the php script that I'm calling in Notepad.

I'm new to PHP and Apache so is there something in the php.ini file that I may need to change? Or is it my code that needs altering?

Posting Multiple Variables To $_POST Using HTML Forms
This is my code :

<FORM ACTION="php_steptwo001.php" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="duration" VALUE=3>
<INPUT TYPE="HIDDEN" NAME="banner" VALUE="test">
<INPUT TYPE="SUBMIT" VALUE"3 DAYS">
</FORM>

Only the 1st Variable 'duration' gets passed!

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?

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.

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?

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...

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.

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'));
}?>

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...

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.

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...

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...

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".

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)

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.

$_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?

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?

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.

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?

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?

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?

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:

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;
}

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());

Sessions, Tmp Dir, Empty Files
Problem - the /tmp session files created in my tmp directory contain zero bytes (ie. totally empty). Any ideas why?

Here's my setup: Windows 2000, Apache web server, PHP402. I can see new session files being created each time a new session is registered, but they're not much use if they're empty! I've checked the file permissions on the tmp directory, and it's completely shared out. No error messages or logs are being generated that I'm aware of.

Thanks for any help...

Empty Arrays Or No Files
I have written a script which depending on the variable uploads $num files.
The value of $num is stored in a mysql column and each file is uploaded in an array $file[], then placed in a directory by the name $id_$i.jpg (for example).

The problem arises when I want to display the files back in a table. The $num is read back through the mysql query and if the amount of files is less than $num then I have a partially filled table. The cells with no filename display the icon which references "no image" as there is no file in the upload directory to reference.

What I would like to know is

1)if when the form is submitted and only half of the files are uploaded could I set the array so it realises that only half of $file[] has been filled, or that only 6 of 12 files have been uploaded.

2) Alternately, could I count the number of files in a directory on my server and store that value as an variable to set the number of columns in my table?

What would be the code for this???

Thanks in advance.

Check If Directory Is Empty
I've made a script that puts images in a certain directory into the database. With the following code.

How Do I Not Print Something Out If A String Is Empty?
I am using mySQL to get stuff from a database, the fields are getting parsed into the variables $no , $t , $a , $l and $y

At the moment I am using this line this to display them to the web browser;

echo "$no: $t - $a [$l] ($y)<br>$n<br><br>";

However, sometimes $y is empty when the SQL query returns it's result and so if that happens I get something like

2000: blah - blah [whatever] ()
blah blah blah

Is it possible to add some code to my echo line that only outputs the () if $y is not empty?

I am sure this is possible but I havn't got a clue how to do it.

Empty Attachement Through Mail()
can someone check my code for me to see where I went wrong please?

I have made a short page where people can enter an email address and select a file to be sent to them. I have pillaged some code from some previous posts here which was very helpful. The script works more or less, however I have 2 problems:

1) The HTML isn't picked up in the body of the email, however the text is.

2) The attachment makes it to the email however when you open it up, its a blank file. The file name and size are correctly reported in the atachment.

Here is my code. I've also made sure the selected files are 777 on the server. If someone could take a quick gander, I'd really appreciate it!

I Was Confused Between Isset() And Empty()
What's the diff between function isset() and empty()? I was totally confused.

I create a table with mysql as:

How Can I Empty A File's Content?
I uses fopen and fwrite to write a file called "dummy.txt". I would like to empty it everytime I want to write a new content. How can I empty the content of the file?

I've tried using unlink() but I seems to have permission problem with my server. I am guessing that I can't delete a file.


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