PHP Echo使文件添加html结束注释破折号
当我试图连接到数据库以搜索用户名和密码时,似乎对任何选项运行“echo”命令都会杀死整个页面,而不会执行其余代码 这是我的PHP文件:PHP Echo使文件添加html结束注释破折号,php,html,mysql,Php,Html,Mysql,当我试图连接到数据库以搜索用户名和密码时,似乎对任何选项运行“echo”命令都会杀死整个页面,而不会执行其余代码 这是我的PHP文件: <html> <body> <?php //setting variables for connecting to database error_reporting(0); $host = 'localhost'; $username = 'root'; $password =
<html>
<body>
<?php
//setting variables for connecting to database
error_reporting(0);
$host = 'localhost';
$username = 'root';
$password = '';
$db = 'aquamandb';
date_default_timezone_set('America/Chicago');
//connecting to the database
$connect = new mysqli($host,$username, $password, $db) or die("Unable to connect");
//getting the username, user type, and password for sanitizing
$_US_username = $_GET['username'];
$_US_password = $_GET['password'];
//sanitize the variable to remove SQL statements that could drop the database potentially.
$username = mysql_real_escape_string($_US_username);
$password = mysql_real_escape_string($_US_password);
$sql = "SELECT * FROM user WHERE username = '$username' AND password = '$password'";
$result = mysql_query($sql);
//Send alert to page if there is not a match found between username password and user type
if(!$result)
{
die('Could not get data: ' . mysql_error());
}
else
{
$row = mysql_fetch_array($result);
if($row['type'] == 1)
{
echo '<form name = "auto" action = "../admin-dash.html" method = "POST">';
}
else if($row['type'] == 2)
{
echo '<form name = "auto" action = "../sigadmin-dash.html" method = "POST">';
} else
{
echo '<form name = "auto" action = "../sigusr-dash.html" method = "POST">';
}
}
?>
第34行末尾缺少分号:
$row = mysql_fetch_array($result);
$row=mysql\u fetch\u数组($result)
缺少一个
正在破坏您的脚本不确定为什么不将表单放在html中,并在php中调用$\u POST或$GET,这样会更简单。我看到的错误就在第37行之前,你忘记了你的(“;”),但即使修复了它也不打印表单,我甚至不认为它正在处理你的表单,如果但不确定。另外,您应该使用准备好的语句而不是mysql\u real\u escape\u字符串,还应该使用mysqli进行初始连接,然后在转义时使用mysql。试试这样的:
<!doctype html>
<html>
<body>
<form action = "whatever.php method = "post">
<input type = "email" name = "email" />
<input type = "password" name = "password" />
<input type = "submit" name = "submit" value = "insert" />
</form>
<?php
// connect to the server
$conn = new mysqli('localhost', 'usename', 'password', 'database');
// check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
} else {
echo "your connection was successful";
}
if($_POST && isset($_POST['submit'], $_POST['name'] )) {
$email = ( $_POST["email"]);
$pass = ($_POST["password"]);
$query = mysqli_prepare($conn, "SELECT pass FROM database
WHERE email = ? ");
mysqli_stmt_bind_param($query,'s', $email );
mysqli_stmt_execute($query);
mysqli_stmt_bind_result($query, $email);
if(mysqli_stmt_fetch($query)) {
echo "<br />";
echo "SUCCESS at query";
if (password_verify($input, $id)) {
echo "matching pass" . header("Location: inserh.php");
} else{
echo "not a match";
}
}
mysqli_stmt_close($query);
}
mysqli_close($conn);
我不知道对用户名和密码使用GET,为了调试问题,我更改了GET。这是一个需要有最小可验证示例的要求。可以删除带有代码的其他地方的链接,留下一个没有代码的问题。这被称为“链接腐烂”。这样,你的问题就没用了。请将代码移到问题中,并解释错误在代码中的位置。IDE可以很容易地告诉您忘记分号的位置。@frz3993不正确,这并没有解决问题,也没有改变它。仍然没有解决问题。它正在打印表单,但是,您必须在其中添加表单元素(例如提交和输入按钮)并关闭表单,否则将无法显示任何内容谢谢您RMD,我忘了我已删除onload=“document.auto.submit()”因此,它会自动提交表单。但在重定向到正确页面时仍然存在问题,if语句的格式是否正确?若要查找与查询返回内容匹配的名为type的列,请执行以下操作:[userID][username][type][password]是列的布局,我正在尝试查看类型是否与某个匹配以重新更正到正确的页面这不是问题所在,也没有修复发生的错误。您正在运行什么PH版本?PHP版本:7.0.4所以您需要使用mysqli_query而不是mysqli_query和mysqli_fetch_数组。旧的mysql扩展不支持ted在PHP7中不再出现了,但我仍然遇到了同样的问题,在第37行的echo语句末尾添加了“-”