Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
inserting array into database
Old 04-06-2009, 10:45 AM inserting array into database
Average Talker

Posts: 26
Trades: 0
Hi,

When inserting my array into my database, I look up the values in the table and it just appears as; NULL, NULL, NULL. is there anything i can do to my code to stop this. I hear i need to use serialize, but im not quite sure how to use this function. this is my code;

function opening($file)
{
$pattern = "(\.txt$)| (\.php$)";
if(eregi($pattern, $file)){
$file_handle = fopen($file, "r");
$contents = file($file);
while (!feof($file_handle)){
$data = fgets($file_handle);
$words = explode(' ' , $data);
foreach($words as $word)
{
$sql = "INSERT INTO webdata VALUES($word);";
if (mysql_query($sql)){
print "successful <p>";
}
}
}
}
else {
echo "Cant open that file type <p>"; }
}
function getfiles($dirname=".") {
$pattern = "(\.txt$)| (\.php$)";
$files = array();
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file) || is_dir($file))
echo "$file <br />";
opening($file);

}
closedir($handle);
}
return($files);
}
applebiz89 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-06-2009, 12:59 PM Re: inserting array into database
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
http://uk2.php.net/manual/en/function.serialize.php

PHP Code:

function opening($file)
{
$pattern "(\.txt$)| (\.php$)";
if(
eregi($pattern$file)){
$file_handle fopen($file"r");
$contents file($file);
while (!
feof($file_handle)){
$data fgets($file_handle);
$words explode(' ' $data);
foreach(
$words as $word)
{
$word serialize($word); // added this
$sql "INSERT INTO webdata VALUES($word);"// Kinda annoying code, you need to seralize the value.
if (mysql_query($sql)){
print 
"successful <p>";
}
}
}
}
else {
echo 
"Cant open that file type <p>"; }
}
function 
getfiles($dirname=".") {
$pattern "(\.txt$)| (\.php$)";
$files = array();
if(
$handle opendir($dirname)) {
while(
false !== ($file readdir($handle))){
if(
eregi($pattern$file) || is_dir($file))
echo 
"$file <br />";
opening($file);

}
closedir($handle);
}
return(
$files);

__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-07-2009, 05:21 AM Re: inserting array into database
Average Talker

Posts: 26
Trades: 0
cheers. However it isnt inserting into database now which is annoying. What do you mean by annoying code, any pointers how to improve this?
applebiz89 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to inserting array into database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16540 seconds with 12 queries