Current location: Hot Scripts Forums » Programming Languages » PHP » Need help with PHP code


Need help with PHP code

Reply
  #1 (permalink)  
Old 05-21-04, 09:28 AM
rodman rodman is offline
New Member
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Need help with PHP code

I need to fetch data from mySQL database and update existing Array in a PHP file


Here is file which should update my Array in PHP file:

<?php
/* Connecting, selecting database */
$link = mysql_connect("localhost", "user", "pass")
or die("Could not connect : " . mysql_error());
echo "Connected successfully";
mysql_select_db("helpdemo_xcart") or die("Could not select database");

/* Performing SQL query */
$query = "SELECT url FROM xcart_customers";
$result = mysql_query($query) or die("Query failed : " . mysql_error());

/* Inserting results in alowed IP file */

while ($row = mysql_fetch_array($result)) {
extract($row);
$line[] = $result; /* I think mistake is here but I do not know how to fiks it */
}


//Open a file in write mode
$fp = fopen("key.php", "w");
if(fwrite($fp, $line)) echo "writing=Ok";
else echo "writing=Error";
fclose($fp);


/* Free resultset */
mysql_free_result($result);

/* Closing connection */
mysql_close($link);
?>

And here is my PHP file(key.php):

<?php

$line = array("195.39.35.31","81.0.235.34","217.11.238.194 ");

foreach($line as $ip)
{
if($ip == $_SERVER[REMOTE_ADDR])
{
$allowaccess = 1;
}
}

if($allowaccess)
{
echo "Comments=2";
}

else
{
echo "Comments=3";
}

?>

What I need is to update my array $line with new values from database. The first file should do the job but it does not work.



So I need to update my Array with new info from mySQL table.


any advices are welcome

Thanks a lot!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 04:03 AM
Use this code outside of PHP tags? D_tunisia PHP 6 04-12-04 12:06 PM
How to sale php code to customer without giving him code pradeep_soft PHP 4 03-12-04 12:10 PM
Generating PHP code for MySQL ptesone General Advertisements 1 02-03-04 08:26 AM
protecting code in PHP ckb PHP 12 01-02-04 08:53 AM


All times are GMT -5. The time now is 10:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.