Fudlite Posted August 16, 2011 Share Posted August 16, 2011 Hi Guys, how's it going. New here and I hope I'll be able to help others in the future here as well. The issue I'm facing is rather odd, and to be honest I've run out of ideas on how to fix it. The long and the short of it is I have a field named 'description' inside my database, of type TEXT. Whenever I try using input from my html form and I try to insert it into the description field, it goes into the database as a 0. When I run SQL commands through phpMyAdmin, I have no issues. The string updates and everybody is happy. The TEXT field is utf8, so I've tried changing the encoding, the database type, and a bunch of other stuff and after hours of googling and simply trying to fix the problem, I'm out of options. My function, where I'm changing the description is: (This is an isolated function to get to the problem. I'm not individually updating fields lol) public function SetDescription($newDesc){ $id = $this->id; $mysql = null; GetMySQLHandle($mysql); $escapedDesc = mysql_real_escape_string($newDesc); $result = mysql_query("UPDATE Item SET `description` = '$escapedDesc' WHERE id=$id",$mysql); if(!$result){ return false; } return true; } This function, or any other PHP function where I try to set the value (even if the value is static/hardcoded), it still comes out as a 0, however with phpMyAdmin it comes out perfect. If anyone has any ideas or suggestions please let me know. Thanks guys/gals! EDIT: I've tried testing my output after I escape the string as well, and as stated, even if the value is hard coded, it doesn't matter. This is why I'm really confused as to what the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/244902-odd-php-mysql-issue/ Share on other sites More sharing options...
harristweed Posted August 16, 2011 Share Posted August 16, 2011 hmmmm...I would suggest trying to insert a description outside of any functions. Just a simple.. <?php $update = "UPDATE Item SET description ='abcxyz' WHEREid = '$id' "; mysql_query($update, $link_id); ?> If that works it's your function, if not there is something else wrong! Quote Link to comment https://forums.phpfreaks.com/topic/244902-odd-php-mysql-issue/#findComment-1258032 Share on other sites More sharing options...
creata.physics Posted August 16, 2011 Share Posted August 16, 2011 Make sure $mysql is a resource or object, however you're using it; I would try var_dump($mysql); after GetMySQLHandle($mysql); if $mysql is null then that's where your issue is. Quote Link to comment https://forums.phpfreaks.com/topic/244902-odd-php-mysql-issue/#findComment-1258035 Share on other sites More sharing options...
Fudlite Posted August 16, 2011 Author Share Posted August 16, 2011 @creata.physis var dump in that function shows: "resource(2) of type (mysql link)", so that looks good to me. Good suggestion though! @harristweed Also good suggestion! Your suggestion worked. I wrote a completely static function and tested it and it worked superbly. I did make a mistake and wrote WHERE = 1 (forgot the WHERE id = 1) in the static script, which overall had the exact same outcome that my script is having, so I think it may be something to do with the ID in the query. Not quite sure though. Anywho, it's 3:30AM right now so I'll test it tomorrow and get back with the results. If anyone can see something these other two fine programmers haven't suggested, feel free to join in the convo! Thanks again guys! Quote Link to comment https://forums.phpfreaks.com/topic/244902-odd-php-mysql-issue/#findComment-1258056 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.