billgod Posted July 28, 2010 Share Posted July 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2010 Share Posted July 28, 2010 $_POST['ticketid'] probably contains a non-printing character. What sets $_POST['ticketid'] in the form and what does using var_dump($_POST['ticketid']) show? Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092356 Share on other sites More sharing options...
billgod Posted July 28, 2010 Author Share Posted July 28, 2010 var_dump show string(3) "830" which 830 would be the correct ticketid in this case. The sql query that gets echoed is update tbl_ticket set col_techcomments='Ordered Parts test 123.12 From:test ' where id = 830 Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092361 Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2010 Share Posted July 28, 2010 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]"; Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092365 Share on other sites More sharing options...
billgod Posted July 28, 2010 Author Share Posted July 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092368 Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2010 Share Posted July 28, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092388 Share on other sites More sharing options...
billgod Posted July 29, 2010 Author Share Posted July 29, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092615 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2010 Share Posted July 29, 2010 There's something going on that you are not showing or telling us. Either that's not the actual code that exhibits the problem or your full code is doing something unusual or your data isn't what you are showing or implying. Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092620 Share on other sites More sharing options...
billgod Posted July 29, 2010 Author Share Posted July 29, 2010 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?? Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092752 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2010 Share Posted July 29, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092805 Share on other sites More sharing options...
billgod Posted July 29, 2010 Author Share Posted July 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092824 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2010 Share Posted July 29, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209161-update-not-working/#findComment-1092834 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.