Jump to content

Odd PHP MySQL issue


Fudlite

Recommended Posts

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

 

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.

Link to comment
Share on other sites

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!

 

 

Link to comment
Share on other sites

@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!

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.