我使用000webhost为我的数据库运行我的代码和phpmyadmin。我试图这样做,当我找到一个名字时,它会在数据库中给我这个名字下的名字和密码。
这是错误:
解析错误:语法错误,意外'>'在第51行的/storage/h11/920/1783920/public_html/search.php
这是我的HTML:
<!DOCTYPE html>
<html>
<head>
<title>Search</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<form action="search.php" method="GET">
<input type="text" name="query" />
<input type="submit" value="Search" />
</form>
</body>
</html>
这是我的php:
<?php
mysql_connect("localhost", "id1783920_123456", "") or die("Error connecting to database: ".mysql_error());
/* The Third "" is the password spot and I don't want to put it. It's not the problem*/
// LINE 10
mysql_select_db("id1783920_mydb") or die(mysql_error());
?>
<!DOCTYPE html>
<html>
<head>
<title>Search results</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$query = $_GET['query'];
$min_length = 1;
// LINE 30
if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT * FROM Signup
WHERE (`username`='$query') OR (`password`='$query') or die(mysql_error());
// LINE 45
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
echo "<p><h3>".$results['username']."</h3>".$results['password']."</p>";
}
}
else{ // if there is no matching rows do following
echo "No results";
}
}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;
}
?>
</body>
</html>
任何帮助都会受到极大的欢迎。感谢
(另一个错误显示:致命错误:未捕获错误:在/storage/h11/920/1783920/public_html/search.php:37中调用未定义函数mysql_query()堆栈跟踪:#0 {main}抛出/第37行存储/ h11 / 920/1783920 / public_html / search.php
答案 0 :(得分:1)
你应该替换
$raw_results = mysql_query("SELECT * FROM Signup
WHERE (`username`='$query') OR (`password`='$query') or die(mysql_error());
与
$raw_results = mysql_query("SELECT * FROM Signup
WHERE (`username`='$query') OR (`password`='$query')") or die(mysql_error());
当你使用PHP7时,你应该摆脱mysql_函数。它们自v 5.5起被弃用,并在PHP7中被删除。请改用mysqli。
答案 1 :(得分:0)
查询字符串必须在引号中,并且没有结束引号。改变它:
$raw_results = mysql_query("SELECT * FROM Signup
WHERE (`username`='$query') OR (`password`='$query')") or die(mysql_error();