How to UPDATE a column without affecting the others?
I have this code to update a record from my database, usually i will update only one column, example: on the array i have 6 columns listed, i want to only update the column keywords
, and the other columns should not me affected.
With this code i can update my records but not a especifc column, because if i write something on the input name="keywords"
and writte nothing on the other inputs, the column values from these input will be replaced with none values on my database.
My question is:
How to updade a column without affecting the others?
if(isset($_POST["updateBTN"])){
$insert_data = array(
':title' => $_POST['title'],
':keywords' => $_POST['keywords'],
':img' => $_POST['img'],
':widht' => $_POST['widht'],
':status' => $_POST['status'],
':name' => $_POST['name'],
':height' => $_POST['height']
);
$query = "UPDATE table SET keywords = :keywords, img = :img, widht = :widht, status = :status, name = :name, height = :height WHERE title = :title";
$statement = $conn->prepare($query);
$statement->execute($insert_data);
}
html:
<form method="post">
<div>
<input type="text" name="title">
<span data-placeholder="Title"></span>
</div>
<div>
<input type="text" name="keywords">
<span data-placeholder="keywords"></span>
</div>
.
.
.
<button type="submit" name="updateBTN">Send</button>
</form>
php sql forms post sql-update
add a comment |
I have this code to update a record from my database, usually i will update only one column, example: on the array i have 6 columns listed, i want to only update the column keywords
, and the other columns should not me affected.
With this code i can update my records but not a especifc column, because if i write something on the input name="keywords"
and writte nothing on the other inputs, the column values from these input will be replaced with none values on my database.
My question is:
How to updade a column without affecting the others?
if(isset($_POST["updateBTN"])){
$insert_data = array(
':title' => $_POST['title'],
':keywords' => $_POST['keywords'],
':img' => $_POST['img'],
':widht' => $_POST['widht'],
':status' => $_POST['status'],
':name' => $_POST['name'],
':height' => $_POST['height']
);
$query = "UPDATE table SET keywords = :keywords, img = :img, widht = :widht, status = :status, name = :name, height = :height WHERE title = :title";
$statement = $conn->prepare($query);
$statement->execute($insert_data);
}
html:
<form method="post">
<div>
<input type="text" name="title">
<span data-placeholder="Title"></span>
</div>
<div>
<input type="text" name="keywords">
<span data-placeholder="keywords"></span>
</div>
.
.
.
<button type="submit" name="updateBTN">Send</button>
</form>
php sql forms post sql-update
add a comment |
I have this code to update a record from my database, usually i will update only one column, example: on the array i have 6 columns listed, i want to only update the column keywords
, and the other columns should not me affected.
With this code i can update my records but not a especifc column, because if i write something on the input name="keywords"
and writte nothing on the other inputs, the column values from these input will be replaced with none values on my database.
My question is:
How to updade a column without affecting the others?
if(isset($_POST["updateBTN"])){
$insert_data = array(
':title' => $_POST['title'],
':keywords' => $_POST['keywords'],
':img' => $_POST['img'],
':widht' => $_POST['widht'],
':status' => $_POST['status'],
':name' => $_POST['name'],
':height' => $_POST['height']
);
$query = "UPDATE table SET keywords = :keywords, img = :img, widht = :widht, status = :status, name = :name, height = :height WHERE title = :title";
$statement = $conn->prepare($query);
$statement->execute($insert_data);
}
html:
<form method="post">
<div>
<input type="text" name="title">
<span data-placeholder="Title"></span>
</div>
<div>
<input type="text" name="keywords">
<span data-placeholder="keywords"></span>
</div>
.
.
.
<button type="submit" name="updateBTN">Send</button>
</form>
php sql forms post sql-update
I have this code to update a record from my database, usually i will update only one column, example: on the array i have 6 columns listed, i want to only update the column keywords
, and the other columns should not me affected.
With this code i can update my records but not a especifc column, because if i write something on the input name="keywords"
and writte nothing on the other inputs, the column values from these input will be replaced with none values on my database.
My question is:
How to updade a column without affecting the others?
if(isset($_POST["updateBTN"])){
$insert_data = array(
':title' => $_POST['title'],
':keywords' => $_POST['keywords'],
':img' => $_POST['img'],
':widht' => $_POST['widht'],
':status' => $_POST['status'],
':name' => $_POST['name'],
':height' => $_POST['height']
);
$query = "UPDATE table SET keywords = :keywords, img = :img, widht = :widht, status = :status, name = :name, height = :height WHERE title = :title";
$statement = $conn->prepare($query);
$statement->execute($insert_data);
}
html:
<form method="post">
<div>
<input type="text" name="title">
<span data-placeholder="Title"></span>
</div>
<div>
<input type="text" name="keywords">
<span data-placeholder="keywords"></span>
</div>
.
.
.
<button type="submit" name="updateBTN">Send</button>
</form>
php sql forms post sql-update
php sql forms post sql-update
edited Nov 21 '18 at 18:54
111111111111
asked Nov 21 '18 at 16:48
111111111111111111111111
489
489
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can either change your SQL query to only update the columns for which you have data, or populate any undefined values in $insert_data
using values retrieved from the database. The first is probably a better idea, but the second is easier to implement.
I haven't written PHP in a bit, but maybe something like:
if(isset($_POST["updateBTN"])) {
$query = "SELECT title, keywords, img, widht, staus, name, height FROM table WHERE title = :title";
$stmt = $conn->prepare($query);
$stmt->execute(array(":title" => $_POST['title']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$insert_data = array(
':title' => $_POST['title'] ? $_POST['title'] : $row['title'],
':keywords' => $_POST['keywords'] ? $_POST['keywords'] : $row['keywords'],
...
);
$query = "UPDATE table SET keywords = :keywords, img = :img, widht = :widht, status = :status, name = :name, height = :height WHERE title = :title";
$statement = $conn->prepare($query);
$statement->execute($insert_data);
}
I got a errorFatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2031 in ... PDO->query('SELECT title, k...')
. People don't update records on this way? I felt that this was a easy question.
– 111111111111
Nov 21 '18 at 18:53
Make sure to double check my code; like I said, I haven't coded PHP in a long time (and so another response to you; I don't update records in this way. I usually use an ORM, or a framework with an ORM such as Django, Ruby on Rails, Phoenix, etc.).
– Charles
Nov 22 '18 at 19:20
I updated the answer; let me know if it works so I can sleep at night :).
– Charles
Nov 22 '18 at 19:26
Sadly not :/ i got this error:Notice: Trying to get property 'num_rows' of non-object
and Undefinet variable $row into the array. I'm almost giving up. I think i will use pure SQL on database to update my records. Thanks anyways.
– 111111111111
Nov 22 '18 at 20:53
Changed again; maybe you can try debugging the errors, since you have a system setup?
– Charles
Nov 22 '18 at 21:40
|
show 1 more comment
Assuming you don't want to set any of the columns to NULL
values, you can use COALESCE()
:
UPDATE table
SET keywords = COALESCE(:keywords, keywords),
img = COALESCE(:img, img),
widht = COALESCE(:widht, widht),
status = COALESCE(:status, status),
name = COALESCE(:name, name),
height = COALESCE(:height height)
WHERE title = :title;
The columns is not getting NULL values, i just want to update only one column, when i set the value only on a single input the others columns get replaced with none values. I tryed your code, but it's getting the same.
– 111111111111
Nov 21 '18 at 17:06
@515948453225 . . . "none" is not a database concept. What database are you using?COALESCE()
should work, assuming the missing values are passed in asNULL
.
– Gordon Linoff
Nov 22 '18 at 0:35
I'm using phpmyadmin.Withnone value
, i meant that the value on column remains blank, and not asNULL
, just a blank space without data.
– 111111111111
Nov 22 '18 at 2:02
add a comment |
see if this works
UPDATE table
SET keywords = :keywords,
img = CASE WHEN img IS NOT NULL THEN img ELSE :img END,
widht = CASE WHEN widht IS NOT NULL THEN widt ELSE :widht END,
status = CASE WHEN status IS NOT NULL THEN status ELSE :status END,
name = CASE WHEN name IS NOT NULL name ELSE :name END,
height = CASE WHEN height IS NOT NULL THEN height ELSE :height END
WHERE title = :title;
No, it's not even updating my record :/
– 111111111111
Nov 21 '18 at 17:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416891%2fhow-to-update-a-column-without-affecting-the-others%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can either change your SQL query to only update the columns for which you have data, or populate any undefined values in $insert_data
using values retrieved from the database. The first is probably a better idea, but the second is easier to implement.
I haven't written PHP in a bit, but maybe something like:
if(isset($_POST["updateBTN"])) {
$query = "SELECT title, keywords, img, widht, staus, name, height FROM table WHERE title = :title";
$stmt = $conn->prepare($query);
$stmt->execute(array(":title" => $_POST['title']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$insert_data = array(
':title' => $_POST['title'] ? $_POST['title'] : $row['title'],
':keywords' => $_POST['keywords'] ? $_POST['keywords'] : $row['keywords'],
...
);
$query = "UPDATE table SET keywords = :keywords, img = :img, widht = :widht, status = :status, name = :name, height = :height WHERE title = :title";
$statement = $conn->prepare($query);
$statement->execute($insert_data);
}
I got a errorFatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2031 in ... PDO->query('SELECT title, k...')
. People don't update records on this way? I felt that this was a easy question.
– 111111111111
Nov 21 '18 at 18:53
Make sure to double check my code; like I said, I haven't coded PHP in a long time (and so another response to you; I don't update records in this way. I usually use an ORM, or a framework with an ORM such as Django, Ruby on Rails, Phoenix, etc.).
– Charles
Nov 22 '18 at 19:20
I updated the answer; let me know if it works so I can sleep at night :).
– Charles
Nov 22 '18 at 19:26
Sadly not :/ i got this error:Notice: Trying to get property 'num_rows' of non-object
and Undefinet variable $row into the array. I'm almost giving up. I think i will use pure SQL on database to update my records. Thanks anyways.
– 111111111111
Nov 22 '18 at 20:53
Changed again; maybe you can try debugging the errors, since you have a system setup?
– Charles
Nov 22 '18 at 21:40
|
show 1 more comment
You can either change your SQL query to only update the columns for which you have data, or populate any undefined values in $insert_data
using values retrieved from the database. The first is probably a better idea, but the second is easier to implement.
I haven't written PHP in a bit, but maybe something like:
if(isset($_POST["updateBTN"])) {
$query = "SELECT title, keywords, img, widht, staus, name, height FROM table WHERE title = :title";
$stmt = $conn->prepare($query);
$stmt->execute(array(":title" => $_POST['title']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$insert_data = array(
':title' => $_POST['title'] ? $_POST['title'] : $row['title'],
':keywords' => $_POST['keywords'] ? $_POST['keywords'] : $row['keywords'],
...
);
$query = "UPDATE table SET keywords = :keywords, img = :img, widht = :widht, status = :status, name = :name, height = :height WHERE title = :title";
$statement = $conn->prepare($query);
$statement->execute($insert_data);
}
I got a errorFatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2031 in ... PDO->query('SELECT title, k...')
. People don't update records on this way? I felt that this was a easy question.
– 111111111111
Nov 21 '18 at 18:53
Make sure to double check my code; like I said, I haven't coded PHP in a long time (and so another response to you; I don't update records in this way. I usually use an ORM, or a framework with an ORM such as Django, Ruby on Rails, Phoenix, etc.).
– Charles
Nov 22 '18 at 19:20
I updated the answer; let me know if it works so I can sleep at night :).
– Charles
Nov 22 '18 at 19:26
Sadly not :/ i got this error:Notice: Trying to get property 'num_rows' of non-object
and Undefinet variable $row into the array. I'm almost giving up. I think i will use pure SQL on database to update my records. Thanks anyways.
– 111111111111
Nov 22 '18 at 20:53
Changed again; maybe you can try debugging the errors, since you have a system setup?
– Charles
Nov 22 '18 at 21:40
|
show 1 more comment
You can either change your SQL query to only update the columns for which you have data, or populate any undefined values in $insert_data
using values retrieved from the database. The first is probably a better idea, but the second is easier to implement.
I haven't written PHP in a bit, but maybe something like:
if(isset($_POST["updateBTN"])) {
$query = "SELECT title, keywords, img, widht, staus, name, height FROM table WHERE title = :title";
$stmt = $conn->prepare($query);
$stmt->execute(array(":title" => $_POST['title']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$insert_data = array(
':title' => $_POST['title'] ? $_POST['title'] : $row['title'],
':keywords' => $_POST['keywords'] ? $_POST['keywords'] : $row['keywords'],
...
);
$query = "UPDATE table SET keywords = :keywords, img = :img, widht = :widht, status = :status, name = :name, height = :height WHERE title = :title";
$statement = $conn->prepare($query);
$statement->execute($insert_data);
}
You can either change your SQL query to only update the columns for which you have data, or populate any undefined values in $insert_data
using values retrieved from the database. The first is probably a better idea, but the second is easier to implement.
I haven't written PHP in a bit, but maybe something like:
if(isset($_POST["updateBTN"])) {
$query = "SELECT title, keywords, img, widht, staus, name, height FROM table WHERE title = :title";
$stmt = $conn->prepare($query);
$stmt->execute(array(":title" => $_POST['title']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$insert_data = array(
':title' => $_POST['title'] ? $_POST['title'] : $row['title'],
':keywords' => $_POST['keywords'] ? $_POST['keywords'] : $row['keywords'],
...
);
$query = "UPDATE table SET keywords = :keywords, img = :img, widht = :widht, status = :status, name = :name, height = :height WHERE title = :title";
$statement = $conn->prepare($query);
$statement->execute($insert_data);
}
edited Nov 22 '18 at 21:40
answered Nov 21 '18 at 18:38
CharlesCharles
362
362
I got a errorFatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2031 in ... PDO->query('SELECT title, k...')
. People don't update records on this way? I felt that this was a easy question.
– 111111111111
Nov 21 '18 at 18:53
Make sure to double check my code; like I said, I haven't coded PHP in a long time (and so another response to you; I don't update records in this way. I usually use an ORM, or a framework with an ORM such as Django, Ruby on Rails, Phoenix, etc.).
– Charles
Nov 22 '18 at 19:20
I updated the answer; let me know if it works so I can sleep at night :).
– Charles
Nov 22 '18 at 19:26
Sadly not :/ i got this error:Notice: Trying to get property 'num_rows' of non-object
and Undefinet variable $row into the array. I'm almost giving up. I think i will use pure SQL on database to update my records. Thanks anyways.
– 111111111111
Nov 22 '18 at 20:53
Changed again; maybe you can try debugging the errors, since you have a system setup?
– Charles
Nov 22 '18 at 21:40
|
show 1 more comment
I got a errorFatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2031 in ... PDO->query('SELECT title, k...')
. People don't update records on this way? I felt that this was a easy question.
– 111111111111
Nov 21 '18 at 18:53
Make sure to double check my code; like I said, I haven't coded PHP in a long time (and so another response to you; I don't update records in this way. I usually use an ORM, or a framework with an ORM such as Django, Ruby on Rails, Phoenix, etc.).
– Charles
Nov 22 '18 at 19:20
I updated the answer; let me know if it works so I can sleep at night :).
– Charles
Nov 22 '18 at 19:26
Sadly not :/ i got this error:Notice: Trying to get property 'num_rows' of non-object
and Undefinet variable $row into the array. I'm almost giving up. I think i will use pure SQL on database to update my records. Thanks anyways.
– 111111111111
Nov 22 '18 at 20:53
Changed again; maybe you can try debugging the errors, since you have a system setup?
– Charles
Nov 22 '18 at 21:40
I got a error
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2031 in ... PDO->query('SELECT title, k...')
. People don't update records on this way? I felt that this was a easy question.– 111111111111
Nov 21 '18 at 18:53
I got a error
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2031 in ... PDO->query('SELECT title, k...')
. People don't update records on this way? I felt that this was a easy question.– 111111111111
Nov 21 '18 at 18:53
Make sure to double check my code; like I said, I haven't coded PHP in a long time (and so another response to you; I don't update records in this way. I usually use an ORM, or a framework with an ORM such as Django, Ruby on Rails, Phoenix, etc.).
– Charles
Nov 22 '18 at 19:20
Make sure to double check my code; like I said, I haven't coded PHP in a long time (and so another response to you; I don't update records in this way. I usually use an ORM, or a framework with an ORM such as Django, Ruby on Rails, Phoenix, etc.).
– Charles
Nov 22 '18 at 19:20
I updated the answer; let me know if it works so I can sleep at night :).
– Charles
Nov 22 '18 at 19:26
I updated the answer; let me know if it works so I can sleep at night :).
– Charles
Nov 22 '18 at 19:26
Sadly not :/ i got this error:
Notice: Trying to get property 'num_rows' of non-object
and Undefinet variable $row into the array. I'm almost giving up. I think i will use pure SQL on database to update my records. Thanks anyways.– 111111111111
Nov 22 '18 at 20:53
Sadly not :/ i got this error:
Notice: Trying to get property 'num_rows' of non-object
and Undefinet variable $row into the array. I'm almost giving up. I think i will use pure SQL on database to update my records. Thanks anyways.– 111111111111
Nov 22 '18 at 20:53
Changed again; maybe you can try debugging the errors, since you have a system setup?
– Charles
Nov 22 '18 at 21:40
Changed again; maybe you can try debugging the errors, since you have a system setup?
– Charles
Nov 22 '18 at 21:40
|
show 1 more comment
Assuming you don't want to set any of the columns to NULL
values, you can use COALESCE()
:
UPDATE table
SET keywords = COALESCE(:keywords, keywords),
img = COALESCE(:img, img),
widht = COALESCE(:widht, widht),
status = COALESCE(:status, status),
name = COALESCE(:name, name),
height = COALESCE(:height height)
WHERE title = :title;
The columns is not getting NULL values, i just want to update only one column, when i set the value only on a single input the others columns get replaced with none values. I tryed your code, but it's getting the same.
– 111111111111
Nov 21 '18 at 17:06
@515948453225 . . . "none" is not a database concept. What database are you using?COALESCE()
should work, assuming the missing values are passed in asNULL
.
– Gordon Linoff
Nov 22 '18 at 0:35
I'm using phpmyadmin.Withnone value
, i meant that the value on column remains blank, and not asNULL
, just a blank space without data.
– 111111111111
Nov 22 '18 at 2:02
add a comment |
Assuming you don't want to set any of the columns to NULL
values, you can use COALESCE()
:
UPDATE table
SET keywords = COALESCE(:keywords, keywords),
img = COALESCE(:img, img),
widht = COALESCE(:widht, widht),
status = COALESCE(:status, status),
name = COALESCE(:name, name),
height = COALESCE(:height height)
WHERE title = :title;
The columns is not getting NULL values, i just want to update only one column, when i set the value only on a single input the others columns get replaced with none values. I tryed your code, but it's getting the same.
– 111111111111
Nov 21 '18 at 17:06
@515948453225 . . . "none" is not a database concept. What database are you using?COALESCE()
should work, assuming the missing values are passed in asNULL
.
– Gordon Linoff
Nov 22 '18 at 0:35
I'm using phpmyadmin.Withnone value
, i meant that the value on column remains blank, and not asNULL
, just a blank space without data.
– 111111111111
Nov 22 '18 at 2:02
add a comment |
Assuming you don't want to set any of the columns to NULL
values, you can use COALESCE()
:
UPDATE table
SET keywords = COALESCE(:keywords, keywords),
img = COALESCE(:img, img),
widht = COALESCE(:widht, widht),
status = COALESCE(:status, status),
name = COALESCE(:name, name),
height = COALESCE(:height height)
WHERE title = :title;
Assuming you don't want to set any of the columns to NULL
values, you can use COALESCE()
:
UPDATE table
SET keywords = COALESCE(:keywords, keywords),
img = COALESCE(:img, img),
widht = COALESCE(:widht, widht),
status = COALESCE(:status, status),
name = COALESCE(:name, name),
height = COALESCE(:height height)
WHERE title = :title;
answered Nov 21 '18 at 16:50
Gordon LinoffGordon Linoff
773k35306408
773k35306408
The columns is not getting NULL values, i just want to update only one column, when i set the value only on a single input the others columns get replaced with none values. I tryed your code, but it's getting the same.
– 111111111111
Nov 21 '18 at 17:06
@515948453225 . . . "none" is not a database concept. What database are you using?COALESCE()
should work, assuming the missing values are passed in asNULL
.
– Gordon Linoff
Nov 22 '18 at 0:35
I'm using phpmyadmin.Withnone value
, i meant that the value on column remains blank, and not asNULL
, just a blank space without data.
– 111111111111
Nov 22 '18 at 2:02
add a comment |
The columns is not getting NULL values, i just want to update only one column, when i set the value only on a single input the others columns get replaced with none values. I tryed your code, but it's getting the same.
– 111111111111
Nov 21 '18 at 17:06
@515948453225 . . . "none" is not a database concept. What database are you using?COALESCE()
should work, assuming the missing values are passed in asNULL
.
– Gordon Linoff
Nov 22 '18 at 0:35
I'm using phpmyadmin.Withnone value
, i meant that the value on column remains blank, and not asNULL
, just a blank space without data.
– 111111111111
Nov 22 '18 at 2:02
The columns is not getting NULL values, i just want to update only one column, when i set the value only on a single input the others columns get replaced with none values. I tryed your code, but it's getting the same.
– 111111111111
Nov 21 '18 at 17:06
The columns is not getting NULL values, i just want to update only one column, when i set the value only on a single input the others columns get replaced with none values. I tryed your code, but it's getting the same.
– 111111111111
Nov 21 '18 at 17:06
@515948453225 . . . "none" is not a database concept. What database are you using?
COALESCE()
should work, assuming the missing values are passed in as NULL
.– Gordon Linoff
Nov 22 '18 at 0:35
@515948453225 . . . "none" is not a database concept. What database are you using?
COALESCE()
should work, assuming the missing values are passed in as NULL
.– Gordon Linoff
Nov 22 '18 at 0:35
I'm using phpmyadmin.With
none value
, i meant that the value on column remains blank, and not as NULL
, just a blank space without data.– 111111111111
Nov 22 '18 at 2:02
I'm using phpmyadmin.With
none value
, i meant that the value on column remains blank, and not as NULL
, just a blank space without data.– 111111111111
Nov 22 '18 at 2:02
add a comment |
see if this works
UPDATE table
SET keywords = :keywords,
img = CASE WHEN img IS NOT NULL THEN img ELSE :img END,
widht = CASE WHEN widht IS NOT NULL THEN widt ELSE :widht END,
status = CASE WHEN status IS NOT NULL THEN status ELSE :status END,
name = CASE WHEN name IS NOT NULL name ELSE :name END,
height = CASE WHEN height IS NOT NULL THEN height ELSE :height END
WHERE title = :title;
No, it's not even updating my record :/
– 111111111111
Nov 21 '18 at 17:53
add a comment |
see if this works
UPDATE table
SET keywords = :keywords,
img = CASE WHEN img IS NOT NULL THEN img ELSE :img END,
widht = CASE WHEN widht IS NOT NULL THEN widt ELSE :widht END,
status = CASE WHEN status IS NOT NULL THEN status ELSE :status END,
name = CASE WHEN name IS NOT NULL name ELSE :name END,
height = CASE WHEN height IS NOT NULL THEN height ELSE :height END
WHERE title = :title;
No, it's not even updating my record :/
– 111111111111
Nov 21 '18 at 17:53
add a comment |
see if this works
UPDATE table
SET keywords = :keywords,
img = CASE WHEN img IS NOT NULL THEN img ELSE :img END,
widht = CASE WHEN widht IS NOT NULL THEN widt ELSE :widht END,
status = CASE WHEN status IS NOT NULL THEN status ELSE :status END,
name = CASE WHEN name IS NOT NULL name ELSE :name END,
height = CASE WHEN height IS NOT NULL THEN height ELSE :height END
WHERE title = :title;
see if this works
UPDATE table
SET keywords = :keywords,
img = CASE WHEN img IS NOT NULL THEN img ELSE :img END,
widht = CASE WHEN widht IS NOT NULL THEN widt ELSE :widht END,
status = CASE WHEN status IS NOT NULL THEN status ELSE :status END,
name = CASE WHEN name IS NOT NULL name ELSE :name END,
height = CASE WHEN height IS NOT NULL THEN height ELSE :height END
WHERE title = :title;
answered Nov 21 '18 at 17:31
SreepuSreepu
66
66
No, it's not even updating my record :/
– 111111111111
Nov 21 '18 at 17:53
add a comment |
No, it's not even updating my record :/
– 111111111111
Nov 21 '18 at 17:53
No, it's not even updating my record :/
– 111111111111
Nov 21 '18 at 17:53
No, it's not even updating my record :/
– 111111111111
Nov 21 '18 at 17:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416891%2fhow-to-update-a-column-without-affecting-the-others%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown