I think you people did not understand me right:
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!