johnwayne77 Posted April 29, 2009 Share Posted April 29, 2009 what is wrong with this code? $query = "SELECT * from cp_products2"; $doq = mysql_query($query); while ($row = mysql_fetch_assoc($doq)) { $catid = $row['cat_id']; $newcatid = $catid . "mns"; $query2 = "UPDATE cp_products2 SET cat_id = '$newcatid' WHERE cat_id = '$catid'"; $doq2 = mysql_query($query2); echo "categorie veche: " . $catid . " | Categorie noua: " . $newcatid . "<br>"; } it echoes correctly but it doesn't update the fields.. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/156112-solved-what-is-wrong-with-this-piece-of-code-phpmysql-simple-echo-update/ Share on other sites More sharing options...
revraz Posted April 29, 2009 Share Posted April 29, 2009 Use mysql_error after the queries to see if there are any errors. Quote Link to comment https://forums.phpfreaks.com/topic/156112-solved-what-is-wrong-with-this-piece-of-code-phpmysql-simple-echo-update/#findComment-821761 Share on other sites More sharing options...
GuitarGod Posted April 29, 2009 Share Posted April 29, 2009 Try this <?php $query = "SELECT * from cp_products2"; $doq = mysql_query($query); $start = 0; while ($row = mysql_fetch_assoc($doq)) { $catid = $row['cat_id']; $newcatid = $catid . "mns"; $query2[$start] = "UPDATE cp_products2 SET cat_id = '$newcatid' WHERE cat_id = '$catid'"; mysql_query($query2[$start]); echo "categorie veche: " . $catid . " | Categorie noua: " . $newcatid . "<br>"; $start++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/156112-solved-what-is-wrong-with-this-piece-of-code-phpmysql-simple-echo-update/#findComment-821763 Share on other sites More sharing options...
johnwayne77 Posted April 29, 2009 Author Share Posted April 29, 2009 heh, the field was INT , that's why i couldn't append any text.. thanks, the code worked also! cheers Quote Link to comment https://forums.phpfreaks.com/topic/156112-solved-what-is-wrong-with-this-piece-of-code-phpmysql-simple-echo-update/#findComment-821769 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.