I used the following code to update one column of a table, but it also delete values of other columns, I couldn't find the reason. Please help.
$handle = fopen($_FILES['filename']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if($data[0]=='NULL'){
$import="UPDATE tst_stores SET store_image_url = 'http://admin.showcasejewellers.com.au/uploads/default_store.jpg' ";
}
else{
$import="UPDATE tst_stores SET store_image_url = 'http://admin.showcasejewellers.com.au/uploads/" . mysql_real_escape_string($data[0]) . ".jpg'";
}
mysql_query($import) or die(mysql_error());
}
fclose($handle);
Your SQL
query is wrong. You have to specify which row you want to update using WHERE
clause. For example
UPDATE tst_stores SET store_image_url = 'http://admin.showcasejewellers.com.au/uploads/default_store.jpg' WHERE tst_stores.id = 10;
This will update only the row where column id is equal to 10.
Note: I just assumed table tst_stores
has id
column is exists and primary key. You have to change accordingly
Just check this link for further reading.