Jump to content

wrong characters saved on my database


makotoshishio

Recommended Posts

Hi All.  I will begin letting you know that I'm a newbie on PHP.  I need help to identify the source of my problem.  I'm building a web site which includes a classifieds ads software I bought from Almond Classifieds.  The software is very good from my point of view but still needed some features that I wanted on my site plus some other ideas I had on my mind.  I decided to change the script to ad all those features and for the last 2 months I have been learning and adding features to it with no problems.  Now I got to a point where I'm stuck with no clue on what to do.

 

Every user needs an account to be able to post ads.  Some of these accounts will be allowed to post ads that last longer 30 days.  I created some functions which are called from another function and help get the appropiate ad term for each respective user.  My site is in spanish and the problem is that when I call those functions the spanish characters (accents) are saved with weird charactes on my DB, then when you see the ad its content is a mess.  If I don't call the functions everything is saved and displayed properly. The way it works is like this:

1) User login and select publish ad

2) User select category

3) User fills out the form then click submit

4) A function is called to identify the USERID

5) A function is called to identify the allowed ad term for that user

6) SUBMIT continues its operation and displays the "ad posted" page

7) When one sees the ad it displays wrong characters for accented letters including all other spanish characters

 

My collation for MySQL DB is utf8_unicode_ci; however, I don't think this is the problem because if I remove the function calls from the scrypt it works fine. Can anyone point me in the right direction to fix this?

 

This are the functions I created on funcisrealtor.php file:

 

////////Gets the ID of the Ad Owner/////////////////////////

function isrealtor2($adowner)

{

//

//variables to use to connect to db

//

$databasehost = "XXXX";

$databasename = "XXXX";

$databasetable = "XXXX";

$databaseusername ="XXXX";

$databasepassword = "XXXX";

//

//db connection string

//

$con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());

@mysql_select_db($databasename) or die(mysql_error());

//

//get user who posted the ad

//

$usris = $adowner;

//

//db query to get user ID

//

$sql_query_USERCHK = "select * from $databasetable where (username='$usris')";

$sql_res = mysql_query("$sql_query_USERCHK");

while ($row = mysql_fetch_array ($sql_res))

{$getid = $row['id'];}

//

//what to do after check

//

return $getid;

//

//close query

//

@mysql_query($query);

}

//

//close db connection

//

@mysql_close($con);

 

////////Gets plan term//////////////////////////////////

function planterm($userid)

{

//

//variables to use to connect to db

//

$databasehost = "XXXXX";

$databasename = "XXXXX";

$databasetable = "XXXXX";

$databaseusername ="XXXXX";

$databasepassword = "XXXXXX";

//

//db connection string

//

$con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());

@mysql_select_db($databasename) or die(mysql_error());

//

//get user who posted the ad

//

$usris = $userid;

//

//db query to get user ID

//

$sql_query_USERCHK = "select * from $databasetable where (id='$usris')";

$sql_res = mysql_query("$sql_query_USERCHK");

while ($row = mysql_fetch_array ($sql_res))

{$planexpvalue = $row['payplanexp'];

$planterm = $row['planterm'];}

//

//what to do after check

//

$expires=time() - $planterm*86400;

if ($planexpvalue < $expires) {

$isexpired = 1;

return $isitexpired;}

else {

$isexpired = 0;}

if ($isexpired = 1) {

$pterm = 30;}

else {

$pterm = $planterm;}

$pterm2 = time() + $pterm*86400;

return $pterm2;

//

//close query

//

@mysql_query($query);

}

//

//close db connection

//

@mysql_close($con);

 

 

THIS IS THE SUBMIT FUNCTION THAT IS USED AND FROM WHICH THE FUNCTIONS ABOVE ARE CALLED:

 

function form_sql_entry($idnum)

{

global $ct,  $table_ads, $visible_val, $cat_fields,

$HTTP_POST_VARS, $moderating, $adphotos, $cook_login;

 

$adowner = cook_login();

include_once('funcisrealtor.php');

$userid = isrealtor2($adowner);

$adperiod = usradterm($userid);

 

$db_entry['login']=$cook_login;

 

$time_now=time();

 

$db_entry['idnum']=$idnum;

$db_entry['exptime']=$time_now + ($adperiod-$expperiod)*86400;

$db_entry['time']=$time_now;

$db_entry['catname']=$ct;

$db_entry['visible']=$visible_val;

$db_entry['adphotos']= $adphotos;

 

 

foreach ($cat_fields as $key => $value)

{

 

$db_entry[$key]=$HTTP_POST_VARS[$key];

 

}

 

return $db_entry;

}

 

 

 

:shrug:

Link to comment
https://forums.phpfreaks.com/topic/187420-wrong-characters-saved-on-my-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.