ถามเรื่องการใช้ sprintf อะครับอ่านแล้ว ลองทำแล้วมันเกิด Error
<?php require_once("../Connections/docconnection.php"); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
include ("../function.php");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}
mysql_select_db($database_schoolsmile, $schoolsmile);
$query_Sub_GroupRS = sprintf("SELECT * FROM tbl_sub_group ORDER BY id_s ASC");
$Sub_GroupRS = mysql_query($query_Sub_GroupRS, $schoolsmile) or die(mysql_error());
$row_Sub_GroupRS = mysql_fetch_assoc($Sub_GroupRS);
$totalRows_Sub_GroupRS = mysql_num_rows($Sub_GroupRS);
?>
<?php
if ((isset($_POST['hiddenDelID'])) && ($_POST['hiddenDelID'] != "")) {
$deleteSQL = sprintf("DELETE FROM tbl_sub_group WHERE id_s = %s",
GetSQLValueString($_POST['hiddenDelID'], "int"));
mysql_select_db($database_schoolsmile, $schoolsmile);
$Result1 = mysql_query($deleteSQL, $schoolsmile) or die(mysql_error());
$deleteGoTo = "showSub_Group.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s"));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ระบบจัดการเว็บไซต์</title>
<link href="adminstyle.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<table width="560" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left"><table width="550" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td height="25" colspan="4" align="center" bordercolor="#FFFFFF" bgcolor="#E4CAAF"><img src="../images/04.png" width="16" height="16" /> แสดงแผนก</td>
</tr>
<tr>
<td height="10" colspan="4" align="right" bordercolor="#FFFFFF">จำนวนทั้งหมด <?php echo $totalRows_Sub_GroupRS; ?></td>
</tr>
<tr>
<td width="140" height="25" align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC">รหัสแผนก</td>
<td align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC">ชื่อแผนก</td>
<td width="40" align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC">แก้ไข</td>
<td width="40" align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC">ลบ</td>
</tr>
<?php if ($totalRows_Sub_GroupRS > 0) { // Show if recordset not empty ?>
<?php do { ?>
<tr >
<td height="1" colspan="4" align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC"><img src="../images/px1.gif" width="1" height="1"></td>
</tr>
<tr >
<td bordercolor="#FFFFFF" bgcolor="#F5F5F5"> <strong><?php echo $row_Sub_GroupRS['id_s']; ?></strong></td>
<td align="left" bordercolor="#FFFFFF" bgcolor="#F5F5F5"> <strong><?php echo $row_Sub_GroupRS['gsname']; ?></strong>
</td>
<td align="center" bordercolor="#FFFFFF" bgcolor="#F5F5F5">
<form name="formEdit" method="post" action="showSub_Group.php#editSub_Group">
<input type="image" name="edit" value="Submit" src="../images/b_edit.png" alt="แก้ไขข้อมูล">
<br>
<input name="hiddenEditID" type="hidden" id="hiddenEditID" value="<?php echo $row_Sub_GroupRS['id_s']; ?>">
</form></td>
<td align="center" bordercolor="#FFFFFF" bgcolor="#F5F5F5">
<form name="formDelete" method="post" action="showSub_Group.php" onsubmit="return R_confirm('<?php echo $row_Sub_GroupRS['gsname']; ?>')">
<input type="image" name="edit" value="Submit" src="../images/b_drop.png" alt="ลบข้อมูล" >
<br>
<input name="hiddenDelID" type="hidden" id="hiddenDelID" value="<?php echo $row_Sub_GroupRS['id_s']; ?>">
</form></td>
</tr>
<?php } while ($row_Sub_GroupRS = mysql_fetch_assoc($Sub_GroupRS)); ?>
<?php } // Show if recordset not empty ?>
</table>
<br>
<a name="editSub_Group"></a>
<?php
if ((isset($_POST['hiddenEditID'])) && ($_POST['hiddenEditID'] != "")) {
include("editSub_Group.php");
}
else {
include ("addSub_Group.php");
}
?>
<br>
</td>
</tr>
</table>
<script language="JavaScript">
function R_confirm(msg)
{
var x=window.confirm("ต้องการลบข้อมูลนี้\n'"+msg+"'\nใช่หรือไม่?");
return (x);
}
</script>
<?php
mysql_free_result($Sub_GroupRS);
?>
Code (PHP)
เป็นการลบ ข้อความออกมา table ครับ แล้วให้กลับมาหน้าเดิม ครับ
แต่พอผมลบแล้วมันฟ้อง
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\repair2\admin\showSub_Group.php:46) in C:\AppServ\www\repair2\admin\showSub_Group.php on line 59Tag : PHP
Date :
2013-09-16 16:15:55
By :
ภัทรมย์
View :
709
Reply :
1
Code (PHP)
<?php require_once("../Connections/docconnection.php"); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
include ("../function.php");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}
mysql_select_db($database_schoolsmile, $schoolsmile);
$query_Sub_GroupRS = sprintf("SELECT * FROM tbl_sub_group ORDER BY id_s ASC");
$Sub_GroupRS = mysql_query($query_Sub_GroupRS, $schoolsmile) or die(mysql_error());
$row_Sub_GroupRS = mysql_fetch_assoc($Sub_GroupRS);
$totalRows_Sub_GroupRS = mysql_num_rows($Sub_GroupRS);
?>
<?php
if ((isset($_POST['hiddenDelID'])) && ($_POST['hiddenDelID'] != "")) {
$deleteSQL = sprintf("DELETE FROM tbl_sub_group WHERE id_s = %s",
GetSQLValueString($_POST['hiddenDelID'], "int"));
mysql_select_db($database_schoolsmile, $schoolsmile);
$Result1 = mysql_query($deleteSQL, $schoolsmile) or die(mysql_error());
$deleteGoTo = "showSub_Group.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s"));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ระบบจัดการเว็บไซต์</title>
<link href="adminstyle.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<table width="560" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left"><table width="550" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td height="25" colspan="4" align="center" bordercolor="#FFFFFF" bgcolor="#E4CAAF"><img src="../images/04.png" width="16" height="16" /> แสดงแผนก</td>
</tr>
<tr>
<td height="10" colspan="4" align="right" bordercolor="#FFFFFF">จำนวนทั้งหมด <?php echo $totalRows_Sub_GroupRS; ?></td>
</tr>
<tr>
<td width="140" height="25" align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC">รหัสแผนก</td>
<td align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC">ชื่อแผนก</td>
<td width="40" align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC">แก้ไข</td>
<td width="40" align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC">ลบ</td>
</tr>
<?php if ($totalRows_Sub_GroupRS > 0) { // Show if recordset not empty ?>
<?php do { ?>
<tr >
<td height="1" colspan="4" align="center" bordercolor="#FFFFFF" bgcolor="#CCCCCC"><img src="../images/px1.gif" width="1" height="1"></td>
</tr>
<tr >
<td bordercolor="#FFFFFF" bgcolor="#F5F5F5"> <strong><?php echo $row_Sub_GroupRS['id_s']; ?></strong></td>
<td align="left" bordercolor="#FFFFFF" bgcolor="#F5F5F5"> <strong><?php echo $row_Sub_GroupRS['gsname']; ?></strong>
</td>
<td align="center" bordercolor="#FFFFFF" bgcolor="#F5F5F5">
<form name="formEdit" method="post" action="showSub_Group.php#editSub_Group">
<input type="image" name="edit" value="Submit" src="../images/b_edit.png" alt="แก้ไขข้อมูล">
<br>
<input name="hiddenEditID" type="hidden" id="hiddenEditID" value="<?php echo $row_Sub_GroupRS['id_s']; ?>">
</form></td>
<td align="center" bordercolor="#FFFFFF" bgcolor="#F5F5F5">
<form name="formDelete" method="post" action="showSub_Group.php" onsubmit="return R_confirm('<?php echo $row_Sub_GroupRS['gsname']; ?>')">
<input type="image" name="edit" value="Submit" src="../images/b_drop.png" alt="ลบข้อมูล" >
<br>
<input name="hiddenDelID" type="hidden" id="hiddenDelID" value="<?php echo $row_Sub_GroupRS['id_s']; ?>">
</form></td>
</tr>
<?php } while ($row_Sub_GroupRS = mysql_fetch_assoc($Sub_GroupRS)); ?>
<?php } // Show if recordset not empty ?>
</table>
<br>
<a name="editSub_Group"></a>
<?php
if ((isset($_POST['hiddenEditID'])) && ($_POST['hiddenEditID'] != "")) {
include("editSub_Group.php");
}
else {
include ("addSub_Group.php");
}
?>
<br>
</td>
</tr>
</table>
<script language="JavaScript">
function R_confirm(msg)
{
var x=window.confirm("ต้องการลบข้อมูลนี้\n'"+msg+"'\nใช่หรือไม่?");
return (x);
}
</script>
<?php
mysql_free_result($Sub_GroupRS);
?>
Date :
2013-09-16 16:17:48
By :
ภัทรมย์
Load balance : Server 02