davil Posted November 2, 2009 Share Posted November 2, 2009 Here's my Code <h1>Edit Side-Orders</h1> <br/><br/> <h2>Input Side Orders here for <strong>[ <?php print_r($_POST); //FOR DEBUGGING $menuid = MySanitiseFunction($_REQUEST['menuid']); $newprice = MySanitiseFunction($_POST['newprice']); // just standard htmlentities instead of my sanitise function because I'm debugging $newsideorders = htmlentities($_POST['newsideorders']); if (!isset($_POST['frubmit'])){// IF SUBMIT BUTTON HASN'T BEEN CLICKED THEN ECHO OUT A PAGE /*---- First we retrieve the menu name and just echo it out --- */ //get menu name and description from SQL $sql1 = "SELECT `name` from `menus` WHERE id='$menuid' LIMIT 1"; $res1 = mysql_query($sql1) or die(mysql_error()); $row1 = mysql_fetch_array($res1); echo $row1['name'].' ]</h2>'; /*------------------------------------------------ */ // Retrieve side-orders from specific menu $sql = "SELECT `price`,`sideorders` from `sideorders` WHERE menu='$menuid'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($res); foreach ($row as $key => $value) {$$key = $value;} ?> <form enctype='multipart/form-data' method='post' action='index.php'> <input type='hidden' name='locate' value='editsideorders'> <input type='hidden' name='menuid' value='<?php echo $menuid ?>'> <br/><h3>PRICE: €<input type='text' name='newprice' value='<?php echo $price ?>'/> <input type='submit' name='frubmit' value='Submit All Changes on Page' /></h3> <br/><br/> <h3>SIDE-ORDERS LIST</h3> <?php echo "<textarea rows='20' cols='80' name='newsideorders'>$sideorders</textarea>"; ?> <br/><br/> </form> <?php } else {// Submit Changes button has been pressed, input data onto database $sql = "UPDATE `sideorders` SET `sideorders` = '$newsideorders',`price` = '$newprice' WHERE `menu` = '$menuid' LIMIT 1;"; echo "<br/><br/>SQL = [$sql]"; mysql_query($sql) or die (mysql_error()); //My_redirect_Function("index.php?locate=viewmenu&id=$menuid"); - Don't redirect for the moment (debugging) } ?> here's the output I'm getting Array ( [locate] => editsideorders [menuid] => 1 [newprice] => 3.50 [frubmit] => Submit All Changes on Page [newsideorders] => dégas ) SQL = [uPDATE `sideorders` SET `sideorders` = 'dégas',`price` = '3.50' WHERE `menu` = '1' LIMIT 1;]</div> so basically I'm wondering why é is becoming é whereas if I simplify this code down to <?php $text=htmlentities($_POST['text1']); if (!isset($_POST['frubmit'])){ echo <<<HEREZ <form enctype='multipart/form-data' method='post' action='test7.php'> Input entity Text: <textarea rows='20' cols='40' name="text1"></textarea> <input type="submit" name="frubmit" /> </form> HEREZ; } else{ $sql = "UPDATE `whatever` SET `whatever` = '$text'"; echo "<br/><br/>SQL = [$sql]"; } ?> It works fine...... So What am I doing wrong in the top bit of code??? P.S. the reason it posts to index.php is because I use that as my main PHP and then include PHP files based on $locate variable (see hidden input in the form) P.P.S. it works fine on my local WAMP setup (I use the Uniform Server on Windows) but not on my uploaded version (CPANEL / LINUX) - phpinfo() gives similar results on both for default charset etc. so I'm completely stumped Link to comment https://forums.phpfreaks.com/topic/179959-htmlentities-not-giving-expected-output/ Share on other sites More sharing options...
seanlim Posted November 2, 2009 Share Posted November 2, 2009 What do you mean "It works fine"? Does the é not become é? To further help with debugging, I would suggest changing the line $newsideorders = htmlentities(.... to var_dump($_POST['newsideorders']); $newsideorders = htmlentities($_POST['newsideorders']); var_dump($newsideorders); Link to comment https://forums.phpfreaks.com/topic/179959-htmlentities-not-giving-expected-output/#findComment-949350 Share on other sites More sharing options...
davil Posted November 2, 2009 Author Share Posted November 2, 2009 Sorry I wasn't very clear. In the second bit of code, é becomes &éacute; - which is perfect. but for some reason in the larger code that's not happening. I will try var_dump now. Thanks Link to comment https://forums.phpfreaks.com/topic/179959-htmlentities-not-giving-expected-output/#findComment-949389 Share on other sites More sharing options...
davil Posted November 2, 2009 Author Share Posted November 2, 2009 Ok so I did this: echo 'dump1->'; var_dump($_POST['newsideorders']); $newsideorders = htmlentities($_POST['newsideorders']); echo '<br/>dump2->'; var_dump($newsideorders); and here is the output (before the browser parses it) dump1->string(6) "Dégas" dump2->string(18) "Dégas" Perhaps PHP needs to be rebuilt on my server ?? I dunno Link to comment https://forums.phpfreaks.com/topic/179959-htmlentities-not-giving-expected-output/#findComment-949396 Share on other sites More sharing options...
davil Posted November 3, 2009 Author Share Posted November 3, 2009 I finally got it fixed by forcing htmlentities output to UTF-8 - I didn't realise you could do this. anyway, the code goes like this now: $newsideorders=htmlentities($var,ENT_QUOTES,'UTF-8'); I can't believe it was that simple. Thanks for any help given. Link to comment https://forums.phpfreaks.com/topic/179959-htmlentities-not-giving-expected-output/#findComment-950117 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.