Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Use case: Created a record Spot, Code, Language, Count ...later found out language entered was wrong. Tried to change the language using UPDATE query. Concatenated string still show same. Updated language string not changed in the concatenated string.

Created record using this MySql query

$sql = "INSERT INTO library (spot,code,language,count,litcode) values(?,?,?,?,CONCAT(language,'-',code))";

Tried to UPDATE language using this MySql query

Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
$sql = "UPDATE literatures set spot = ?, code = ?,language = ?, count =?, litcode = CONCAT(language,'-',code) WHERE id = ?";
$q = $pdo->prepare($sql); 
$q->execute(array($spot,$code,$language,$count,$litcode,$id)); 
Database::disconnect();

Finally language was updated but its not updating in the concatenated string.

Any errors in the UPDATE query?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
808 views
Welcome To Ask or Share your Answers For Others

1 Answer

You are trying to bind $litcode but you have CONCAT(language,'-',code). You have 5 ? in your query but you are trying to bind 6 params.

Change your code to this:

Database::connect(); 
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
$sql = "UPDATE literatures set spot = ?, code = ?, language = ?, count = ?, litcode = ? WHERE id = ?";
$q = $pdo->prepare($sql); 
$q->execute(array($spot,$code,$language,$count,$litcode,$id)); 
Database::disconnect();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...