473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

text array not posting as null when empty!

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 1288
hsriat
1,654 Expert 1GB
Why didn't you used $_POST[ ] ...?

And do the validation inside the for loop as[php]for ($i=0; $i<2; $i++)
{
if(isset($mStreet[$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
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...
7
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...
7
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...
8
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...
13
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 ...
11
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
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...
8
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 =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.