我在這裏是新的,我真的越來越絕望,嘗試和修復至少三天我的代碼,它根本不工作。 我有一個本地服務器,它可以工作(在我的macbook上使用Mamp)我在我的「hexameter」數據庫中編輯了一個名爲「forms」的小表。初學php代碼不工作在
Here`s我的代碼:
connection.php
<?php
$servername = "";
$username = "";
$password = "";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
連接不工作!
輸入:
<!DOCTYPE html>
<html>
<body>
<form action="http://localhost:8888/index.php" method="GET">
Hexameter: <input type="text" name="Hexameter"><br>
<input type="submit" name"Eingabe">
</form>
</body>
</html>
的index.php:
<!DOCTYPE html PUBLIC>
<html >
<head>
<title>Search results</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<?php
$query = $_GET['Hexameter'];
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM forms
WHERE `text` LIKE '%".$query."%')" or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "<p><h3>".$results['title']."</h3>".$results['text']."
</p>";
}
} else{
echo "No results";
}
}
?>
</body>
</html>
我總是得到index.php的,但有沒有任何顯示。 如果有人能幫忙,我們真的會很高興!
這是關於什麼的? –
'mysql_real_escape_string' nope。你用'mysqli'打開連接。你在混合API。切換到PDO,以免混淆mysql_和mysqli_。 – developerwjk
@developerwjk - 我從字面上打算輸入。你在我面前。 –