Jump to content

update not working


billgod

Recommended Posts

Anyone have any idea why this is not wokring?

 if ($_POST[partsyes] == 'yes'){
	$sql10="insert into tbl_partsordered (col_ticketid, col_price, col_orderedfrom, col_part, col_date) values ($_SESSION[ticketid], '$_POST[pprice]', '$_POST[pfrom]', '$_POST[part]', CURDATE( ))";
	$result10=mysql_query($sql10) or die ('Error: '.mysql_error ());
//get tech comments so we can add our parts ordered to them.
$sql11="SELECT col_techcomments FROM tbl_ticket where id = $_SESSION[ticketid]";
$result11=mysql_query($sql11) or die ('Error: '.mysql_error ());
	while($row11 = mysql_fetch_array($result11)) {
		$newtechcomments = $row11[col_techcomments] . " " . "Ordered Parts" . " " .$_POST[part] . " " .$_POST[pprice] . " " . "From:" .$_POST[pfrom] . " ". $today;
		$sql12="update tbl_ticket set col_techcomments='$newtechcomments' where id = $_POST[ticketid]";
		$result12=mysql_query($sql12) or die ('Error: '.mysql_error ());
	}

 }

 

The first query pull data out of the database.  then concatenates that string with other strings.

 

The update query never runs?  If I add echo $sql2; and copy the sql that is displayed on the screen and paste it into phpadmin it updates just fine.

 

I tried putting a typo in on the query just to see if it failed.  It does.  so I know its running the query

 

This is driving me nuts. I know it's gotta be a typo somewhere. 

 

Also don't make fun of my code.. I know It's gotta be bad.  :)

Link to comment
Share on other sites

How about var_dump($_SESSION[ticketid]) ?

 

Since you are apparently not getting the or die() message, the query is being executed without error and something is causing the WHERE clause to be false.

 

Also, after looking more closely to what your code is doing, you don't need to SELECT the data in order to UPDATE it, just use one query to UPDATE it -

 

$newtechcomments = " Ordered Parts {$_POST['part']} {$_POST['pprice']} From:{$_POST[pfrom]} $today";
$sql11="UPDATE tbl_ticket SET col_techcomments= CONCAT(col_techcomments, '$newtechcomments') where id = $_SESSION[ticketid]";

Link to comment
Share on other sites

If I just do an update.  Won't it erase what is already in there?  I need to append this to the data in the same column. 

 

var_dump  shows string(3) "830"

 

I tried using session and post thinking that was the problem so my code may have both versions floating around in it.

Link to comment
Share on other sites

Won't it erase what is already in there?

 

Not if you concatenate what is already there with the additional information. See the mysql CONCAT() function I used in that single UPDATE query.

 

Based on the code you have posted and the var_dump's your update query should be working. What exactly makes you think it is not?

 

 

Link to comment
Share on other sites

concat does not seem to do what I need.  Lets say for instance I have this in my database

 

fish

 

I need to add the word tank (that is not in the database) to fish to get

 

Fish tank

 

So the only way I know to do it is query for fish.  use php to concat my second string and update the database.

 

You ask how I know its not working?  When I look at the table the data stays the same.

 

Check this out..  If I copy and paste the entire update query into another php page.  It works??  WTF?

Link to comment
Share on other sites

That is a copy and paste of the code.  like I said before If I change the query with a typo on like table name.  mysql spits out an error of no table found.  Just like this has no errors at all.

 

I just tried changing my query to

$sql12="update tbl_ticket set col_techcomments='blahblah' where id = 830";

 

and it did not update my table to blahblah??

 

Link to comment
Share on other sites

What's the column definition for col_techcomments and what data do you already have in it (nothing printed at the point where the existing contents should have been when you posted the query that was being used to update it.)

 

Edit: Also, what method or code are you using to display the data that leads you to believe it is not changing?

Link to comment
Share on other sites

This is for a ticket system I wrote for my small computer repair shop.

 

The  col_techcomments type is set to LONGTEXT in MYSQL.

 

for example.  The first comment may say something like "tested hard drive.  Drive failed"

 

I can use my form on the web to pull the data out of the database and display it on my screen. I can then modify it and hit save.  Then look at that ticket again and all my changes are there.

 

I am trying to add a new feature that when I order a part, adds the part, price and where I purchased it to a new table.  This part works also.  I then want it to take the part, price and where I purchased it and append it to the current col_techcomments.  This is the part that does not work.

 

It should now say "tested hard drive.  Drive failed  Parts ordered - Hard drive, 63.17 from Newegg.com"

 

If I echo my sql query to the screen.  Then copy and paste it into phpadmin.  the query runs and updates the table with no errors but will not do it by itself.  It's almost like its skipping the query but I know its not since I purposefully added typos just to see it fail and it does.

 

I know its not adding it because I am looking at the table in phpadmin and it shows exactly what it did before I run the script.

Link to comment
Share on other sites

What's the whole current code for the page?

 

Given that the posted code is using $sql10, 11, and 12, you likely have a bunch of other queries on the page and at least one of them could be putting back in original text (from the form field or from the $row11[col_techcomments] variable) and overwriting the UPDATEed text.

 

You could also put a die; statement in after the UPDATE query has been executed to see if the code is doing what it should.

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.