Jump to content

Need help updating a database.


sx

Recommended Posts

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


<?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";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.