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
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.

Link to comment
Share on other sites

You need to add curly braces around an array when accessed within a string:

 

"UPDATE tbl_ticket set col_techcomments='$newtechcomments' where id = {$_POST['ticketid']}"

 

It's also better to add quotes around an associative key.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.