2011-08-10 27 views
0

我在保存子模式功能中的註釋部分時遇到了很多麻煩。其他一切節省,但筆記不會。我究竟做錯了什麼?在使用子模式功能時將我的「註釋」字段發佈到數據庫中有許多麻煩

<?php 
ini_set('display_errors', 'On'); 
error_reporting(E_ALL); 
?> 
<?php require_once('Connections/cms.php'); ?> 
<?php 
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"] == "lead_note")) { 
$updateSQL = sprintf ("UPDATE Leads SET Notes = CONCAT_WS('\n', Notes, '\n', %s) WHERE Id=%d", 
GetSQLValueString($_POST['Notes'], "text"), 
GetSQLValueString($_POST['Id'], "int")); 

mysql_select_db($database_cms, $cms); 
$Result1 = mysql_query($updateSQL, $cms) or die(mysql_error()); 

$updateGoTo = "testleadform.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_cms, $cms); 
$query_Recordset1 = sprintf("SELECT Id, First_Name, Last_Name, Notes FROM Leads WHERE Id = %s",  
GetSQLValueString($colname_Recordset1, "int")); 
$Recordset1 = mysql_query($query_Recordset1, $cms) 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" /> 

<script language="JavaScript" src="jquery.js" type="text/javascript"></script> 

<script> 
function clickSubmit() { 

//$("form").submit(); 
// window.opener.document.form1.Notes.value = $('#Notes').text(); 
    window.parent.hidePopWin(); 

} 

</script> 

</head> 

<body> 

<table><tr><td> 

<div id="lead_box"> 
<form action="<?php echo $editFormAction; ?>" method="POST" name="lead_note" id="lead_note" 
target="_top"> 
<input type="hidden" name="Id" id="Id" value="<?php echo $row_Recordset1['Id']; ?>" /> 
<table width="100%" border="0" cellpadding="0" cellspacing="5"> 
<tr> 
<td colspan="2" bgcolor="#eeeeee"><p align="center" class="name"></p></td> 
</tr> 
<tr> 
<td><textarea rows="15" style="width: 99%" readonly><?php echo $row_Recordset1['Notes']; ?></textarea>  
</td> 
</tr> 
<tr> 
<td valign="top"><p class="title">Add Note:</p></td> 
<tr> 
    <td> 
    <textarea name="Notes" id="Notes" style="width: 99%" rows="5"></textarea> 
</td> 
</tr> 
</table> 
<input type="hidden" name="MM_update" value="lead_note" /> 
</form> 
</div><!-- and of lead box --> 
</td></tr> 
<tr><td> 
<div align="right"> 
<input type="submit" name="save" id="save" value="Save" onClick="clickSubmit()"/> 
<input type="button" name="cancel" id="cancel" value="Cancel" onClick="window.parent.hidePopWin()"/> 
</div> 
</td></tr></table> 



</body> 
</html> 
<?php 
mysql_free_result($Recordset1); 
?> 
+0

那麼錯誤是什麼? – Pehmolelu

+0

有沒有...我唯一的問題是,「註釋」字段不會插入到數據庫中,並且每個其他字段都會... –

回答

0

你爲什麼不使用PDO OR MYSQLI,而不是MySQL的?如果您將使用PDO你不會需要「清」,由你自己的變量:

switch ($theType) { 
case "text": 
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
    break;  
    .... 
} 

您可以使用PDO預處理語句:pdostatement

能否請您插入var_dump這裏

var_dump($_POST); 
$updateSQL = sprintf ("UPDATE Leads SET Notes = CONCAT_WS('\n', Notes, '\n', %s) WHERE Id=%d", 
GetSQLValueString($_POST['Notes'], "text"), 
GetSQLValueString($_POST['Id'], "int")); 
var_dump($updateSQL,$_POST['Notes']); 

並告訴我們,輸出是什麼?

+0

已經解決了,謝謝! –