- Joined
- Jun 14, 2004
- Posts
- 11,071
- Reaction score
- 951
Hi,
I want to update a MySQL DB I have with the contents from a text file but it's a bit beyond me.
I connect to my DB
Search for a Domain Name against one from the text file.
Now I want to update 1 field for that Domains record from the text file, this is what I am using:
When I run it tells me there is an error near 'expiration'.
Any help would be appreciated.
Admin
I want to update a MySQL DB I have with the contents from a text file but it's a bit beyond me.
I connect to my DB
Search for a Domain Name against one from the text file.
Now I want to update 1 field for that Domains record from the text file, this is what I am using:
Code:
<?php
if ($_REQUEST["do"]!="update") {
?>
<form enctype="multipart/form-data" action="update.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="hidden" name="do" value="update" />
<input type="submit" value="Update" />
</form>
<?php } else {
$ok=1;
$db = mysql_pconnect($hostname_db, $username_db, $password_db) or die(mysql_error());
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
echo "The file has been uploaded, now processing....";
$row = 0;
$handle = fopen($target, "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> Checking : $data[0]\n";
$sql = "SELECT Domain_Name FROM domains WHERE Domain_Name = '$data[0]'";
mysql_select_db($database_db, $db);
$query_Search = $sql;
$Search = mysql_query($query_Search, $db) or die(mysql_error());
$row_Search = mysql_fetch_assoc($Search);
$all_Search = mysql_query($query_Search);
$totalRows_Search = mysql_num_rows($all_Search);
if ($totalRows_Search !=0){
echo " -> updating domains\n";
$sql = " ";
$sql= "UPDATE `domains` SET (`expiration`) VALUES ('','";
$sql .= $data[1] ."');";
mysql_select_db($database_db, $db);
$query_Search = $sql;
$Search = mysql_query($query_Search, $db) or die(mysql_error());
echo " -> completed<br /></p>\n";
$row++;
}
}
fclose($handle);
echo "<p> ". $row." domains updated.<br /></p>\n";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
}
?>
When I run it tells me there is an error near 'expiration'.
Any help would be appreciated.
Admin