![]() |
|
| Domain Name Sales | Domain Software | Calculate UK Domain Drop Dates | Domain Registration | NameDrive | Domain Parking |
| |||||||
| Scripts and Coding PHP, MySQL, scripts |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| Administrator | Update MySQL from a text file
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: 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.";
}
}
?> Any help would be appreciated. Admin |
| |
| | #2 (permalink) |
![]() |
First I would suggest that for: $sql= "UPDATE `domains` SET (`expiration`) VALUES ('','"; $sql .= $data[1] ."');"; try writing it all as one line instead of splitting it over two lines. If that doesn't help, check carefully that all your single quotes and double quotes in this line are right as errors are often related to that. Hope that helps. Rgds
__________________ My Twitter | KeyphraseDomains.co.uk | Mens Shirts | Hotels in Bath | Money Off Code |
| |
| | #3 (permalink) |
![]() |
This might work: $sql= "UPDATE `domains` SET (`expiration`) VALUES ('','". $data[1] ."');"; I think you might have been missing a full stop, I feel the error is probably around the $data statement anyway. Hope that might help. Rgds
__________________ My Twitter | KeyphraseDomains.co.uk | Mens Shirts | Hotels in Bath | Money Off Code Last edited by accelerator; 15-06-2008 at 08:17:24 PM. |
| |
| | #4 (permalink) |
![]() |
I use Navicat for really simple stuff like this. No point in creating a script for something so simple IMHO.
|
| |
| | #6 (permalink) |
![]() |
$sql= "UPDATE `domains` SET (`expiration`) VALUES ('','"; $sql .= $data[1] ."');"; should be $sql= "UPDATE `domains` SET (`expiration`) VALUES ('"; $sql .= $data[1] ."');"; You've got one to many parameters in the values bit. |
| |
| | #7 (permalink) | |
| Administrator | Quote:
Thanks for the help Last edited by admin; 15-06-2008 at 09:36:39 PM. | |
| |
| | #8 (permalink) |
![]() |
Ah you're doing an UPDATE statement in the format of an INSERT you need to do something like $sql= "UPDATE `domains` SET `expiration` = '". $data[1] ."';"; I also notice you need to trim that space in the date |
| |
| | #9 (permalink) |
| Administrator |
Your command works but over-wrote every domain in the DB with the value from the first domain in the text file. Basically, I need it to match each domain in the file and update the expiration date with the one also in the file relevant to that particular domain. thanks |
| |
| | #10 (permalink) |
![]() |
You're missing your WHERE clause on the update statement try: $sql= "UPDATE `domains` SET `expiration` = '". $data[1] ."' WHERE `Domain_Name` = '".$data[0] ."' ;"; ensuring that Domain_Name is the actual column name DISCLAIMER: Run at your own risk |
| |
![]() |
| Bookmarks |
| Tags |
| update mysql text file |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Domain Name Community | Replies | Last Post |
| Revenue Update | NameDriver | NameDrive | 0 | 06-05-2008 08:05:51 PM |
| MySQL help | fish | Services Wanted | 9 | 10-09-2007 10:59:49 AM |
| UK Zone File - where can I find the last publically released version (2003)? | TravelSite | Domain Research | 2 | 08-03-2007 11:31:08 AM |
| Help with Photoshop PSD file | admin | Website Design | 3 | 26-05-2006 10:36:51 PM |