2011-08-09 13 views
0

我是PHP和MYSQL的初學者,我真的需要你的幫助。我試圖在數據庫中插入新的信息,並安裝了submodal功能來輸入和查看客戶筆記。我試圖插入一個「新客戶」數據庫,並不斷獲取未定義的索引錯誤的「註釋」字段...我不知道如何聲明該值,因爲我使用的是submodal功能,也有一個圖像用戶將點擊激活子模式。這是桌子的代碼...非常感謝你!不斷獲取未定義的索引錯誤,無法弄清楚如何在submodal窗口中聲明值

<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" target="_top" id="form1"> 
<table width="30%%" border="1"> 
<tr> 
    <td>First Name:</td> 
    <td><label for="First_Name"></label> 
    <input type="text" name="First_Name" id="First_Name" /></td> 
</tr> 
<tr> 
    <td>Last Name:</td> 
    <td><label for="Last_Name"></label> 
    <input type="text" name="Last_Name" id="Last_Name" /></td> 
</tr> 
<tr> 
    <td>Address:</td> 
    <td><label for="Address"></label> 
    <input type="text" name="Address" id="Address" /></td> 
</tr> 
<tr> 
    <td>City:</td> 
    <td><label for="City"></label> 
    <input type="text" name="City" id="City" /></td> 
</tr> 

<tr> 
    <td>Zip:</td> 
    <td><label for="Zip"></label> 
    <input type="text" name="Zip" id="Zip" /></td> 
</tr> 
<tr> 
    <td>Phone:</td> 
    <td><label for="Phone"></label> 
    <input type="text" name="Phone" id="Phone" /></td> 
</tr> 
<tr> 
    <td>E-Mail:</td> 
    <td><label for="Email"></label> 
    <input type="text" name="Email" id="Email" /></td> 
</tr> 
<tr> 
    <td>Fee:</td> 
    <td><label for="Fee"></label> 
    <input type="text" name="Fee" id="Fee" /></td> 
</tr> 
<tr> 
    <td>Referral Source:</td> 
    <td><label for="Referral_Source"></label> 
    <input type="text" name="Referral_Source" id="Referral_Source" /></td> 
</tr> 
<tr> 
    <td>Notes:</td> 
    <td><a href="subform.php?Id=<?php echo $row_Recordset1['Id']; ?>" class="submodal"><img  
    src="Images/editnote.png" class="pencil" width="33" height="33" /></a></td> 
</tr> 
<tr> 
    <td>&nbsp;</td> 
    <td><input type="submit" name="Submit" id="Submit" value="Submit" /></td> 
</tr> 
</table> 
<input type="hidden" name="MM_insert" value="form1" /> 

Notice: Undefined index: Notes in /home/content/02/8116402/html/testleadform.php on line 55 

         GetSQLValueString($_POST['Notes'], "text")); 


Notice: Undefined index: Notes in /home/content/02/8116402/html/testleadform.php on line 55 

Warning: Cannot modify header information - headers already sent by (output started at  
/home/content/02/8116402/html/testleadform.php:55) in /home/content/02/8116402/html/testleadform.php  
on line 65 

Line 65: header(sprintf("Location: %s", $insertGoTo)); 




<?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_insert"])) && ($_POST["MM_insert"] == "form1")) { 
$insertSQL = sprintf("INSERT INTO Leads (First_Name, Last_Name, Address, City, `State`, Zip, Phone, 
Email, Fee, Referral_Source, Notes) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", 
        GetSQLValueString($_POST['First_Name'], "text"), 
        GetSQLValueString($_POST['Last_Name'], "text"), 
        GetSQLValueString($_POST['Address'], "text"), 
        GetSQLValueString($_POST['City'], "text"), 
        GetSQLValueString($_POST['State'], "text"), 
        GetSQLValueString($_POST['Zip'], "text"), 
        GetSQLValueString($_POST['Phone'], "text"), 
        GetSQLValueString($_POST['Email'], "text"), 
        GetSQLValueString($_POST['Fee'], "int"), 
        GetSQLValueString($_POST['Referral_Source'], "text"), 
        GetSQLValueString($_POST['Notes'], "text")); 

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

$insertGoTo = "leads.php"; 
if (isset($_SERVER['QUERY_STRING'])) { 
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; 
$insertGoTo .= $_SERVER['QUERY_STRING']; 
} 
header(sprintf("Location: %s", $insertGoTo)); 
} 

mysql_select_db($database_cms, $cms); 
$query_Recordset1 = "SELECT * FROM Leads"; 
$Recordset1 = mysql_query($query_Recordset1, $cms) or die(mysql_error()); 
$row_Recordset1 = mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysql_num_rows($Recordset1); 
?> 
+1

這是什麼「submodal功能,」你說的? – cdhowie

回答

0

你通過表單訪問該頁面?如果不是,$_POST不存在。另外,如果沒有被稱爲Notes(區分大小寫 - 即<input name="Notes">)的字段,則該字段不存在並且將引發這種類型的錯誤。如果它返回到此頁面,請在嘗試訪問變量之前檢查$_POST是否存在if(isset($_POST))

原來的答案

如果您得到您的注意一個未定義的索引錯誤:一節,然後$row_Recordset1['Id'];不存在。確保您的數據庫字段爲Id(區分大小寫),而不是IDid或某些變體。 class="submodal"看起來像HTML代碼,不應該影響這個問題。

+0

我發現有趣的是,當只有一個可用變體時,你說「或某種變化」 – Mike

+0

我剛剛更新了我的問題......我粘貼了錯誤和問題行..我知道我沒有聲明值的筆記,我無法弄清楚如何與子模式功能和圖像.. –

+0

@亞歷克斯:更新回答 – RageD

0

如果它是有效的$row_Recordset1['Id']被取消設置,請執行以下操作:

<a href="subform.php?Id=<?php if (isset($row_Recordset1['Id'])) { echo $row_Recordset1['Id']; } ?>" class="submodal"> 
+0

沒有工作,粘貼上面的錯誤.. –

+0

您收到的錯誤不是從您粘貼上面的代碼。看看錯誤消息。你會看到它來自'55h'上的'/home/content/02/8116402/html/testleadform.php'。我假設$ _POST ['Notes']不存在。 – Mike

+0

@麥克沒錯,這是我的問題...我不知道如何在表中設定的值,它...​​注: ​​ ... –

相關問題