Jump to content

Can anyone tell me why this wont update?


billgod

Recommended Posts

if (isset ($_POST[callcust])){
	// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
               //get todays date and set format
$today = date(DATE_RFC822);
              //grab old comments from db
$sql=" SELECT col_techcomments FROM tbl_ticket where id = $_SESSION[ticketid]";
$result=mysql_query($sql) or die ('Error: '.mysql_error ());
	while($row = mysql_fetch_array($result)) {
                                // combine old comments with time stamp
		$newtechcomments = $row[col_techcomments] . " " .$_POST[callcust] . " " . $today;
                                //update DB
		mysql_query("UPDATE tbl_ticket set col_techcomments='$newtechcomments' where id = $_POST[ticketid]") or die ('Error: '.mysql_error ());
		}
}

 

If i echo my update to the screen.  The update sql looks correct.  If I copy and paste it into mysql it runs and works fine.  It's like php is just skipping th update.

 

PS I am in no way shape or form a software developer.  If my code looks like crap thats why.

Link to comment
https://forums.phpfreaks.com/topic/200295-can-anyone-tell-me-why-this-wont-update/
Share on other sites

A good practice is to store the SQL string into a variable before running it.

 

$sql = "UPDATE tbl_ticket set col_techcomments='$newtechcomments' where id = $_POST['ticketid']";.

 

That way, you can echo out $sql and verify that it's correct before you run it using mysql_query.

that just made it blow up.. ok figured out a little more.  It's updating the wrong table row?  if I echo my

$_POST[ticketid]

  it is correct.  If I echo the SQL statement it is correct.  But if I let it run. It seems to updating rows starting with id 1 then 2 then 3 and so on? 

 

here is the SQL statement that gets generated

 

UPDATE tbl_ticket set col_techcomments=' Left VM Fri, 30 Apr 10 14:22:06 -0400' where tbl_ticket.id = 670

 

If I paste this into mysql it works perfect?

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.