Re: [PHP] Re: Not getting expected result from file()

2007-06-11 Thread Frank Arensmeier
If you are not able to get anything into your DB (and your connection  
is ok), then two things might be wrong: your input or the query  
string itself.


Echo out the query string and try to use the query  
manually (directly with a MySQL client). If the query string is ok,  
you might check your MySQL connection settings (var_dump, echo etc).  
If the query string is not ok, you have to look at the input values  
for the query ($regName, $regAddress etc).


//frank


11 jun 2007 kl. 07.27 skrev kvigor:

Trimmed elements in the array.  I still can't get it to store in  
central

table.  No MySQL errors either. :-(
 (Also, all form values are escaped.) Strings compared in if  
condition are

now identical.


newcode
===
theFileArray = file('C:\htdocs\folder1\file.txt');

function trim_value($value)
{
$value = trim($value);
}

array_walk($theFileArray, 'trim_value');


if(isset($_POST['strName'], $_POST['strCity'], $_POST['strState']))
{
 $space =  ;
 $stringOne = $_POST['strName']. $space. $_POST['strCity']. $space .
$_POST['strState'];
}

 if(in_array($stringOne, $theFileArray)) // string were identical  
after I

trimmed an did var_dump on $stringOne and $theFileArray[2]
 {
  $queryCentral = INSERT INTO central (conName, conAddress, conCity,
conState, conZip, conPhone, schName, schAddress, schCity, schState,  
schZip,
strName, strCity, strState) VALUES('$regName', '$regAddress',  
'$regCity',
'$regState', '$regZip', '$regPhone', '$sclName', '$sclAddress',  
'$sclCity',

'$sclState', '$sclZip', '$stoName', '$stoCity', '$stoState');

  mysql_query($queryCentral, $connection) or die(Query failed: .
mysql_error($connection));
 }


else
{
$queryUnknown = INSERT INTO unknown (conName, conAddress, conCity,
conState, conZip, conPhone, schName, schAddress, schCity, schState,  
schZip,
strName, strCity, strState) VALUES('$regName', '$regAddress',  
'$regCity',
'$regState', '$regZip', '$regPhone', '$sclName', '$sclAddress',  
'$sclCity',

'$sclState', '$sclZip', '$stoName', '$stoCity', '$stoState');
mysql_query($queryUnknown, $connection) or die(Query failed: .
mysql_error($connection));
}
== 
==

David Robley [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

kvigor wrote:


Hello,

I'm using the file function create an array.  I'm using a value  
from a

form to see if it matches in elements in the array.

My problem is I expect  the condition to be true but info but my  
DB isn't

populated as I in the right DB...
=Code
Begins==
$theFileArray = file('C:\htdocs\folder1\file.txt');



Your problem starts here - file returns the file in an array. Each  
element
of the array corresponds to a line in the file, with the newline  
still
attached. When you compare to a string without the newline at the  
end, the

comparison fails.

If you have php  5.0.0 you can use the FILE_IGNORE_NEW_LINES flag  
in the
file() arguments, otherwise use trim() to remove trailing  
whitespace from

the array elements.



Cheers
--
David Robley

I hate playing craps, Tom said dicily.
Today is Boomtime, the 16th day of Confusion in the YOLD 3173.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Not getting expected result from file()

2007-06-11 Thread Richard Lynch
trim is probably sub-optimal, as you MIGHT have leading/trailing
whitespace as part of the actual data at some point.

You should trim off ONLY one last newline character, no more, no less.

I dunno why it's not working still though...

On Mon, June 11, 2007 12:14 am, kvigor wrote:
 OK, I trimmed the elements in the array. using var_dump() it shows
 strings
 are identical, however nothing is storing in DB still.

 view new code
 =//doesn't store in central still,
 also
 shows no MySQL errors.
 $theFileArray = file('C:\htdocs\folder1\file.txt');

 function trim_value($value)
 {
 $value = trim($value);
 }

 array_walk($theFileArray, 'trim_value');


 if(isset($_POST['strName'], $_POST['strCity'], $_POST['strState']))
 {
  $space =  ;
  $stringOne = $_POST['strName']. $space. $_POST['strCity']. $space .
 $_POST['strState'];

 }
  if(in_array($storeInfo, $theFileArray))
  {
   $queryCentral = INSERT INTO central (conName, conAddress, conCity,
 conState, conZip, conPhone, schName, schAddress, schCity, schState,
 schZip,
 strName, strCity, strState) VALUES('$regName', '$regAddress',
 '$regCity',
 '$regState', '$regZip', '$regPhone', '$sclName', '$sclAddress',
 '$sclCity',
 '$sclState', '$sclZip', '$stoName', '$stoCity', '$stoState');

   mysql_query($queryCentral, $connection) or die(Query failed: .
 mysql_error($connection));
  }


 else
 {
 $queryUnknown = INSERT INTO unknown (conName, conAddress, conCity,
 conState, conZip, conPhone, schName, schAddress, schCity, schState,
 schZip,
 strName, strCity, strState) VALUES('$regName', '$regAddress',
 '$regCity',
 '$regState', '$regZip', '$regPhone', '$sclName', '$sclAddress',
 '$sclCity',
 '$sclState', '$sclZip', '$stoName', '$stoCity', '$stoState');
 mysql_query($queryUnknown, $connection) or die(Query failed: .
 mysql_error($connection));
 }
 =

 David Robley [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 kvigor wrote:

 Hello,

 I'm using the file function create an array.  I'm using a value
 from a
 form to see if it matches in elements in the array.

 My problem is I expect  the condition to be true but info but my DB
 isn't
 populated as I in the right DB...
 =Code
 Begins==
 $theFileArray = file('C:\htdocs\folder1\file.txt');


 Your problem starts here - file returns the file in an array. Each
 element
 of the array corresponds to a line in the file, with the newline
 still
 attached. When you compare to a string without the newline at the
 end, the
 comparison fails.

 If you have php  5.0.0 you can use the FILE_IGNORE_NEW_LINES flag
 in the
 file() arguments, otherwise use trim() to remove trailing whitespace
 from
 the array elements.



 Cheers
 --
 David Robley

 I hate playing craps, Tom said dicily.
 Today is Boomtime, the 16th day of Confusion in the YOLD 3173.

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Not getting expected result from file()

2007-06-11 Thread kvigor
Found out the issue this afternoon.  I realized that my .txt file was tab 
delimited and not space delimited.  So I changed $space to equal $tab and 
query was successful! All is working now. Thanks to all who replied.  I 
appreciate all.

David Robley [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 kvigor wrote:

 Hello,

 I'm using the file function create an array.  I'm using a value from a
 form to see if it matches in elements in the array.

 My problem is I expect  the condition to be true but info but my DB isn't
 populated as I in the right DB...
 =Code
 Begins==
 $theFileArray = file('C:\htdocs\folder1\file.txt');


 Your problem starts here - file returns the file in an array. Each element
 of the array corresponds to a line in the file, with the newline still
 attached. When you compare to a string without the newline at the end, the
 comparison fails.

 If you have php  5.0.0 you can use the FILE_IGNORE_NEW_LINES flag in the
 file() arguments, otherwise use trim() to remove trailing whitespace from
 the array elements.



 Cheers
 -- 
 David Robley

 I hate playing craps, Tom said dicily.
 Today is Boomtime, the 16th day of Confusion in the YOLD 3173. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Not getting expected result from file()

2007-06-10 Thread David Robley
kvigor wrote:

 Hello,
 
 I'm using the file function create an array.  I'm using a value from a
 form to see if it matches in elements in the array.
 
 My problem is I expect  the condition to be true but info but my DB isn't
 populated as I in the right DB...
 =Code
 Begins==
 $theFileArray = file('C:\htdocs\folder1\file.txt');
 

Your problem starts here - file returns the file in an array. Each element
of the array corresponds to a line in the file, with the newline still
attached. When you compare to a string without the newline at the end, the
comparison fails.

If you have php  5.0.0 you can use the FILE_IGNORE_NEW_LINES flag in the
file() arguments, otherwise use trim() to remove trailing whitespace from
the array elements.



Cheers
-- 
David Robley

I hate playing craps, Tom said dicily.
Today is Boomtime, the 16th day of Confusion in the YOLD 3173. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Not getting expected result from file()

2007-06-10 Thread kvigor
Sorry I re-wrote for problem clarity.

FYI whenever I do a var_dump it always shows $stringOne as being 2 
characters less

e.g.
var_dump($foodlandPA[45]);
var_dump($storeInfo);

string(31) Wellston Foodland Wellston OH  string(29) Wellston Foodland 
Wellston OH

kvigor [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hello,

 I'm using the file function to create an array.  I'm also using values 
 from a form to see if it matches any elements in the array.

 My problem is I expect  the condition to be true, but my DB isn't 
 populated as it should be if condition was true.
 =Code 
Begins==
 $theFileArray = file('C:\htdocs\folder1\file.txt');


 if(isset($_POST['strName'], $_POST['strCity'], $_POST['strState']))
 {
 $space =  ;
 $stringOne = $_POST['strName']. $space. $_POST['strCity']. $space . 
 $_POST['strState'];

 }
 //I match the string Grantsville Foodland Grantsville MD letter for 
 letter in the form and form info gets stored in unknown table and not 
 central as it should...?

 if(in_array($stringOne, $theFileArray)) //Any Problem solvers, 
 suggestions, or new ways to code welcome
 {
  $queryCentral = INSERT INTO central (conName, conAddress, conCity,

 conState, conZip, conPhone, schName, schAddress, schCity, schState, 
 schZip, strName,

 strCity, strState) VALUES('$regName', '$regAddress', '$regCity', 
 '$regState',

 '$regZip', '$regPhone', '$sclName', '$sclAddress', '$sclCity', 
 '$sclState',

 '$sclZip', '$stoName', '$stoCity', '$stoState');

  mysql_query($queryCentral, $connection) or die(Query failed: .

 mysql_error($connection));
 }


 else
 {
 $queryUnknown = INSERT INTO unknown (conName, conAddress, conCity, 
 conState,

 conZip, conPhone, schName, schAddress, schCity, schState, schZip, strName, 
 strCity,

 strState) VALUES('$regName', '$regAddress', '$regCity', '$regState', 
 '$regZip',

 '$regPhone', '$sclName', '$sclAddress', '$sclCity', '$sclState', 
 '$sclZip',

 '$stoName', '$stoCity', '$stoState');
 mysql_query($queryUnknown, $connection) or die(Query failed: .

 mysql_error($connection));
 }

 THIS WHAT FILE LOOKS LIKE //Any Problem solvers and suggestion welcome
 =
 Begin Row 1
 Grantsville Foodland Grantsville MD
 Deep Creek Foodland Fresh Mc Henry MD
 Oakland Foodland Oakland MD
 Bridgeport Foodland Bridgeport WV
 Grafton Foodland Grafton WV
 Morgan's Foodland Fresh Kingwood WV
 Petersburg Foodland Petersburg WV
 Rainelle Foodland Rainelle WV
 6th Avenue Foodland St. Albans WV
 Weston Foodland Weston WV
 Ambridge Foodland Ambridge PA
 Curry Hollow Road Foodland Baldwin Pleasant Hills PA
 Tusca Plaza Foodland Fresh Beaver PA
 Bethel Park Foodland Bethel Park PA
 Lebanon Shops Foodland Castle Shannon PA
 Fatur's Foodland Delmont PA
 Ford City Ford City PA
 Glassport Foodland Glassport PA
 Mount Royal Foodland Glenshaw PA
 Grindstone Foodland Grindstone PA
 Kittanning Foodland Kittanning PA
 Mars Foodland Mars PA
 Fifth Avenue Foodland Mc Keesport PA
 Mckees Rocks Mckees Rocks PA
 Monessen Foodland Fresh Monessen PA
 Monongahela Foodland Monongahela PA
 Great Valley Foodland N. Versailles PA
 Gold Crown Foodland Nanty Glo PA
 New Brighton Foodland New Brighton PA
 J  J Foodland New Kensington PA
 Brownsville Road Foodland Pittsburgh PA
 Mt Washington Foodland Fresh Pittsburgh PA
 Beechview Foodland Pittsburgh PA
 Mcneilly Road Foodland Pittsburgh PA
 Rochester Road Foodland Pittsburgh PA
 Pines Plaza Foodland Pittsburgh PA
 Point Marion Foodland Point Marion PA
 Beulah Road Foodland Turtle Creek PA
 Midtown Foodland Uniontown PA
 Henderson Avenue Foodland Washington PA
 Interstate Foodland Washington PA
 Maiden Street Foodland Washington PA
 Buttermilk Hollow Foodland West Mifflin PA
 Village Foodland Fresh West Mifflin PA
 Wellston Foodland Wellston OH
 Westmoreland Foodland Fresh Huntington WV 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Not getting expected result from file()

2007-06-10 Thread Jim Lucas

kvigor wrote:

Sorry I re-wrote for problem clarity.

FYI whenever I do a var_dump it always shows $stringOne as being 2 
characters less


e.g.
var_dump($foodlandPA[45]);
var_dump($storeInfo);

string(31) Wellston Foodland Wellston OH  string(29) Wellston Foodland 
Wellston OH


This would be because of the ' ' and \n at the end of the 31 char line

use trim to remove the white space before your comparison and it should 
work.


One other thing I noticed, in your SQL insert statement, are all 
variables coming from the post?  If so, do you need to reference the 
$_POST['..'] array instead and clean them??


or have you already done that?



kvigor [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

Hello,

I'm using the file function to create an array.  I'm also using values 
from a form to see if it matches any elements in the array.


My problem is I expect  the condition to be true, but my DB isn't 
populated as it should be if condition was true.
 =Code 
Begins==

$theFileArray = file('C:\htdocs\folder1\file.txt');


if(isset($_POST['strName'], $_POST['strCity'], $_POST['strState']))
{
$space =  ;
$stringOne = $_POST['strName']. $space. $_POST['strCity']. $space . 
$_POST['strState'];


}
//I match the string Grantsville Foodland Grantsville MD letter for 
letter in the form and form info gets stored in unknown table and not 
central as it should...?


if(in_array($stringOne, $theFileArray)) //Any Problem solvers, 
suggestions, or new ways to code welcome

{
 $queryCentral = INSERT INTO central (conName, conAddress, conCity,

conState, conZip, conPhone, schName, schAddress, schCity, schState, 
schZip, strName,


strCity, strState) VALUES('$regName', '$regAddress', '$regCity', 
'$regState',


'$regZip', '$regPhone', '$sclName', '$sclAddress', '$sclCity', 
'$sclState',


'$sclZip', '$stoName', '$stoCity', '$stoState');

 mysql_query($queryCentral, $connection) or die(Query failed: .

mysql_error($connection));
}


else
{
$queryUnknown = INSERT INTO unknown (conName, conAddress, conCity, 
conState,


conZip, conPhone, schName, schAddress, schCity, schState, schZip, strName, 
strCity,


strState) VALUES('$regName', '$regAddress', '$regCity', '$regState', 
'$regZip',


'$regPhone', '$sclName', '$sclAddress', '$sclCity', '$sclState', 
'$sclZip',


'$stoName', '$stoCity', '$stoState');
mysql_query($queryUnknown, $connection) or die(Query failed: .

mysql_error($connection));
}

THIS WHAT FILE LOOKS LIKE //Any Problem solvers and suggestion welcome
=
Begin Row 1
Grantsville Foodland Grantsville MD
Deep Creek Foodland Fresh Mc Henry MD
Oakland Foodland Oakland MD
Bridgeport Foodland Bridgeport WV
Grafton Foodland Grafton WV
Morgan's Foodland Fresh Kingwood WV
Petersburg Foodland Petersburg WV
Rainelle Foodland Rainelle WV
6th Avenue Foodland St. Albans WV
Weston Foodland Weston WV
Ambridge Foodland Ambridge PA
Curry Hollow Road Foodland Baldwin Pleasant Hills PA
Tusca Plaza Foodland Fresh Beaver PA
Bethel Park Foodland Bethel Park PA
Lebanon Shops Foodland Castle Shannon PA
Fatur's Foodland Delmont PA
Ford City Ford City PA
Glassport Foodland Glassport PA
Mount Royal Foodland Glenshaw PA
Grindstone Foodland Grindstone PA
Kittanning Foodland Kittanning PA
Mars Foodland Mars PA
Fifth Avenue Foodland Mc Keesport PA
Mckees Rocks Mckees Rocks PA
Monessen Foodland Fresh Monessen PA
Monongahela Foodland Monongahela PA
Great Valley Foodland N. Versailles PA
Gold Crown Foodland Nanty Glo PA
New Brighton Foodland New Brighton PA
J  J Foodland New Kensington PA
Brownsville Road Foodland Pittsburgh PA
Mt Washington Foodland Fresh Pittsburgh PA
Beechview Foodland Pittsburgh PA
Mcneilly Road Foodland Pittsburgh PA
Rochester Road Foodland Pittsburgh PA
Pines Plaza Foodland Pittsburgh PA
Point Marion Foodland Point Marion PA
Beulah Road Foodland Turtle Creek PA
Midtown Foodland Uniontown PA
Henderson Avenue Foodland Washington PA
Interstate Foodland Washington PA
Maiden Street Foodland Washington PA
Buttermilk Hollow Foodland West Mifflin PA
Village Foodland Fresh West Mifflin PA
Wellston Foodland Wellston OH
Westmoreland Foodland Fresh Huntington WV 





--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Unknown

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Not getting expected result from file()

2007-06-10 Thread kvigor
OK, I trimmed the elements in the array. using var_dump() it shows strings 
are identical, however nothing is storing in DB still.

view new code
=//doesn't store in central still, also 
shows no MySQL errors.
$theFileArray = file('C:\htdocs\folder1\file.txt');

function trim_value($value)
{
$value = trim($value);
}

array_walk($theFileArray, 'trim_value');


if(isset($_POST['strName'], $_POST['strCity'], $_POST['strState']))
{
 $space =  ;
 $stringOne = $_POST['strName']. $space. $_POST['strCity']. $space . 
$_POST['strState'];

}
 if(in_array($storeInfo, $theFileArray))
 {
  $queryCentral = INSERT INTO central (conName, conAddress, conCity, 
conState, conZip, conPhone, schName, schAddress, schCity, schState, schZip, 
strName, strCity, strState) VALUES('$regName', '$regAddress', '$regCity', 
'$regState', '$regZip', '$regPhone', '$sclName', '$sclAddress', '$sclCity', 
'$sclState', '$sclZip', '$stoName', '$stoCity', '$stoState');

  mysql_query($queryCentral, $connection) or die(Query failed: . 
mysql_error($connection));
 }


else
{
$queryUnknown = INSERT INTO unknown (conName, conAddress, conCity, 
conState, conZip, conPhone, schName, schAddress, schCity, schState, schZip, 
strName, strCity, strState) VALUES('$regName', '$regAddress', '$regCity', 
'$regState', '$regZip', '$regPhone', '$sclName', '$sclAddress', '$sclCity', 
'$sclState', '$sclZip', '$stoName', '$stoCity', '$stoState');
mysql_query($queryUnknown, $connection) or die(Query failed: . 
mysql_error($connection));
}
=

David Robley [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 kvigor wrote:

 Hello,

 I'm using the file function create an array.  I'm using a value from a
 form to see if it matches in elements in the array.

 My problem is I expect  the condition to be true but info but my DB isn't
 populated as I in the right DB...
 =Code
 Begins==
 $theFileArray = file('C:\htdocs\folder1\file.txt');


 Your problem starts here - file returns the file in an array. Each element
 of the array corresponds to a line in the file, with the newline still
 attached. When you compare to a string without the newline at the end, the
 comparison fails.

 If you have php  5.0.0 you can use the FILE_IGNORE_NEW_LINES flag in the
 file() arguments, otherwise use trim() to remove trailing whitespace from
 the array elements.



 Cheers
 -- 
 David Robley

 I hate playing craps, Tom said dicily.
 Today is Boomtime, the 16th day of Confusion in the YOLD 3173. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Not getting expected result from file()

2007-06-10 Thread kvigor
Trimmed elements in the array.  I still can't get it to store in central 
table.  No MySQL errors either. :-(
 (Also, all form values are escaped.) Strings compared in if condition are 
now identical.


newcode
===
theFileArray = file('C:\htdocs\folder1\file.txt');

function trim_value($value)
{
$value = trim($value);
}

array_walk($theFileArray, 'trim_value');


if(isset($_POST['strName'], $_POST['strCity'], $_POST['strState']))
{
 $space =  ;
 $stringOne = $_POST['strName']. $space. $_POST['strCity']. $space . 
$_POST['strState'];
}

 if(in_array($stringOne, $theFileArray)) // string were identical after I 
trimmed an did var_dump on $stringOne and $theFileArray[2]
 {
  $queryCentral = INSERT INTO central (conName, conAddress, conCity, 
conState, conZip, conPhone, schName, schAddress, schCity, schState, schZip, 
strName, strCity, strState) VALUES('$regName', '$regAddress', '$regCity', 
'$regState', '$regZip', '$regPhone', '$sclName', '$sclAddress', '$sclCity', 
'$sclState', '$sclZip', '$stoName', '$stoCity', '$stoState');

  mysql_query($queryCentral, $connection) or die(Query failed: . 
mysql_error($connection));
 }


else
{
$queryUnknown = INSERT INTO unknown (conName, conAddress, conCity, 
conState, conZip, conPhone, schName, schAddress, schCity, schState, schZip, 
strName, strCity, strState) VALUES('$regName', '$regAddress', '$regCity', 
'$regState', '$regZip', '$regPhone', '$sclName', '$sclAddress', '$sclCity', 
'$sclState', '$sclZip', '$stoName', '$stoCity', '$stoState');
mysql_query($queryUnknown, $connection) or die(Query failed: . 
mysql_error($connection));
}

David Robley [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 kvigor wrote:

 Hello,

 I'm using the file function create an array.  I'm using a value from a
 form to see if it matches in elements in the array.

 My problem is I expect  the condition to be true but info but my DB isn't
 populated as I in the right DB...
 =Code
 Begins==
 $theFileArray = file('C:\htdocs\folder1\file.txt');


 Your problem starts here - file returns the file in an array. Each element
 of the array corresponds to a line in the file, with the newline still
 attached. When you compare to a string without the newline at the end, the
 comparison fails.

 If you have php  5.0.0 you can use the FILE_IGNORE_NEW_LINES flag in the
 file() arguments, otherwise use trim() to remove trailing whitespace from
 the array elements.



 Cheers
 -- 
 David Robley

 I hate playing craps, Tom said dicily.
 Today is Boomtime, the 16th day of Confusion in the YOLD 3173. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php