acctman Posted March 25, 2009 Share Posted March 25, 2009 $dbc = mysql_connect ($db_server, $db_user, $db_pass); mysql_select_db ($db_name) or die(mysql_error()); $rs = mysql_query("SELECT b_id, b_text FROM rate_blogs"); if($rs) { while($row = mysql_fetch_assoc($rs)) { $decode = unserialize(base64_decode($row['b_text'])); $b_text = $decode[]; mysql_query ("UPDATE rate_blogs SET b_untext = '$b_text', WHERE b_id = '".$row['b_id']."'"); } } echo "Done"; Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/ Share on other sites More sharing options...
Maq Posted March 25, 2009 Share Posted March 25, 2009 Why not? Is there something wrong or you're concerned about? Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793819 Share on other sites More sharing options...
acctman Posted March 25, 2009 Author Share Posted March 25, 2009 Why not? Is there something wrong or you're concerned about? i just did a test run and the only error i got was the [] on the $decode... but it did not unserialize and move anything over. also no other errors Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793851 Share on other sites More sharing options...
revraz Posted March 25, 2009 Share Posted March 25, 2009 Echo your variables to verify where it's failing. Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793870 Share on other sites More sharing options...
acctman Posted March 25, 2009 Author Share Posted March 25, 2009 Echo your variables to verify where it's failing. i just tried that actually I tried that and its echo'ing that data. do you think it's because i'm doing an Update and should be doing INSERT since that new fields are all blank? if so would this INSERT command work mysql_query ("INSERT INTO rate_blogs VALUES b_untext = '$b_text' WHERE b_id = '".$row['b_id']."'"); Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793880 Share on other sites More sharing options...
Maq Posted March 25, 2009 Share Posted March 25, 2009 Echo your variables to verify where it's failing. i just tried that actually I tried that and its echo'ing that data. do you think it's because i'm doing an Update and should be doing INSERT since that new fields are all blank? if so would this INSERT command work mysql_query ("INSERT INTO rate_blogs VALUES b_untext = '$b_text' WHERE b_id = '".$row['b_id']."'"); No. Add or die(mysql_error()); to the end of your queries and see if there are any errors; Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793890 Share on other sites More sharing options...
acctman Posted March 25, 2009 Author Share Posted March 25, 2009 Echo your variables to verify where it's failing. i just tried that actually I tried that and its echo'ing that data. do you think it's because i'm doing an Update and should be doing INSERT since that new fields are all blank? if so would this INSERT command work mysql_query ("INSERT INTO rate_blogs VALUES b_untext = '$b_text' WHERE b_id = '".$row['b_id']."'"); No. Add or die(mysql_error()); to the end of your queries and see if there are any errors; Parse error: syntax error, unexpected T_STRING in /rate_blog.php on line 19 which is the first line of this statement mysql_query ("UPDATE rate_blogs SET b_untext = '$b_text', WHERE b_id = '".$row['b_id']."'"); Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793896 Share on other sites More sharing options...
Maq Posted March 25, 2009 Share Posted March 25, 2009 You have a comma right before the WHERE clause, remove it. EDIT: The comma doesn't exists 2 posts ago but your most recent it does, which one is it? If there really is no comman, then use this: mysql_query("UPDATE rate_blogs SET b_untext = '$b_text' WHERE b_id = '{$row['b_id']}') or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793899 Share on other sites More sharing options...
acctman Posted March 25, 2009 Author Share Posted March 25, 2009 You have a comma right before the WHERE clause, remove it. EDIT: The comma doesn't exists 2 posts ago but your most recent it does, which one is it? If there really is no comman, then use this: mysql_query("UPDATE rate_blogs SET b_untext = '$b_text' WHERE b_id = '{$row['b_id']}') or die(mysql_error()); same error Parse error: syntax error, unexpected T_STRING in /rate_blog.php on line 26 the comma i had in the 2nd post was because the sql statement was on 3 lines. i just tried it on one line and got the same error Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793904 Share on other sites More sharing options...
acctman Posted March 25, 2009 Author Share Posted March 25, 2009 i tried this code in my php IDE and it came back clean, but when I run it I'm giving the same error. mysql_query("UPDATE rate_blogs SET b_untext = $b_text WHERE b_id = $row[b_id]") or die(mysql_error()); some users have html coding inside the b_text could that be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793910 Share on other sites More sharing options...
acctman Posted March 25, 2009 Author Share Posted March 25, 2009 this is working but with an error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE b_id = 4' at line 1 $dbc = mysql_connect ($db_server, $db_user, $db_pass); mysql_select_db ($db_name) or die(mysql_error()); $rs = mysql_query("SELECT b_id, b_text FROM rate_blogs") or die(mysql_error()); if($rs) { while($row = mysql_fetch_assoc($rs)) { //$b_text = $row['b_text']; // echo $row['b_text']; $decode = unserialize(base64_decode($row['b_text'])); // echo $decode; $b_text = $decode; // mysql_query ("UPDATE rate_blogs SET // b_untext = '$b_text', // WHERE b_id = '".$row['b_id']."'"); mysql_query("UPDATE rate_blogs SET b_untext = $b_text WHERE b_id = $row[b_id]") or die(mysql_error()); } } echo "Done"; Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793936 Share on other sites More sharing options...
Maq Posted March 25, 2009 Share Posted March 25, 2009 Do addslashes() and mysql_real_escape_string() on $b_text before you do the UPDATE query. Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793947 Share on other sites More sharing options...
acctman Posted March 25, 2009 Author Share Posted March 25, 2009 same error. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE b_id = 4' at line 1 $dbc = mysql_connect ($db_server, $db_user, $db_pass); mysql_select_db ($db_name) or die(mysql_error()); $rs = mysql_query("SELECT b_id, b_text FROM rate_blogs") or die(mysql_error()); if($rs) { while($row = mysql_fetch_assoc($rs)) { //$b_text = $row['b_text']; // echo $row['b_text']; $decode = unserialize(base64_decode($row['b_text'])); // echo $decode; $b_atext = mysql_real_escape_string($decode); $b_text = addslashes($b_atext); // mysql_query ("UPDATE rate_blogs SET // b_untext = '$b_text', // WHERE b_id = '".$row['b_id']."'"); mysql_query("UPDATE rate_blogs SET b_untext = $b_text WHERE b_id = $row[b_id]") or die(mysql_error()); } } echo "Done"; Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-793965 Share on other sites More sharing options...
revraz Posted March 26, 2009 Share Posted March 26, 2009 You need single quotes around $b_text mysql_query("UPDATE rate_blogs SET b_untext = '$b_text' WHERE b_id = $row[b_id]") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/151109-does-this-look-correct/#findComment-794431 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.