I have the code below, and the issue I'm having is when you run the script the first time in your browser and say the url is:
filename.php?option=append
That works fine. But say you edit the url to:
filename.php?option=redo
while still in the same browser window and then hit the green GO button on internet explorer. The message comes up saying the database rebuild was successful, but it actually doesnt do the rebuild. You actually have to hit the Refresh button in IE to make the MySQL rebuild actually occur. Does anyone know why?
I find it wierd it echoes the right text but doesnt perform the other code. Please help
PHP Code:<?php
if($_GET['option'] == "")
{
$_GET['option'] = "append";
}
require('databaseparameters.php');
if($_GET['option'] == "append")
{
$fcontents = file ($csv_filename);
$dbh = mysql_connect("localhost", $db_user, $db_pass);
mysql_select_db($db_name);
for($i=0; $i<sizeof($fcontents); $i++)
{
if($i != 0)
{
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
$sql = "INSERT INTO ".$table_name." VALUES ('".implode("','", $arr) ."')";
mysql_query($sql);
}
}
echo "Data Appended To MySQL Database!";
}
elseif($_GET['option'] == "redo")
{
$fcontents = file ($csv_filename);
$dbh = mysql_connect("localhost", $db_user, $db_pass);
mysql_select_db($db_name);
//EMPTY THE TABLE FIRST
$sql = "DELETE FROM ".$table_name;
mysql_query($sql);
for($i=0; $i<sizeof($fcontents); $i++)
{
if($i != 0)
{
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
$sql = "INSERT INTO ".$table_name." VALUES ('".implode("','", $arr) ."')";
mysql_query($sql);
}
}
echo "MySQL Database Rebuild Complete!";
}
else
{
echo "Error: Option Invalid";
}
?><?php
if($_GET['option'] == "")
{
$_GET['option'] = "append";
}
require('databaseparameters.php');
if($_GET['option'] == "append")
{
$fcontents = file ($csv_filename);
$dbh = mysql_connect("localhost", $db_user, $db_pass);
mysql_select_db($db_name);
for($i=0; $i<sizeof($fcontents); $i++)
{
if($i != 0)
{
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
$sql = "INSERT INTO ".$table_name." VALUES ('".implode("','", $arr) ."')";
mysql_query($sql);
}
}
echo "Data Appended To MySQL Database!";
}
elseif($_GET['option'] == "redo")
{
$fcontents = file ($csv_filename);
$dbh = mysql_connect("localhost", $db_user, $db_pass);
mysql_select_db($db_name);
//EMPTY THE TABLE FIRST
$sql = "DELETE FROM ".$table_name;
mysql_query($sql);
for($i=0; $i<sizeof($fcontents); $i++)
{
if($i != 0)
{
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
$sql = "INSERT INTO ".$table_name." VALUES ('".implode("','", $arr) ."')";
mysql_query($sql);
}
}
echo "MySQL Database Rebuild Complete!";
}
else
{
echo "Error: Option Invalid";
}
?>




Reply With Quote