sx Posted March 20, 2007 Share Posted March 20, 2007 Hi I have a mysql database with an entry in it. I want to take a certain part of that entry and change it and put it back into the database. I can get it to take the entry and replace the part no problem and echo the correct info to the screen. The problem is that it will not update the database. This is the entry as it appears in the database. <span style="color:blue"><!--/coloro-->Link(s) Checked<br />2 Mar 07<br />crackerhead<!--colorc--></span><!--/colorc--> Basically I am wanting to change it to Link(s) Checked<br />**todays Date**<br />***Name*** here is the code I am trying to use. I have a form that submits the pid number to this script. using method POST. <? include 'config.php'; include 'auth.php'; $pid = $_POST["pid"]; $today = date('d M Y'); $query = "SELECT * FROM ibf_posts WHERE (pid = '$pid')"; $result = mysql_query($query) or ("" . mysql_error()); while($row = mysql_fetch_array($result)) {extract($row);} $post = eregi_replace("\\Link([^\\[]*)\\<!--colorc-->","Link(s) Checked<br />$today<br />$admitname<!--colorc-->",$post); echo "$pid"; echo "$post"; $query="UPDATE ibf_posts SET post = '$post' WHERE (pid = '$pid')"; mysql_query($query); echo "Record Updated"; mysql_close(); ?> If I change this line $query="UPDATE ibf_posts SET post = '$post' WHERE (pid = '$pid')"; to this $query="UPDATE ibf_posts SET post = 'hi' WHERE (pid = '$pid')"; It will change the entire entry to "hi" and it will update the database. Can someone help me understand this?? Link to comment https://forums.phpfreaks.com/topic/43444-need-help-updating-a-database/ Share on other sites More sharing options...
redarrow Posted March 20, 2007 Share Posted March 20, 2007 <?php include 'config.php'; include 'auth.php'; $pid = $_POST["pid"]; $today = date('d M Y'); $query1 = "SELECT * FROM `ibf_posts` WHERE `pid` = '$pid' "; $result1 = mysql_query($query1) or ("" . mysql_error()); while($row1 = mysql_fetch_assoc($result1)){ $post=$row1['post']; $post= eregi_replace("\\Link([^\\[]*)\\<!--colorc-->","Link(s) Checked<br />$today<br />$admitname<!--colorc-->",$post); $query2="UPDATE `ibf_posts` SET `post` = '$post' WHERE `pid` = '$pid' "; mysql_query($query2) or die (mysql_error()); echo "Record Updated"; } ?> Link to comment https://forums.phpfreaks.com/topic/43444-need-help-updating-a-database/#findComment-210978 Share on other sites More sharing options...
jitesh Posted March 20, 2007 Share Posted March 20, 2007 $query="UPDATE ibf_posts SET post = '".addslashes($post)."' WHERE (pid = '$pid')"; Link to comment https://forums.phpfreaks.com/topic/43444-need-help-updating-a-database/#findComment-211123 Share on other sites More sharing options...
sx Posted March 20, 2007 Author Share Posted March 20, 2007 OMG. Thank you guys. You rock. It works now. Link to comment https://forums.phpfreaks.com/topic/43444-need-help-updating-a-database/#findComment-211132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.