BASIC PHP MYSQL Question

Hello… All im trying to do is get the Old Data from my database and update it with the new post added to it… what am i doing wrong ?

Thanks a lot

//add function
function add()
{
	if(isset($_POST['add']))
	{
		
		$username = $_SESSION['username'];
		$id       = $_SESSION['id'];
			$select = "SELECT msg FROM $table WHERE id='$id'";
			$qq = mysql_query($select) or die("<Br>" . "Error". mysql_error());		
			$fetch = mysql_fetch_array($qq);
			$old = $fetch[0];
            $new = mysql_real_escape_string(stripslashes(strip_tags($_POST['msg'])));
			$msg = $old."<br>".$new;
            $insert_query_line = "UPDATE login SET msg='$msg' WHERE id='$id'";
            $insert_query = mysql_query($insert_query_line) or die (" Error Adding Values: " . mysql_error() . "<br>");
            echo '<p align="center"><font  color="red">Successfully Added !</p></font>';
			echo '<meta http-equiv="refresh" content="0">';
	}
}

where is the variable $table set?

also, you do not have to retrieve a value in order to update it – that’s 2 SQL statements instead of 1, which is 100% more inefficient than it has to be

I want the post ADDED to the old one… how else would you do that?

and the $table is included in config.php no worries about that.

with CONCAT

see this other thread from a few days ago …

R937 has a valid point, $table may have been set in another file but it’s not within the scope of your add function.

Log/display the actual SQL statement you’re trying to execute and double check it is what you expect.


UPDATE table SET foo = CONCAT(foo, ?) WHERE id = ?

mmm if i just replaced the $table with login ?

i dont understand whats wrong with the code i wrote… when i open it i find no errors yet it doesnt execute right…