Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page PHP to MYSQL varables
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
Member
caboose9792 is on a distinguished road
 
Posts: 55
Join Date: Oct 2010
Default PHP to MYSQL varables - 07-17-2012, 02:38 AM

Working from a backup trying to merge the valid data onto the clipped data. From my backup I have tab delimited text in which to insert the correct data from. I wrote a simple (ha ha ha) program to quickly patch the issue. The data from the txt page to the MYSQL makes it ok but no matches are ever found. If I add some code to manually set the variables it works fine. It is like there is two different languages in play there both the same style code and the variables are the same type and I have manually confirmed the data.


Code snip it that the trouble is occurring on:

$fp = fopen ( "tracedata.txt" , "r" );

//feof setting maxamum number of loop with the count of lines to be run

while (!feof($fp)) { $data =fgets ($fp);

$data = preg_split ( "#/\t/#" , $data);

// clean up the split
$road =trim($data[0]);
$numb =trim($data[1]);
$date =trim($data[3]);
$symbol =trim($data[2]);
$notes =trim($data[4]);
//row 35
// mysql adminastrative
$conn = mysql_connect( $mysql_host , $mysql_user , $mysql_password )or die(mysql_error());
$db = mysql_select_db( $mysql_database , $conn )or die(mysql_error());

//mysql serch for $rd , $nm,
$result = mysql_query("SELECT *
FROM `palpower`
WHERE `road` = '$road'
AND `number` = '$numb'
AND `last_date` = '$date'
LIMIT 1
");
print"$row<br>";
$row = mysql_fetch_assoc($result) or die(mysql_error());
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 762
Join Date: Dec 2010
Default 07-17-2012, 03:22 AM

Do you have any specific reason to use preg_split()?
If the delimiter is tab, how about changing as follows:

PHP Code:
$fp fopen "tracedata.txt" "r" );

while (!
feof($fp)) { $data =fgets($fp);
list(
$road$numb$symbol$date$notes) = $array
$array 
split("\t"$data);

$road trim($array[0]);
$numb trim($array[1]);
.
.
.

$row mysql_fetch_assoc($result) or die(mysql_error()); //This line should come before print command.
print"$row<br>"

Last edited by grace1004; 07-17-2012 at 06:43 AM.
Reply With Quote
(#3 (permalink))
Old
Leder678's Avatar
Senior Member
Leder678 is on a distinguished road
 
Posts: 1,618
Join Date: Jan 2009
Location: Norway
Send a message via MSN to Leder678
Default 07-17-2012, 05:44 AM

grace1004:
The split function is deprecated, so I would use one of the alternatives in the list in the php page:
http://php.net/manual/en/function.split.php

try using print_r to manually check the $data array for any mistakes the split funktion might cause


Follow me on twitter @Mortenrb

W3Fools - Read and learn

Please AT LEAST read the 10 bolded lines of the TOS at:
http://www.000webhost.com/includes/tos.php
Reply With Quote
(#4 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 762
Join Date: Dec 2010
Default 07-17-2012, 06:12 AM

Leder678:
The split() function is depreciated as of php 5.3.x. As the php version of 000webhost.com server is
5.2.x, it's still O.K. to use split() function in this hosting.

caboose9792:
In case php version of your hosting server is 5.3.x, you can use explode() function
instead of split() function.

Last edited by grace1004; 07-17-2012 at 06:47 AM.
Reply With Quote
(#5 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 6,620
Join Date: Jul 2009
Location: Spain
Default 07-17-2012, 08:29 AM

Hi,

Avoid using files with txt extension. The server usually block / disallow.


Recuerda realizar copias de seguridad de tus sitios web. Si este mensaje te ayudó puedes pulsar sobre el botón karma
Reply With Quote
(#6 (permalink))
Old
Member
caboose9792 is on a distinguished road
 
Posts: 55
Join Date: Oct 2010
Default 07-17-2012, 09:44 PM

There isn't ant other options that I aware of and the fear of the TXT is rather irrational. So what TXT like file can 000 host both write and read without running afoul of the TOS and still be usable?
Reply With Quote
(#7 (permalink))
Old
Member
caboose9792 is on a distinguished road
 
Posts: 55
Join Date: Oct 2010
Default 07-17-2012, 10:10 PM

Quote:
Originally Posted by Leder678 View Post
grace1004:
The split function is deprecated, so I would use one of the alternatives in the list in the php page:
http://php.net/manual/en/function.split.php

try using print_r to manually check the $data array for any mistakes the split function might cause
*************
I have and everything looks good. if I use

if I preload with valid data such as:
$road= PAL
$numb = 1998
$date = (valid date code)
under the fopen to replace the file data the data passes though correctly. I also have access to the other side of the code that goes from my backup file to the TXT code.


Maybe the issue is on this side:

while ($count <= 499) {

//mysql serch for data if it exist
$result = $result = mysql_query("
SELECT *
FROM `palpower`
WHERE `vpbkey` = '$akey'
LIMIT 1 ")
or die(mysql_error());

$row=mysql_fetch_assoc($result);

$road = $row["road"];
$numb = $row["number"];
$notes = $row["notes"];
$date =$row["last_date"];
$symbol =$row["symbol"];

$newrecord =$road."\t".$numb."\t".$symbol."\t".$date."\t".$no tes."\n";

// file system sign in & out and data preperation

$fp = fopen("tracedata.txt", "a");
fputs ($fp,$newrecord);
fclose($fp);

To further muddy the waters, I was successfully using the program for a few cycles and it worked fine. I stopped to spread my SQL usage out even more than usual and it stopped working when I tried to resume which seems odd in itself. Both sets of data are on 000 host just different servers (if one bits the dust all is not lost). The site itself is a low volume of data and visitor hobby site so there isn't tons of data to be dealt with I just haven't seen anything quite like this before .
Reply With Quote
(#8 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 762
Join Date: Dec 2010
Default 07-18-2012, 01:12 AM

I tested my code above and it did not work. So, I changed it as shown below and it works fine.

PHP Code:
$fp fopen "tracedata.txt" "r" ); 

while (!
feof($fp)) {$data =fgets($fp); 
list(
$road$numb$symbol$date$notes) = explode("\t"$data);

$road trim($road);
$numb trim($numb); 



echo 
$road//To test $road is getting data from the txt file.

.
.
.

$row mysql_fetch_assoc($result) or die(mysql_error()); //This line should come before print command.
 
print "$row['road']<br>";  
print 
"$row['number']<br>";
.
.
}
?> 

Last edited by grace1004; 07-18-2012 at 01:16 AM.
Reply With Quote
(#9 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 762
Join Date: Dec 2010
Default 07-18-2012, 01:26 AM

Regarding txt file, I found that to use txt file within php script is O.K. in 000webhost.com server.
However, to write something in txt file through cron job is not allowed in this hosting. In case
the file is executed manually (not by cron job), it works fine.

Last edited by grace1004; 07-18-2012 at 01:39 AM.
Reply With Quote
(#10 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 6,620
Join Date: Jul 2009
Location: Spain
Default 07-18-2012, 09:42 AM

Quote:
Originally Posted by grace1004 View Post
Regarding txt file, I found that to use txt file within php script is O.K. in 000webhost.com server.
However, to write something in txt file through cron job is not allowed in this hosting. In case
the file is executed manually (not by cron job), it works fine.
Are they working properly txt files?

It's new news to me. Thanks grace1004 for the information.
A greeting.


Recuerda realizar copias de seguridad de tus sitios web. Si este mensaje te ayudó puedes pulsar sobre el botón karma
Reply With Quote
Reply

Tags
mysql problem, mysql query, php

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com