Php 如何为用户插入登录数据?
我创建了一个注册页面,但出现了一个错误 注意:未定义变量:中的语句 第35行的D:\xampp\htdocs\123\signup.php 它插入到数据库中,但php文件显示错误。如何将其插入数据库但仍显示错误 注册页面Php 如何为用户插入登录数据?,php,mysql,post,Php,Mysql,Post,我创建了一个注册页面,但出现了一个错误 注意:未定义变量:中的语句 第35行的D:\xampp\htdocs\123\signup.php 它插入到数据库中,但php文件显示错误。如何将其插入数据库但仍显示错误 注册页面 <!doctype html> <html> <head><title>ABU E-ADVISING</title> <link rel="stylesheet" type="text/css" href
<!doctype html>
<html>
<head><title>ABU E-ADVISING</title>
<link rel="stylesheet" type="text/css" href="style.css" \>
</head>
<body>
<?php
$Username1 = $_POST['usr'];
$Pass1 = $_POST['pass'];
$Surname = $_POST['sur'];
$Othernames = $_POST['oname'];
$DOB = $_POST['dob'];
$email = $_POST['email'];
$Tel = $_POST['tel'];
$Add = $_POST['add'];
$Postcode = $_POST['postcode'];
$db = mysql_connect('localhost','root','ROOT');
if (!$db)
{
print "<h1>Unable to Connect to MySQL</h1>";
}
$dbname = 'adv';
$btest = mysql_select_db($dbname);
if (!$btest)
{
print "<h1>Unable to Select the Database</h1>";
}
$statement .= "insert into user (userName, Password, FName, LName, DOB,Email, Tele, Address, PCode) ";
$statement .= "values (";
$statement .= "'".$Username1."', '".$Pass1."',
'".$Surname."','".$Othernames."','".$DOB."','".$Tel."', '".$Add."',
'".$Postcode."','".$email."'";
$statement .= ")";
$result = mysql_query($statement);
if ($result)
{
echo "<br>Author Added: ".$Surname.", ".$Othernames;
} else {
$errno = mysql_errno($db);
if ($errno == '1062') {
echo "<br>Author is already in Table: <br />".$mylastname.",
".$myfirstname;
} else {
echo("<h4>MySQL No: ".mysql_errno($result)."</h4>");
echo("<h4>MySQL Error: ".mysql_error($result)."</h4>");
echo("<h4>SQL: ".$statement."</h4>");
echo("<h4>MySQL Affected Rows: ".mysql_affected_rows($result)."
</h4>");
}
print 'NotAdded';
}
?>
</body>
有人能帮忙吗?这里是您遇到错误的地方:
$statement .= "insert into user (userName, Password, FName, LName, DOB,Email, Tele, Address, PCode) ";
您正在连接以前未声明的字符串变量
应改为:
$statement = "insert into user (userName, Password, FName, LName, DOB,Email, Tele, Address, PCode) ";
更新以下行
$statement .= "insert into user (userName, Password, FName, LName, DOB,Email, Tele, Address, PCode) ";
到
$x.=$y
表示$x=$x$y
因此,如果在此语句之前未定义$x
,您将得到第二个$x
(在=
之后)的通知
不要使用
mysql.*
。它已被弃用且不安全。您试图在第35行的$statement变量之后追加一些内容
$statement未定义,您正在尝试附加到它
试试看
<!doctype html>
<html>
<head>
<title>ABU E-ADVISING</title>
<link rel="stylesheet" type="text/css" href="style.css" \>
</head>
<body>
<?php
$Username1 = $_POST['usr'];
$Pass1 = $_POST['pass'];
$Surname = $_POST['sur'];
$Othernames = $_POST['oname'];
$DOB = $_POST['dob'];
$email = $_POST['email'];
$Tel = $_POST['tel'];
$Add = $_POST['add'];
$Postcode = $_POST['postcode'];
$db = mysql_connect('localhost','root','ROOT');
if (!$db)
{
print "<h1>Unable to Connect to MySQL</h1>";
}
$dbname = 'adv';
$btest = mysql_select_db($dbname);
if (!$btest)
{
print "<h1>Unable to Select the Database</h1>";
}
$statement = "insert into user (userName, Password, FName, LName, DOB,Email, Tele, Address, PCode) ";
$statement .= "values (";
$statement .= "'".$Username1."', '".$Pass1."', '".$Surname."','".$Othernames."','".$DOB."','".$Tel."', '".$Add."', '".$Postcode."','".$email."'";
$statement .= ")";
$result = mysql_query($statement);
if ($result)
{
echo "<br>Author Added: ".$Surname.", ".$Othernames;
} else {
$errno = mysql_errno($db);
if ($errno == '1062') {
echo "<br>Author is already in Table: <br />".$mylastname.", ".$myfirstname;
} else {
echo("<h4>MySQL No: ".mysql_errno($result)."</h4>");
echo("<h4>MySQL Error: ".mysql_error($result)."</h4>");
echo("<h4>SQL: ".$statement."</h4>");
echo("<h4>MySQL Affected Rows: ".mysql_affected_rows($result)."</h4>");
}
print 'NotAdded';
}
?>
</body>
阿布电子咨询公司
请mysql.*
函数已经过时,而且不安全。使用或代替。另外,你完全可以使用mysql。停止使用mysql,我知道这与你的问题无关,但这对未来会更好,避免使用mysql,使用mysqli、pdo或任何其他。
$statement = "insert into user (userName, Password, FName, LName, DOB,Email, Tele, Address, PCode) ";
<!doctype html>
<html>
<head>
<title>ABU E-ADVISING</title>
<link rel="stylesheet" type="text/css" href="style.css" \>
</head>
<body>
<?php
$Username1 = $_POST['usr'];
$Pass1 = $_POST['pass'];
$Surname = $_POST['sur'];
$Othernames = $_POST['oname'];
$DOB = $_POST['dob'];
$email = $_POST['email'];
$Tel = $_POST['tel'];
$Add = $_POST['add'];
$Postcode = $_POST['postcode'];
$db = mysql_connect('localhost','root','ROOT');
if (!$db)
{
print "<h1>Unable to Connect to MySQL</h1>";
}
$dbname = 'adv';
$btest = mysql_select_db($dbname);
if (!$btest)
{
print "<h1>Unable to Select the Database</h1>";
}
$statement = "insert into user (userName, Password, FName, LName, DOB,Email, Tele, Address, PCode) ";
$statement .= "values (";
$statement .= "'".$Username1."', '".$Pass1."', '".$Surname."','".$Othernames."','".$DOB."','".$Tel."', '".$Add."', '".$Postcode."','".$email."'";
$statement .= ")";
$result = mysql_query($statement);
if ($result)
{
echo "<br>Author Added: ".$Surname.", ".$Othernames;
} else {
$errno = mysql_errno($db);
if ($errno == '1062') {
echo "<br>Author is already in Table: <br />".$mylastname.", ".$myfirstname;
} else {
echo("<h4>MySQL No: ".mysql_errno($result)."</h4>");
echo("<h4>MySQL Error: ".mysql_error($result)."</h4>");
echo("<h4>SQL: ".$statement."</h4>");
echo("<h4>MySQL Affected Rows: ".mysql_affected_rows($result)."</h4>");
}
print 'NotAdded';
}
?>
</body>
<html>
<head>
</head>
<body>
<?php
if($bla == $bla) {
echo "bla = bla";
}
?>
</body>
</html>