我是一个PHP和MYSQL的初学者,我真的需要你的帮助。我试图插入新的信息到数据库中,并安装了次模态功能来输入和查看客户笔记。我正试图插入一个"新客户"到数据库中,并不断得到未定义的索引错误为"笔记"字段…我不知道如何声明值,因为我正在使用子模态功能,也有一个图像,用户将点击激活子模态。这是表格的代码…非常感谢大家!!
<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> </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);
?>
如果可以取消$row_Recordset1['Id']
的设置,请尝试以下操作:
<a href="subform.php?Id=<?php if (isset($row_Recordset1['Id'])) { echo $row_Recordset1['Id']; } ?>" class="submodal">
您是否通过表单访问此页面?如果不存在,则表示$_POST
不存在。同样,如果没有称为Notes
的字段(区分大小写-即<input name="Notes">
),则该字段不存在,并将抛出这种类型的错误。如果它返回到这个页面,在尝试访问这个变量之前,检查$_POST
和if(isset($_POST))
是否存在。
原始回答
如果你得到一个未定义的索引错误在你的注释:部分,那么$row_Recordset1['Id'];
不存在。确保您的数据库字段是Id
(区分大小写),而不是ID
、id
或其他变体。class="submodal"
看起来像HTML代码,不应该影响这个问题。