Apostrophe in Variable
Posted: Wed Jan 05, 2011 4:15 pm
I have the following code that displays names in with a checkbox. The user selects the names he wants and that then get passed to a variable so that I can post it back to the parrent page. This all works with the exception of names that have appostrophes in them. I have tried using addslashes and stripslashes but have not been able to get what I want.
here is code for the page. any help would be greatly appreciated.
</head>
</div>
here is code for the page. any help would be greatly appreciated.
Code: Select all
<?php
if (!isset($_SESSION)) {
session_start();
}
//---------------------------------------------------------------
// input param $selectedList : comma separated selected id/value
// return $nColumn column check list
//---------------------------------------------------------------
function showDynamicCheckList($selectedList, $nColumn) {
// use single existed connection, make the memory efficient
global $CONN;
// split into array
$arrSelected = split(",", $selectedList);
// build option list
$sql = "SELECT Rep FROM `Liste Agents Sentiers`";
$result = mysql_query($sql);
// column counter
$colCount = 1;
$listCheckbox = "<table width='100%'>";
while($row = mysql_fetch_array($result)) {
$isSelected = (in_array($row['value'], $arrSelected)) ? "Unchecked" : "";
// first column
//------------------------------
if ($colCount == 1) {
$listCheckbox .= "<tr><td><input type='checkbox' name='myCheckbox[]' value='".$row['Rep']."' ".$isSelected."> ".$row['Rep']."</td>";
$colCount++;
// last column
//------------------------------
} else if ($colCount == $nColumn) {
$listCheckbox .= " <td><input type='checkbox' name='myCheckbox[]' value='".$row['Rep']."' ".$isSelected."> ".$row['Rep']."</td></tr>";
$colCount = 1;
// other column
//------------------------------
} else {
$listCheckbox .= " <td><input type='checkbox' name='myCheckbox[]' value='".$row['Rep']."' ".$isSelected."> ".$row['Rep']."</td>";
$colCount++;
}
}
$listCheckbox .= "</table>";
return $listCheckbox;
}
// create mysql connection
$CONN = mysql_connect("localhost", "randonneur_admin", "C4ttAbhT") or die("Could not connect: " . mysql_error());
// select database used
mysql_select_db("randonneur_quaddb");
// hold posted data into variable, build comma separated id
$selectedList = "";
if (isset($_POST['myCheckbox'])) {
$arrMyCheckbox = $_POST['myCheckbox'];
for ($i=0; $i<count($arrMyCheckbox); $i++) {
$selectedList .= $arrMyCheckbox[$i].", ";
}
}
// print the form
$_SESSION['SelectedReps'] = $selectedList;
echo "<form name='fDynamic' method='post'>".
showDynamicCheckList($selectedList, 3).
"<input type='submit' value='Selectionner' onclick='post_value();'>".
"</form>";
//close connection
mysql_close($CONN);
?>
<script language="javascript" type="text/javascript">
var SList = "<?php echo $_SESSION['SelectedReps'] ?>";
//document.write(SList);
opener.document.form1.lstPatrouilleurs.value = SList;
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<html>
<style type="text/css">
<!--
.style1 {
font-size: 24px
}
-->
</style>
<head>
<div align="center">
<?php
// Show IF Conditional region1
if (@$_SESSION['SelectedReps'] != "") {
?>
<A href="javascript: self.close ()" class="style1">Fermer la fenêtre</A>
<?php }
// endif Conditional region1
?>
<script langauge="javascript" type="text/javascript">
function post_value(){
self.close();
//}
</script>
</div>