473,569 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

text array not posting as null when empty!

8 New Member
Hi There,
I am building a form that allows a business to enter at most 2 mailing addresses. i have the form set up so both inputs are there, storing as a post array. the problem is, when i try to use php to enter the data into in the mysql database, it enters empty data even when a field is null.
html
Expand|Select|Wrap|Line Numbers
  1. <form method='POST' action='entry2.php' name='entry'>
  2. <table>
  3. <tr><td colspan='4' align='center'>Mailing Address</td></tr>
  4. <tr><td>Street:<input type='text' name='mStreet[]' /></td><td>Zip:
  5. <?php
  6. selectDistinct($connection,'CityCode','zip','mzip[]','97465');
  7. ?>
  8. </td></tr>
  9. <tr><td>Street:<input type='text' name='mStreet[]' /></td><td>Zip:
  10. <?php
  11. selectDistinct($connection,'CityCode','zip','mzip[]','97465');
  12. ?>
  13. </td></tr></table></form>
  14.  
php to save to db
Expand|Select|Wrap|Line Numbers
  1. if(!empty($mStreet)){
  2. for($i=0;$i<2;$i++){
  3.   $Cityquery = "SELECT cityCode FROM CityCode WHERE zip='{$mzip[$i]}'";
  4.   if(!($result = @ mysql_query($Cityquery,$connection))){showerror();}
  5.   $row = mysql_fetch_array($result);
  6.   $mcityCode[$i] = $row['cityCode'];
  7.   $insertQuery = "INSERT INTO Address VALUES(NULL,1,'{$BID}','{$mStreet[$i]}','{$mcityCode[$i]}')";
  8.   if(!(@ mysql_query($insertQuery, $connection))){showerror();}
  9.   }
  10.   }
  11.  
p.s. the selectDistinct functions return a list of zip codes that are accepted, and in the php it is used to determine the code that is associated with the zip
Feb 27 '08 #1
1 1305
hsriat
1,654 Recognized Expert Top Contributor
Why didn't you used $_POST[ ] ...?

And do the validation inside the for loop as[php]for ($i=0; $i<2; $i++)
{
if(isset($mStre et[$i]))
{
//save data to db
}
}[/php]
Feb 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

22
4584
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last month I had enough of extra proof that the cat doesn't hount mice anymore in more and more situations. And the surrent sicretisme among array and...
7
7388
by: !TG | last post by:
I recently learned of Join response.write join(ThisArray," ") I am having trouble with it, however and it appears to be caused by null characters. Is there anyway around this join problem with Arrays containing Null?
7
8639
by: Gertjan van Heijst | last post by:
Hi, I really hope someone can help me because I've already spend 2 days on this problem and I'm not getting anywhere. I think the problem is that I don't really understand how text boxes store 'empty' values. I'm trying tot do the following. I have a continous sub form that lists transactions. On the top level form I have some text boxes...
8
3669
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was static; if the input file contained more than entries, tough. This time I want to do it right - use a dynamic array that increases in size with...
13
1912
by: j_ruez | last post by:
I am trying to learn the best ways to do some things in c# When testing for an empty string, what is the best way to test it. For example, if I have a textbox named txtValue Should I use txtValue.Text == "" or
11
3759
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
30
3580
by: ggnguser | last post by:
It's part of a test and I'm stumped. There is a function void foo(char **x) The function signature is given and cannot be changed, so no passing of other values. The test case involves defining this variable: char *y = { /* bunch of stuff */ } and calling
8
5842
by: Sunny | last post by:
Hi, Can someone tell me, How to redefine array or make array empty or null. Here what I am trying to do. var temp = new Array(); for(i=0; i <=outstring.length-1; i++) { temp = outstring.split(','); } Once the for loop will finish doing it, I want temp array to be null
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.