10 Replies - 29494 Views - Last Post: 18 August 2011 - 07:35 PM Rate Topic: -----

#1 Ayumi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-March 10

[Question] how to put special characters in mysql?

Posted 17 August 2011 - 09:24 PM

i'm working on a project in which i need to connect it to mysql database.. my problem is.. i have to put special characters like theta (θ), radical signs (√), etc..

when i display it to the database, it shows this: θ
Is This A Good Question/Topic? 0
  • +

Replies To: [Question] how to put special characters in mysql?

#2 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,571
  • Joined: 08-June 10

Re: [Question] how to put special characters in mysql?

Posted 17 August 2011 - 09:59 PM

View PostAyumi, on 18 August 2011 - 06:24 AM, said:

when i display it to the database, it shows this: θ

so there is no problem?

generally, to pass special characters to the DB there are 2 ways, either set the DB to an appropriate encoding (mostly one of the UTF family) or encode the characters before sending to the DB.
Was This Post Helpful? 1
  • +
  • -

#3 Ayumi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-March 10

Re: [Question] how to put special characters in mysql?

Posted 17 August 2011 - 10:08 PM

View PostDormilich, on 17 August 2011 - 09:59 PM, said:

View PostAyumi, on 18 August 2011 - 06:24 AM, said:

when i display it to the database, it shows this: θ

so there is no problem?

generally, to pass special characters to the DB there are 2 ways, either set the DB to an appropriate encoding (mostly one of the UTF family) or encode the characters before sending to the DB.




ooops sorry.. i didn't know that it is converted to the symbol.. but this is what appears in the database

θ


i tried to set it to utf-8 but it's still not working..

This post has been edited by Dormilich: 17 August 2011 - 10:09 PM

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,571
  • Joined: 08-June 10

Re: [Question] how to put special characters in mysql?

Posted 17 August 2011 - 10:11 PM

Id say thats fine. every browser can read that.

this conversion to the entity is probably caused by one of your input validation functions (Id assume).
Was This Post Helpful? 0
  • +
  • -

#5 Ayumi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-March 10

Re: [Question] how to put special characters in mysql?

Posted 17 August 2011 - 10:19 PM

View PostDormilich, on 17 August 2011 - 10:11 PM, said:

I’d say that’s fine. every browser can read that.

this conversion to the entity is probably caused by one of your input validation functions (I’d assume).


err.. maybe i should post the code here..

 
<?php
$con = mysql_connect ('Localhost','****','****') or die (mysql_error());
mysql_query("SET NAMES utf8");  
mysql_select_db("DemiGod_db_Online",$con);

$sql = "CREATE TABLE Game1 (
Q_NO INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
Q_LEVEL VARCHAR( 20 ) NOT NULL ,
Q_ASK VARCHAR( 10000 ) NOT NULL ,
Q_ANS VARCHAR( 10000 ) NOT NULL ,
Q_W1 VARCHAR( 10000 ) NOT NULL ,
Q_W2 VARCHAR( 10000 ) NOT NULL
) ";

mysql_query($sql,$con);
echo "Game1 Table Created";

mysql_close($con);

?>



This post has been edited by Dormilich: 18 August 2011 - 04:38 AM
Reason for edit:: removed login credentials

Was This Post Helpful? 0
  • +
  • -

#6 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,571
  • Joined: 08-June 10

Re: [Question] how to put special characters in mysql?

Posted 18 August 2011 - 04:39 AM

that is the code to create the DB, not the code processing your data
Was This Post Helpful? 1
  • +
  • -

#7 Ayumi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-March 10

Re: [Question] how to put special characters in mysql?

Posted 18 August 2011 - 05:56 AM

View PostDormilich, on 18 August 2011 - 04:39 AM, said:

that is the code to create the DB, not the code processing your data …


oh yea right! what am i doing :oops: *facepalms*
sorry :nervous:

here's the real one.

<?php
	 
	$con = mysql_connect ('Localhost','****','****') or die (mysql_error());
	mysql_query("SET NAMES utf8"); 
	mySQL_Select_db ("DemiGod_db_Online",$con);
	 
	$quest = $_POST['quest'];
	$level = $_POST['level'];
	 
	if (isset($_POST['submit']))
	{
	 
	if ($quest == "math")
	{
	$sql = "INSERT INTO Game1(Q_LEVEL,Q_ASK,Q_ANS,Q_W1,Q_W2)
	VALUES
	(
	 
	'$level',
	 
	'$_POST[question]',
	'$_POST[correct_ans]',
	'$_POST[wrong1]',
	'$_POST[wrong2]'
	)";
	}
	}
	 
	echo "1 question added Created";
	mySQL_Query($sql,$con);
	mySQL_close($con);
	 
	?>



This post has been edited by Dormilich: 18 August 2011 - 07:41 AM
Reason for edit:: removed login credentials

Was This Post Helpful? 0
  • +
  • -

#8 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,571
  • Joined: 08-June 10

Re: [Question] how to put special characters in mysql?

Posted 18 August 2011 - 07:43 AM

I dont see anything that would do the conversion, maybe there is a php.ini setting
Was This Post Helpful? 0
  • +
  • -

#9 Ayumi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-March 10

Re: [Question] how to put special characters in mysql?

Posted 18 August 2011 - 08:58 AM

View PostDormilich, on 18 August 2011 - 07:43 AM, said:

I don‘t see anything that would do the conversion, maybe there is a php.ini setting …



i thought that having the UTF8 would convert the characters but i searched about this function
function check_input($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}



and also this one

function check_input($value)
{
// Stripslashes
if (get_magic_quotes_gpc())
  {
  $value = stripslashes($value);
  }
// Quote if not a number
if (!is_numeric($value))
  {
  $value = "'" . mysql_real_escape_string($value) . "'";
  }
return $value;
}


(though they're pretty much alike... )

i tried it but it's still not working..
the data i input is not 'insert'-ing in the table..


thank you for your time~

This post has been edited by Ayumi: 18 August 2011 - 09:00 AM

Was This Post Helpful? 0
  • +
  • -

#10 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,571
  • Joined: 08-June 10

Re: [Question] how to put special characters in mysql?

Posted 18 August 2011 - 11:13 AM

the only functions (I know) that do this type of conversion are filter functions, htmlentities() and of course custom functions (cf. user notes of utf8_encode())
Was This Post Helpful? 0
  • +
  • -

#11 Ayumi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-March 10

Re: [Question] how to put special characters in mysql?

Posted 18 August 2011 - 07:35 PM

View PostDormilich, on 18 August 2011 - 11:13 AM, said:

the only functions (I know) that do this type of conversion are filter functions, htmlentities() and of course custom functions (cf. user notes of utf8_encode())


thank you.. i will try those functions.. i hope i could get it now..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1