Im new to PHP MySQL. Im developing a songbook site.
我是PHP MySQL新手。我正在开发一个歌集网站。
I'm trying to pull data in a database from the ID in the URL site/publicsong.php?id=12
.
我正在尝试从URL站点/ publicsong.php?id = 12中的ID中提取数据库中的数据。
<?php
// Create connection
$conn = new mysqli($servername = "localhost";$username = "dansdlpe_dan";$password = "g+GbMr}DU4E@";$db_name = "dansdlpe_lyrics";);
// Check connection
$db_name = "dansdlpe_lyrics";
mysqli_select_db($conn,$db_name);
$id = $_GET['id'];
$id = mysqli__real_escape_string($conn,$id);
$query = "SELECT * FROM `lyrics_a` WHERE `id`='" . $id . "'";
$result = mysqli__query($conn,$query);
echo $row['id']; while($row = mysqli__fetch_array( $result )) {
echo "<br><br>";
echo $row['eng_title'];
echo $row['eng_lyrics'];
echo $row['alphabet'];
}
?>
I changed mysql_ to mysqli_ and added $conn.
我将mysql_更改为mysqli_并添加了$ conn。
And still i result is blank. Please help guys. Thanks in advance.
我的结果仍然是空白。请帮帮我们提前致谢。
3 个解决方案
#1
4
So I will stick to what you already have with some fixes.
所以我会坚持你已经有的一些修复。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$servername = "localhost";
$username = "xxxx";
$password = "xxxxxx";
$db_name = "xxxxxxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $db_name);
// Check connection
if ($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
$id = $_GET['id'];
$id = mysqli_real_escape_string($conn,$id);
$query = "SELECT * FROM `lyrics_a` WHERE `id`='" . $id . "'";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><br>";
echo $row['id'];
echo $row['eng_title'];
echo $row['eng_lyrics'];
echo $row['alphabet'];
}
?>
#2
-1
Try this:
尝试这个:
<?php
$servername = "localhost";
$username = "";
$password = "";
$db_name = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $db_name);
// Check connection
mysql_select_db($db_name);
$id = $_GET['id'];
$id = mysql_real_escape_string($id);
$query = "SELECT * FROM `lyrics` WHERE `id`='" . $id . "'";
$result = mysql_query($query);
while($row = mysql_fetch_array( $result )) {
echo "<br><br>";
echo $row['title'];
echo $row['content'];
}
?>
#3
-1
No need to use the id as a string,
you can use like : id=" . $id;
不需要将id用作字符串,你可以使用like:id =“。$ id;
#1
4
So I will stick to what you already have with some fixes.
所以我会坚持你已经有的一些修复。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$servername = "localhost";
$username = "xxxx";
$password = "xxxxxx";
$db_name = "xxxxxxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $db_name);
// Check connection
if ($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
$id = $_GET['id'];
$id = mysqli_real_escape_string($conn,$id);
$query = "SELECT * FROM `lyrics_a` WHERE `id`='" . $id . "'";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><br>";
echo $row['id'];
echo $row['eng_title'];
echo $row['eng_lyrics'];
echo $row['alphabet'];
}
?>
#2
-1
Try this:
尝试这个:
<?php
$servername = "localhost";
$username = "";
$password = "";
$db_name = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $db_name);
// Check connection
mysql_select_db($db_name);
$id = $_GET['id'];
$id = mysql_real_escape_string($id);
$query = "SELECT * FROM `lyrics` WHERE `id`='" . $id . "'";
$result = mysql_query($query);
while($row = mysql_fetch_array( $result )) {
echo "<br><br>";
echo $row['title'];
echo $row['content'];
}
?>
#3
-1
No need to use the id as a string,
you can use like : id=" . $id;
不需要将id用作字符串,你可以使用like:id =“。$ id;