bine.heckmann Posted November 26, 2010 Share Posted November 26, 2010 Hello, i've got some trouble with one of my scripts which is some kind of a CMS which includes a support function which allows the user to create support tickets. Now those tickets are saved in a MySQL db, which all works fine, my problem is some special german characters which are mandatory for my support won't properly save in the DB. I tried everything from setting headers to UTF-8 Charset to changing the Collation in phpmyadmin, but nothing works. I also set mysql_real_escape_string in my script but i'm not sure if i did it right. the special characters in question are "Öö, Ää and Üü" the code: Index.php <?php ##################### # index.php # ##################### ob_start(); session_start(); include('libs/mysql_config.php'); include('libs/class_user.php'); include('libs/class_bbcode.php'); $mysql_connect = mysql_connect($mysql_host, $mysql_username, $mysql_password); mysql_select_db($mysql_database, $mysql_connect); $user = new user; $bbcode = new SimpleBBCode; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="shortcut icon" href="/favicon.ico" > <?php $title = mysql_query("SELECT `cms_title` FROM `shop_options`") OR die(mysql_error()); $title_row = mysql_fetch_assoc($title); echo "<title>".$title_row['cms_title']."</title>\n"; ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="style/_style.css" media="all" /> <script type="text/javascript"> <!-- function MM_swapImgRestore() { var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } function Border () { var box1 = document.getElementById("left"); var box2 = document.getElementById("right"); var height = Math.max(box1.offsetHeight, box2.offsetHeight); box1.style.height = height + "px"; box2.style.height = height + "px"; } //--> </script> </head> <body onload="Border()"> <div id="head_login"> </div> <div id="header"> <div class="left"> <?php if ($user->check_login() == false) { echo 'Hello, Guest <a href="index.php?site=login"><strong>Login</strong></a> or <a href="index.php?site=register"><strong>Register</strong></a>'; } elseif ($user->check_login() == true) { if(strlen($_SESSION["username"]) > 7) { $username = substr($_SESSION["username"], 0, 6) . '..'; } else { $username = $_SESSION["username"]; } echo "Hello, <a href='index.php?site=account'><strong>".$username."</strong></a> (".$user->check_credits($_SESSION["userid"])." €) <a href='index.php?site=logout'><strong>Logout</strong></a>"; } ?> </div> <div style="margin-left: 220px;"><img src="style/images/header.PNG" border="0"></div> </div> <div id="body"> <div class="navigation_head"> <div style="margin-left: 125px; float: left;"><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Home','','style/images/home_2.JPG',1)"><img src="style/images/home.JPG" border="0" name="Home"></a></div> <div style="margin-left: 15px; float: left;"><a href="index.php?site=cashin" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Cashin','','style/images/cashin_2.JPG',1)"><img src="style/images/cashin.JPG" border="0" name="Cashin"></a></div> <div style="margin-left: 15px; float: left;"><a href="index.php?site=account" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Account','','style/images/account_2.JPG',1)"><img src="style/images/account.JPG" border="0" name="Account"></a></div> <div style="margin-left: 15px; float: left;"><a href="index.php?site=faq" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Faq','','style/images/faq_2.JPG',1)"><img src="style/images/faq.JPG" border="0" name="Faq"></a></div> <div style="margin-left: 15px; float: left;"><a href="index.php?site=support" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Support','','style/images/support_2.JPG',1)"><img src="style/images/support.JPG" border="0" name="Support"></a></div> <?php $status = mysql_query("SELECT `status` FROM `shop_user` WHERE `userid` = '".$_SESSION["userid"]."' AND `username` = '".$_SESSION["username"]."'") OR die(mysql_error()); $status_r = mysql_fetch_assoc($status); if($status_r["status"] == 3) { echo "<a href='admin/'><strong>Admin</strong></a>"; } elseif($status_r["status"] != 3) { #nothing; } ?> </div> <div id="left"> <div style="margin-top: 5px;margin-left: -6px;"><img src="style/images/warenkorb.JPG" border="0"></div> <?php $w_n = mysql_query("SELECT `userid` FROM `shop_basket` WHERE `userid` = '".$_SESSION["userid"]."'") OR die(mysql_error()); $w_r = mysql_num_rows($w_n); ?> <div style="margin-top: 8px; margin-left: 15px; color: #808080; float: left;">Waren: <strong><?php echo $w_r; ?></strong></div> <div style="margin-left: 80px; margin-top: 20px; float: left;"><a href="index.php?site=basket"><img src="style/images/checkout.JPG" border="0"></a></div> <div style="margin-left: -6px;"><img src="style/images/produkte.JPG" border="0"></div> <?php $navigation = "SELECT * FROM `shop_navigation` ORDER BY `sort` ASC"; $do = mysql_query($navigation) OR die(mysql_error()); while($n_row = mysql_fetch_assoc($do)) { echo "<div style='margin-left: 10px; margin-top: 10px; color: #808080;'><a href='index.php?site=cat&id=".$n_row["id"]."'>".$n_row["name"]."</a></div><hr style='width: 225px; color: #2a2a2a;'>\n"; } ?> <div style="margin-left: -6px; margin-top: 20px;"><img src="style/images/zahlung.JPG" border="0"></div> </div> <div id="right"> <?php $site = $_GET["site"]; if($site == "login") { include('login.php'); } elseif($site == "register") { include('register.php'); } elseif($site == "account") { include('account.php'); } elseif($site == "faq") { include('faq.php'); } elseif($site == "support") { include('support.php'); } elseif($site == "error") { include('error.php'); } elseif($site == "logout") { include('logout.php'); } elseif($site == "cat") { include('category.php'); } elseif($site == "prod") { include('product.php'); } elseif($site == "basket") { include('basket.php'); } elseif($site == "checkout") { include('checkout.php'); } else { ?> <div class="topnews"><img src="style/images/news.JPG" border="0"></div> <div class="news"> <?php $limit = mysql_query("SELECT `index_news` FROM `shop_options`") OR die(mysql_error()); $limit_r = mysql_fetch_assoc($limit); $news = mysql_query("SELECT * FROM `shop_news` ORDER BY `date` DESC LIMIT ".$limit_r["index_news"]."") OR die(mysql_error()); while($ne_row = mysql_fetch_array($news)) { $tmp = explode("-", $ne_row["date"]); $newdate = $tmp[2].".".$tmp[1].".".$tmp[0]; echo "<div style='padding-top: 5px; margin-left: 15px; color: #7d7d7d; font-size: 16px;'><strong>"; echo str_replace(array('Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', 'ß'), array("Ä", "ä", "Ö", "ö", "Ü", "ü", "ß"), $ne_row['title']); echo "</strong></div><hr style='width:580px; color: #FFFFFF;'>"; echo "<div style='margin-top: 5px; margin-left: 25px; color: #707070; font-size: 14px;'><strong>"; echo nl2br(str_replace(array('Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', 'ß'), array("Ä", "ä", "Ö", "ö", "Ü", "ü", "ß"), $ne_row['text'])); echo "</strong></div>"; } ?> <div class="bottom"></div> </div> <?php } ?> <div style="clear:both;"></div> </div> <br /> <br /> </body> </html> <?php ob_end_flush(); ?> Support.php <?php ##################### # support.php # ##################### if ($user->check_login() == false) { header("location: index.php?site=login"); } elseif($user->check_login() == true) { $background_color = array( 1 => "#ffd7d7", //rot 2 => "#fffe92", //gelb 3 => "#d4ffe3"); //grün $ticket_status = array( 1 => "unbearbeitet", 2 => "in bearbeitung", 3 => "bearbeitet"); if($_GET["show"] == "ticket") { $support = "SELECT * FROM `shop_tickets` WHERE `userid` = '".$_SESSION["userid"]."' AND `id` = '".intval($_GET["ticketid"])."'"; $support_r = mysql_query($support) OR die(mysql_error()); $support_num = mysql_num_rows($support_r); if($support_num == 0) { header("location: index.php?site=support"); } elseif($support_num != 0) { $support_row = mysql_fetch_assoc($support_r); echo "<div style='margin-left:15px; padding-top:10px; font-size: 14px;'><strong>Ticket #".$support_row["id"]."</strong></div>"; echo "<div style='margin-left:15px; margin-top:25px; font-size: 12px;'>Datum: <strong>".$support_row["date"]."</strong></div>"; echo "<div style='margin-left:15px; margin-top:5px; font-size: 12px;'>Betreff: <strong>".$support_row["title"]."</strong></div>"; echo "<div style='margin-left:15px; margin-top:5px; font-size: 12px;'>Status: <strong>".$ticket_status[$support_row["status"]]."</strong></div>"; echo "<div style='margin-left:15px; margin-top:20px; font-size: 14px;'><strong>Beschreibung</strong></div>"; echo "<div style='width: 450px; min-height: 100px; height: auto; background-color: #f6f6f6; margin-left: 15px; margin-top: 15px; font-size: 12px; border: 1px solid #b5c2d5;'>"; echo nl2br($support_row["ticket"]); echo "</div>"; echo "<div style='margin-left:15px; margin-top:20px; font-size: 14px;'><strong>Antwort</strong></div>"; echo "<div style='width: 450px; min-height: 100px; height: auto; background-color: #f6f6f6; margin-left: 15px; margin-top: 15px; font-size: 12px; border: 1px solid #b5c2d5;'>"; echo nl2br($support_row["answer"]); echo "</div>"; echo "<br /><br /><div style='margin-left: 15px;'><a href='index.php?site=support'><img src='style/images/arrow_left.PNG' border='0'> <strong>zur Ticketübersicht</strong></a></div><br /><br/><br/>"; } } elseif($_GET["do"] == "create") { echo "<form action='support_do.php' method='post'>"; echo "<div style='margin-left:15px; padding-top:10px; font-size: 14px;'><strong>Neues Ticket erstellen</strong></div>"; echo "<div style='margin-left:15px; margin-top:25px; font-size: 12px;'><strong>Betreff: </strong><input type='text' name='title' style='width: 288px;'></div>"; echo "<div style='margin-left:15px; margin-top:5px; font-size: 12px;'><textarea name='text' rows='10' cols='40'></textarea></div>"; echo "<div style='margin-left:15px; margin-top:10px; font-size: 12px;'><input type='submit' name='submit' value='Ticket erstellen'></div>"; echo "</form>"; } else { echo '<div class="topnews"><img src="style/images/tsupport.JPG" border="0"></div>'; echo '<div class="news">'; echo "<div style='margin-left: 15px; font-size: 14px;'><a href='index.php?site=support&do=create'><img src='style/images/add.PNG' border='0'> <strong>Neues Ticket erstellen</strong></a></div>"; echo "<br />"; echo "<div class='support'>"; echo "<div style='width: 40px; height: 20px; text-align: center; background-color: #f6f6f6; float: left; border-left: 1px solid #b5c2d5; border-top: 1px solid #b5c2d5; border-bottom: 1px solid #b5c2d5; font-size: 14px;'>ID</div>"; echo "<div style='width: 248px; height: 20px; background-color: #f6f6f6; float: left; border-left: 1px solid #b5c2d5; border-top: 1px solid #b5c2d5; border-bottom: 1px solid #b5c2d5; font-size: 14px;'> Betreff</div>"; echo "<div style='width: 87px; height: 20px; background-color: #f6f6f6; float: left; border-left: 1px solid #b5c2d5; border-top: 1px solid #b5c2d5; border-bottom: 1px solid #b5c2d5; font-size: 14px;'> Status</div>"; echo "<div style='width: 98px; height: 20px; text-align: center; background-color: #f6f6f6; float: left; border-left: 1px solid #b5c2d5; border-top: 1px solid #b5c2d5; border-bottom: 1px solid #b5c2d5; border-right: 1px solid #b5c2d5; font-size: 14px;'>Datum</div>"; echo "</div>"; echo "<div style='clear:both;'></div>"; $support = "SELECT * FROM `shop_tickets` WHERE `userid` = '".$_SESSION["userid"]."' ORDER BY `date` DESC"; $support_r = mysql_query($support) OR die(mysql_error()); while($support_row = mysql_fetch_assoc($support_r)) { if(strlen($support_row["title"]) > 27) $support_row["title"] = substr($support_row["title"], 0, 26) . '..'; echo "<a href='index.php?site=support&show=ticket&ticketid=".$support_row["id"]."'><div class='support'>"; echo "<div style='width: 40px; height: 20px; line-height: 20px; text-align: center; background-color: ".$background_color[$support_row["status"]]."; ; float: left; border-left: 1px solid #b5c2d5; border-bottom: 1px solid #b5c2d5; font-size: 12px;'>".$support_row["id"]."</div>"; echo "<div style='width: 248px; height: 20px; line-height: 20px; background-color: ".$background_color[$support_row["status"]]."; ; float: left; border-left: 1px solid #b5c2d5; border-bottom: 1px solid #b5c2d5; font-size: 12px;'> ".$support_row["title"]."</div>"; echo "<div style='width: 87px; height: 20px; line-height: 20px; background-color: ".$background_color[$support_row["status"]]."; ; float: left; border-left: 1px solid #b5c2d5; border-bottom: 1px solid #b5c2d5; font-size: 12px;'> ".$ticket_status[$support_row["status"]]."</div>"; echo "<div style='width: 98px; height: 20px; line-height: 20px; text-align: center; background-color: ".$background_color[$support_row["status"]]."; ; float: left; border-left: 1px solid #b5c2d5; border-bottom: 1px solid #b5c2d5; border-right: 1px solid #b5c2d5; font-size: 12px;'>".$support_row["date"]."</div>"; echo "</div></a>"; echo "<div style='clear:both;'></div>"; } } } echo "</div>"; echo "<div class='bottom'></div>"; ?> Support.do.php <?php ##################### # support_do.php # ##################### session_start(); include('libs/mysql_config.php'); include('libs/class_user.php'); $mysql_connect = mysql_connect($mysql_host, $mysql_username, $mysql_password); mysql_select_db($mysql_database, $mysql_connect); $user = new user; if ($user->check_login() == false) { header("location: index.php?site=login"); } elseif($user->check_login() == true) { $title = htmlspecialchars(mysql_real_escape_string($_POST["title"])); $text = htmlspecialchars(mysql_real_escape_string($_POST["text"])); $date = date("Y-m-d"); if(empty($title) || empty($text)) { header("location: index.php?site=support&do=create"); } else { $insert = "INSERT INTO `shop_tickets` (`userid`, `title`, `ticket`, `status`, `date`) VALUES ('".$_SESSION["userid"]."', '".$title."', '".$text."', '1', '".$date."')"; $insert_do = mysql_query($insert) OR die(mysql_error()); header("location: index.php?site=support"); } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.