- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在制作一个表单,该表单接收数据并将其输出到表中,将数据插入表单并按提交按钮后,我收到以下错误:
Notice: Undefined property: stdClass::$memberID inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 40
Notice: Undefined property: stdClass::$username inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 41
Notice: Undefined property: stdClass::$password inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 42
Notice: Undefined property: stdClass::$firstname inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 43
Notice: Undefined property: stdClass::$lastname inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 44
Notice: Undefined property: stdClass::$address inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 45
Notice: Undefined property: stdClass::$email inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 46
Notice: Undefined property: stdClass::$memberID inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 47
Notice: Undefined property: stdClass::$memberID inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 48
Notice: Undefined property: stdClass::$memberID inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 40
Notice: Undefined property: stdClass::$username inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 41
Notice: Undefined property: stdClass::$password inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 42
Notice: Undefined property: stdClass::$firstname inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 43
Notice: Undefined property: stdClass::$lastname inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 44
Notice: Undefined property: stdClass::$address inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 45
Notice: Undefined property: stdClass::$email inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 46
Notice: Undefined property: stdClass::$memberID inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 47
Notice: Undefined property: stdClass::$memberID inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 48
Notice: Undefined property: stdClass::$memberID inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 40
Notice: Undefined property: stdClass::$username inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 41
Notice: Undefined property: stdClass::$password inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 42
Notice: Undefined property: stdClass::$firstname inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 43
Notice: Undefined property: stdClass::$lastname inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 44
Notice: Undefined property: stdClass::$address inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 45
Notice: Undefined property: stdClass::$email inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 46
Notice: Undefined property: stdClass::$memberID inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 47
Notice: Undefined property: stdClass::$memberID inD:\Xamp\htdocs\Assignment\Addmember\New Ver\view.php on line 48
表单代码:
<?php
/*
Allows the user to both create new records and edit existing records
*/
// connect to the database
include("connection.php");
// creates the new/edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($username = '', $password ='', $firstname ='', $lastname ='', $address ='', $email ='', $error = '', $memberID = '')
{ ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>
<?php if ($memberID != '') { echo "Edit Record"; } else { echo "New Record"; } ?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h1><?php if ($memberID != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1>
<?php if ($error != '') {
echo "<div style='padding:4px; border:1px solmemberID red; color:red'>" . $error
. "</div>";
} ?>
<form action="" method="post">
<div>
<?php if ($memberID != '') { ?>
<input type="hidden" name="memberID" value="<?php echo $memberID; ?>" />
<p>memberID: <?php echo $memberID; ?></p>
<?php } ?>
<strong>Username: *</strong> <input type="text" name="username" value="<?php echo $username; ?>"/><br/>
<strong>Password: *</strong> <input type="password" name="password" value="<?php echo $password; ?>"/><br/>
<strong>First Name: *</strong> <input type="text" name="firstname" value="<?php echo $firstname; ?>"/><br/>
<strong>Last Name: *</strong> <input type="text" name="lastname" value="<?php echo $lastname; ?>"/><br/>
<strong>Address: *</strong> <input type="text" name="address" value="<?php echo $address; ?>"/><br/>
<strong>Email: *</strong> <input type="text" name="email" value="<?php echo $email; ?>"/><br/>
<p>* required</p>
<input type="submit" name="submit" value="Submit" />
</div>
</form>
</body>
</html>
<?php }
/*
EDIT RECORD
*/
// if the 'memberID' variable is set in the URL, we know that we need to edit a record
if (isset($_GET['memberID']))
{
// if the form's submit button is clicked, we need to process the form
if (isset($_POST['submit']))
{
// make sure the 'memberID' in the URL is valmemberID
if (is_numeric($_POST['memberID']))
{
// get variables from the URL/form
$memberID = $_POST['memberID'];
$username = htmlentities($_POST['username'], ENT_QUOTES);
$password = htmlentities($_POST['password'], ENT_QUOTES);
$firstname = htmlentities($_POST['firstname'], ENT_QUOTES);
$lastname = htmlentities($_POST['lastname'], ENT_QUOTES);
$address = htmlentities($_POST['address'], ENT_QUOTES);
$email = htmlentities($_POST['email'], ENT_QUOTES);
// check that firstname and lastname are both not empty
if ($username == '' || $password == '' || $firstname == '' || $lastname == '' || $address == '' || $email == '')
{
// if they are empty, show an error message and display the form
$error = 'ERROR: Please fill in all required fields!';
renderForm($username, $password, $firstname, $lastname, $address, $email, $error, $memberID);
}
else
{
// if everything is fine, update the record in the database
if ($stmt = $mysqli->prepare("UPDATE players SET firstname = ?, lastname = ?
WHERE memberID=?"))
{
$stmt->bind_param("ssi", $firstname, $lastname, $memberID, $username, $password, $address, $email);
$stmt->execute();
$stmt->close();
}
// show an error message if the query has an error
else
{
echo "ERROR: could not prepare SQL statement.";
}
// redirect the user once the form is updated
header("Location: view.php");
}
}
// if the 'memberID' variable is not valmemberID, show an error message
else
{
echo "Error!";
}
}
// if the form hasn't been submitted yet, get the info from the database and show the form
else
{
// make sure the 'memberID' value is valmemberID
if (is_numeric($_GET['memberID']) && $_GET['memberID'] > 0)
{
// get 'memberID' from URL
$memberID = $_GET['memberID'];
// get the recod from the database
if($stmt = $mysqli->prepare("SELECT * FROM members WHERE memberID=?"))
{
$stmt->bind_param("i", $memberID);
$stmt->execute();
$stmt->bind_result($memberID, $firstname, $lastname, $username, $password, $address, $email);
$stmt->fetch();
// show the form
renderForm($firstname, $lastname, $username, $password, $address, $email, NULL, $memberID);
$stmt->close();
}
// show an error if the query has an error
else
{
echo "Error: could not prepare SQL statement";
}
}
// if the 'memberID' value is not valmemberID, redirect the user back to the view.php page
else
{
header("Location: view.php");
}
}
}
/*
NEW RECORD
*/
// if the 'memberID' variable is not set in the URL, we must be creating a new record
else
{
// if the form's submit button is clicked, we need to process the form
if (isset($_POST['submit']))
{
// get the form data
$username = htmlentities($_POST['username'], ENT_QUOTES);
$password = htmlentities($_POST['password'], ENT_QUOTES);
$firstname = htmlentities($_POST['firstname'], ENT_QUOTES);
$lastname = htmlentities($_POST['lastname'], ENT_QUOTES);
$address = htmlentities($_POST['address'], ENT_QUOTES);
$email = htmlentities($_POST['email'], ENT_QUOTES);
// check that firstname and lastname are both not empty
if ($username == '' || $password == '' || $firstname == '' || $lastname == '' || $address == '' || $email == '')
{
// if they are empty, show an error message and display the form
$error = 'ERROR: Please fill in all required fields!';
renderForm($username, $password, $firstname, $lastname, $address, $email, $error, $memberID);
}
else
{
// insert the new record into the database
if ($stmt = $mysqli->prepare("INSERT members (username, password, firstname, lastname, address, email) VALUES (?, ?, ?, ?, ?, ?)"))
{
$stmt->bind_param("ss", $username, $password, $firstname, $lastname, $address, $email, $error, $memberID);
$stmt->execute();
$stmt->close();
}
// show an error if the query has an error
else
{
echo "ERROR: Could not prepare SQL statement.";
}
// redirec the user
header("Location: view.php");
}
}
// if the form hasn't been submitted yet, show the form
else
{
renderForm();
}
}
// close the mysqli connection
$mysqli->close();
?>
这是我的查看代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>View Records</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h1>View Records</h1>
<p><b>View All</b> | <a href="view-paginated.php">View Paginated</a></p>
<?php
// connect to the database
include('connection.php');
// get the records from the database
if ($result = $mysqli->query("SELECT * FROM members ORDER BY memberID"))
{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table border='1' cellpadding='10'>";
// set table headers
echo "<tr><th>memberID
</th><th>username
</th><th>password
</th><th>firstname
</th><th>lastname
</th><th>address
</th><th>email
</th><th></th><th></th></tr>";
while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->memberID . "</td>";
echo "<td>" . $row->username . "</td>";
echo "<td>" . $row->password . "</td>";
echo "<td>" . $row->firstname . "</td>";
echo "<td>" . $row->lastname . "</td>";
echo "<td>" . $row->address . "</td>";
echo "<td>" . $row->email . "</td>";
echo "<td><a href='records.php?memberID=" . $row->memberID . "'>Edit</a></td>";
echo "<td><a href='delete.php?memberID=" . $row->memberID . "'>Delete</a></td>";
echo "</tr>";
}
echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}
// show an error if there is an issue with the database query
else
{
echo "Error: " . $mysqli->error;
}
// close database connection
$mysqli->close();
?>
<a href="records.php">Add New Record</a>
</body>
</html>
我很困惑到底是什么导致了这个错误。并且以前从未遇到过。我该如何修复它?谢谢
最佳答案
if ($result = $mysqli->query("SELECT * FROM members ORDER BY memberID"))
请仔细检查此查询。检查表名、字段名小写/大写。之后你的控件应该进入这一行 while ($row = $result->fetch_object())
。
然后您必须能够获取记录列表。如果没有,那么按照我的建议使用以下代码:print "<pre>"; var_dump($row); exit;
在打印单独的行之前。
这只是大小写字母不匹配的愚蠢情况。
创建数据库、表名和字段时始终使用 Snake_cased 表示法。
您可以在核心 PHP 程序中使用驼峰命名法或蛇形命名法。
希望这有帮助!
关于php - 未定义的属性:stdClass::($variablename),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26300194/
这两种语法是否相同:`${variableName}` 和 {variableName} 最佳答案 不。第一个是 JavaScript 的 template literals 根据问题的标签,我假设上
在我的 Xcode Apple 模板中,managedObjectContext 在 AppDelegate.m 中合成如下: @synthesize managedObjectContext = _
Perl 中的 my ($variableName) 和 my $variableName 有什么区别?括号有什么作用? 最佳答案 重要的效果是在声明变量的同时初始化变量: my ($a) = @b;
当您想要初始化参数并且想要分配其中之一时,构造函数中的 super(variable-name); 和 super.variableName = Something; 之间有什么区别它们是父类的变量吗
class Simple { string *data ; //some functions and declaration of some variable,const, d
给定 c++ 关键字 decltype 并用代码示例进行说明: int main(){ int variableName = 0; sizeof(variableName) == si
所以我有一个非常奇怪的问题,在 JavaScript 中调用 console.log 实际上是打印出标签的内容,标签的 id 属性与我传入的变量的名称相同. 这是我的代码:
const data = variableName[0] 有更好的写法吗?我的意思是 variableName[0]。我知道数据放在索引 0 中,但是写一个数字看起来并不专业(至少对我来说),所以如果
这个问题已经有答案了: Why would a JavaScript variable start with a dollar sign? [duplicate] (16 个回答) 已关闭 9 年前。
我在尝试更新特定行的数据库时遇到一些问题,我收到错误消息必须声明标量变量“@lvl”。不太确定我应该做什么。我需要在我的 SQL 语句中声明值吗? private void button1_Click
我是一名尝试学习 C++ 的自学开发人员,我在谷歌上找到了这个练习,并为其编写了代码,尽管我的所有条件都是正确的,但它行不通,当我检查他们的答案时,我发现这行代码- if (!(cin >> gues
我想知道@variablename和variablename之间有什么区别。所有的帮助将不胜感激。 最佳答案 variablename 局部变量 局部变量在存储过程中声明,并且仅在声明它们的 BEGI
我目前正在制作一个表单,该表单接收数据并将其输出到表中,将数据插入表单并按提交按钮后,我收到以下错误: Notice: Undefined property: stdClass::$memberID
当我在 javascript 方法的括号内声明变量时,我会为函数对象提供一个有趣的补充。但是,我实际上无法在函数对象中找到结果逻辑。 [].forEach(towel = function(){con
在 C++ 中,有时会定义一个变量,但不会使用它。这是一个示例 - 用于 COM_INTERFACE_ENTRY_FUNC_BLIND 的函数ATL 宏: HRESULT WINAPI blindQu
我在网上看到了许多使用它的示例脚本。最近,我在 automating TFS 的脚本中看到了它。 : [string] $fields = "Title=$($taskTitle);Descripti
我正在使用 JS、Angular 和 Meteor 来开发一个使用 Youtube api 的 Web 应用程序。在我的 Controller 之一的构造函数中,我按照 youtube api 流程创
我正在使用 React 路由器通过 URL 参数传递 Id 并设置我的变量,如 let { posterId } = useParams(); 这似乎按预期工作,因为我可以在 JSX 中很好地写出它
我在文档中找不到有关此表达式的任何信息。 Ehternaut Re-entrancy task上有如下代码. function withdraw(uint _amount) public { if
我在文档中找不到有关此表达式的任何信息。 Ehternaut Re-entrancy task上有如下代码. function withdraw(uint _amount) public { if
我是一名优秀的程序员,十分优秀!