|
|
|
เกิดปัญหา Warning: Cannot modify header information - headers already sent dreamweaver cs6 ครับ |
|
|
|
|
|
|
|
คือผมกำลังทำเกี่ยวกับระบบข่าวครับ คือพวกเพิ่มข่าว โค๊ดผมพิมพ์มือเองครับเลยไม่มีปัญหาแต่พอใช้ระบบการแก้ไขข่าวจากตัวช่วยของ dream มีปัญหาเลยครับ คือเวลาทำปกติเนี่ยยังไม่เอาขึ้นเทมเพลท โอเคไม่มีปัญหา แต่พอเอาระบบไปใส่เทมเพลทแล้วเนี่ยจะมีปัญหาเวลาผมกดส่งข้อมูลเลยอ่าครับ
Code (PHP)
<? ob_start(); ?>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<?php require_once('Connections/mk.php'); ?>
<?php
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE news SET subject=%s, detail=%s WHERE id=%s",
GetSQLValueString($_POST['subject'], "text"),
GetSQLValueString($_POST['detail'], "text"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_mk, $mk);
$Result1 = mysql_query($updateSQL, $mk) or die(mysql_error());
mysql_query("SET NAMES UTF8");
$updateGoTo = "news_shows.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_Recordset1 = "-1";
if (isset($_GET['id'])) {
$colname_Recordset1 = $_GET['id'];
}
mysql_select_db($database_mk, $mk);
$query_Recordset1 = sprintf("SELECT * FROM news WHERE id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $mk) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
#form1 p {
font-size: 18px;
color: #36C;
font-weight: bold;
}
</style>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table width="715" align="center">
<tr valign="baseline">
<td colspan="2" align="right" valign="middle" nowrap="nowrap" bgcolor="#92D3F3"><div align="center">แก้ไขข่าวสารประชาสัมพันธ์</div></td>
</tr>
<tr valign="baseline">
<td width="111" align="right" valign="middle" nowrap="nowrap" bgcolor="#92D3F3"><div align="center">หัวข้อ :</div></td>
<td width="192" bgcolor="#B8DDEF"><input type="text" name="subject" value="<?php echo htmlentities($row_Recordset1['subject'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right" valign="middle" nowrap="nowrap" bgcolor="#92D3F3"><div align="center">รายละเอียด :</div></td>
<td bgcolor="#B8DDEF"><textarea name="detail" cols="45" rows="10"><?php echo htmlentities($row_Recordset1['detail'], ENT_COMPAT, 'UTF-8'); ?></textarea></td>
</tr>
<tr valign="baseline" bgcolor="#92D3F3">
<td colspan="2" align="right" nowrap="nowrap"><div align="center">
<input type="submit" value="แก้ไข" />
</div></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="id" value="<?php echo $row_Recordset1['id']; ?>" />
</form>
<p> </p>
</body>
<?php
mysql_free_result($Recordset1);
?>
รบกวนตรวจสอบทีครับ
ขอบคุณมากครับ
Tag : PHP
|
|
|
|
|
|
Date :
2014-01-06 23:26:09 |
By :
adisorn99 |
View :
1262 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอาฟังก์ชันนี้ไปใช้แทน header() ครับ
Code (PHP)
function Redirect($url){
echo '<script>';
echo "window.location.href = '$url';";
echo '</script>';
}
แทนบรรทัดนี้
Code (PHP)
header(sprintf("Location: %s", $updateGoTo));
ด้วย
Code (PHP)
Redirect($updateGoTo);
แบบนี้ครับ ไม่มีปัญหา
|
|
|
|
|
Date :
2014-01-06 23:54:38 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอโทษฮะคือผมงงนิดหน่อย ขอแบบละเอียดๆเลยได้ไหมฮะ
ผมมือใหม่เสียจนไม่น่าเชื่ออ่าครับ
ขอรบกวนหน่อยนะฮะ
|
|
|
|
|
Date :
2014-01-06 23:59:48 |
By :
adisorn99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ข้างบนก็ละเอียดซะเป็นผงแล้วนะครับนั่น เอาแบบเต็ม
ขออธิบายก่อน
header("location: URL"); เป็นฟังก์ชั่นใช้สำหรับรีไดเรคไปหน้านึงๆ ที่เราต้องการ บางครั้งมันเกิดปัญหาดังที่คุณเห็นอยู่(มันแก้ได้ลองค้นดู)
แล้วนี่เป็นฟังก์ชันที่ผมใช้แก้ปัญหาดังกล่าววิธีนึง คือใช้จาวาสคริปให้มีประโยชน์
function Redirect($url){
echo '<script>';
echo "window.location.href = '$url';";
echo '</script>';
}
การเรียกใช้งาน ก็แค่
Redirect('ตามด้วย url ที่ต้องการให้ไป');
Code (PHP)
<?
ob_start();
function Redirect($url){
echo '<script>';
echo "window.location.href = '$url';";
echo '</script>';
}
?>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<?php require_once('Connections/mk.php'); ?>
<?php
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE news SET subject=%s, detail=%s WHERE id=%s",
GetSQLValueString($_POST['subject'], "text"),
GetSQLValueString($_POST['detail'], "text"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_mk, $mk);
$Result1 = mysql_query($updateSQL, $mk) or die(mysql_error());
mysql_query("SET NAMES UTF8");
$updateGoTo = "news_shows.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
Redirect($updateGoTo);
}
$colname_Recordset1 = "-1";
if (isset($_GET['id'])) {
$colname_Recordset1 = $_GET['id'];
}
mysql_select_db($database_mk, $mk);
$query_Recordset1 = sprintf("SELECT * FROM news WHERE id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $mk) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
#form1 p {
font-size: 18px;
color: #36C;
font-weight: bold;
}
</style>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table width="715" align="center">
<tr valign="baseline">
<td colspan="2" align="right" valign="middle" nowrap="nowrap" bgcolor="#92D3F3"><div align="center">แก้ไขข่าวสารประชาสัมพันธ์</div></td>
</tr>
<tr valign="baseline">
<td width="111" align="right" valign="middle" nowrap="nowrap" bgcolor="#92D3F3"><div align="center">หัวข้อ :</div></td>
<td width="192" bgcolor="#B8DDEF"><input type="text" name="subject" value="<?php echo htmlentities($row_Recordset1['subject'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right" valign="middle" nowrap="nowrap" bgcolor="#92D3F3"><div align="center">รายละเอียด :</div></td>
<td bgcolor="#B8DDEF"><textarea name="detail" cols="45" rows="10"><?php echo htmlentities($row_Recordset1['detail'], ENT_COMPAT, 'UTF-8'); ?></textarea></td>
</tr>
<tr valign="baseline" bgcolor="#92D3F3">
<td colspan="2" align="right" nowrap="nowrap"><div align="center">
<input type="submit" value="แก้ไข" />
</div></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="id" value="<?php echo $row_Recordset1['id']; ?>" />
</form>
<p> </p>
</body>
<?php
mysql_free_result($Recordset1);
?>
|
|
|
|
|
Date :
2014-01-07 00:14:30 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากๆครับ
หลับฝันดีแล้วคืนนี้
|
|
|
|
|
Date :
2014-01-07 00:25:09 |
By :
adisorn99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|