在提交数据并插入数据库后,我试图显示用户从 php 程序输入的信息。当我运行它时,我看不到任何结果。我只是得到一个空白页。我在我的代码中找不到错误,希望你们能帮我找到它,这样我就可以修复它并继续前进。这只是我的代码的一部分,我想在我的数据库中插入一些信息,然后显示我插入的内容......
if ( $valid ) {
$lines = file('/home/user/Documents/file.txt');
$uid = trim($lines[0]);
$pw = trim($lines[1]);
$dbserver = trim($lines[2]);
$dbname = trim($lines[3]);
//Connecting to mysql
$link = mysqli_connect($dbserver, $uid, $pw, $dbname);
or die('Could not connect: ' . mysql_error());
//Our SQL Query
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$organization = $_POST['organization'];
$emailaddress = $_POST['emailaddress'];
$phonenumber = $_POST['phonenumber'];
$sql_query = "INSERT INTO table VALUES ('$firstname','$lastname','$organization','$emailaddress','$phonenumber')";
//Run our sql query
$result = mysqli_query($link, $sql_query) or die('query failed'. mysql_error());
// Get all records now in DB
$sql_query = "SELECT * FROM table";
//Run our sql query
$result = mysqli_query($link, $sql_query) or die('query failed'. mysql_error());
//iterate through result printing each record
echo "<br>Names in DB: <br>";
while($row = mysqli_fetch_assoc($result)) {
echo $row['firstname'];
echo $row['lastname'];
echo $row['organization'];
echo $row['emailaddress'];
echo $row['phonenumber'];
echo "<br>";
}
// Free resultset (optional)
mysqli_free_result($result);
//Close the MySQL Link
mysqli_close($link);
}
}