djp1988 Posted September 11, 2008 Share Posted September 11, 2008 I am using a javascript to update content on the fly and also to send post data of a submitted textfield to a php page where I then update a database, BUT my problem is, the javascript string when it is collected by the php is not collecting it properly, instead of "Chizé" I am retreiving and saving to the database: "chizé" as I update the page's content without the ajax, the user initially sees the correct string, but if they refresh or leave and come back they get the second result.Why? and how can I make it so that the php collects the javascript post data correctly?This is my javascript, I have alert() the data to check if the info was correct and this part of the script is fine: function updatesite(data, whatdata, userid){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ alert ("Your browser does not support AJAX!"); return; } var url="updateSiteinfo.php"; xmlHttp.open("POST",url,true); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); myData = whatdata+"="+ data; myData += "&memberID="+ userid; xmlHttp.send(myData);} And the updateSiteinfo.php file looks like this: if($_POST['nexttrip']){ require_once ('db_connect.php'); $nexttrip = $_POST['nexttrip']; $member = $_POST['memberID']; $q = "SELECT * FROM Profils WHERE userid = $member"; $res = mysql_query ($q, $dbc); $exists=@mysql_num_rows($res); if($exists == 1){ $q = "UPDATE Profils SET next_trip='$nexttrip' WHERE userid = $member"; $r = @mysql_query ($q); }elseif($exists == 0){ $q = "INSERT INTO Profils(userid,image,site,next_trip) VALUES($member, '', '', '$nexttrip')"; $r = @mysql_query ($q); }} So it should be in the php at this point: $nexttrip = $_POST['nexttrip'];Where it all goes wrong,Please help, DJP Link to comment Share on other sites More sharing options...
justsomeguy Posted September 11, 2008 Share Posted September 11, 2008 Use Firebug to look at the data that goes out on the XHR request to see if the data is being sent in the wrong format or if it's being converted by PHP. Link to comment Share on other sites More sharing options...
djp1988 Posted September 12, 2008 Author Share Posted September 12, 2008 the firebug is telling me I am sending the wrong text:nexttrip: é(when I send 'é')It seems I need to set my page to utf-8right now I am in:charset=ISO-8859-1Will there be any problems if I change it?Okay just tried, Here is what I want to do: I need to get it so the database entry is correctly accented with 'é' right now with utf-8 the accents appear but the database is still being given values such as é, how can I get around this, I have tried sending the é through but on the php page that handles the variables and queries the data base I put utf-8 but this doesn't work... Link to comment Share on other sites More sharing options...
justsomeguy Posted September 12, 2008 Share Posted September 12, 2008 Dan Grossman knows.http://www.dangrossman.info/2007/05/25/han...utf8-databases/ Link to comment Share on other sites More sharing options...
djp1988 Posted September 12, 2008 Author Share Posted September 12, 2008 hmmm this seems to be a very big problem with only complex solutions, is there no way I can loop through a strnig and replace the accents by their html equivilant before sending the data through AJAX? OR somehow decode the string in the page that handles the text? Link to comment Share on other sites More sharing options...
djp1988 Posted September 12, 2008 Author Share Posted September 12, 2008 Victory is mine, all I needed to do is decode the string in php before saving to data base: $nexttrip = utf8_decode($nexttrip); if($_POST['nexttrip']){ require_once ('db_connect.php'); $nexttrip = $_POST['nexttrip']; $member = $_POST['memberID']; $nexttrip = utf8_decode($nexttrip); $q = "SELECT * FROM Profils WHERE userid = $member"; $res = mysql_query ($q, $dbc); $exists=@mysql_num_rows($res); if($exists == 1){ $q = "UPDATE Profils SET next_trip='$nexttrip' WHERE userid = $member"; $r = @mysql_query ($q); }elseif($exists == 0){ $q = "INSERT INTO Profils(userid,image,site,next_trip) VALUES($member, '', '', '$nexttrip')"; $r = @mysql_query ($q); }} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.