Reputation: 2880
So I am updating my mysql database using php. Below is the end of the UPDATE, and if I have a string instead of echo $row[embedcode]");
it works fine, and this echo sets data on the page just fine retrieving the right value, but within this UPDATE it doesn't work.
...WHERE `embedcode` = echo $row[embedcode]");
I have tried using ". ." around it and adding its own php tag around it but I'm not sure what needs to be done.
Upvotes: 1
Views: 276
Reputation: 554
to prevent SQL injection, you can pass that value as a parameter if you are using PDO or MySQLi.
For example,
$stmt = $dbConnection->prepare('...WHERE `embedcode` = :embedcode');
$stmt->execute(array(':embedcode' => $row[embedcode]));
See this for details.
Upvotes: 0
Reputation: 2758
Let say for example...
("UPDATE `tblProfile` SET `profilename` = 'abc' WHERE `embedcode` = '".$row['embedcode']."'");
Upvotes: 0
Reputation: 5624
You don't use echo, perhaps it should be:
...WHERE `embedcode=` . $row[embedcode]");
Not that if $row[embedcode]
is a string you have to put quotes around it.
Upvotes: 0
Reputation: 5057
WHERE
embedcode= . $row[embedcode]);
will set the value.
There is not need for echo inside the sql statement. echo is used for displaying something from php to the webbrowser.
Upvotes: 0
Reputation: 10994
Just use this:
...WHERE `embedcode` = " . $row[embedcode]);
There is no need for echo
.
As a side note, you should probably parameterize or at least sanitize any strings that go into a MySQL query to prevent SQL injection and other bad things.
Upvotes: 6