无法使用MySQLi从数据库获取数据

无法使用MySQLi从数据库获取数据

本文介绍了无法使用MySQLi从数据库获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个文件,在index.html中,用户将输入一个URL,当他点击提交时,URL将用一个ID登录到数据库中,用户也可以获得该ID。现在问题是我能够将URL放入数据库中,但我无法获取已记录的ID。我得到存储在数据库中的所有ID!但我只想要用户在index.thml中输入的URL的ID ......请帮助我!

I have 2 files, in index.html the user will input a URL and when he clicks on submit then the URL would be logged into the database with an ID and also the user would get that id. Now the problem is that I am able to put the URL in DB but I am not able to fetch the ID to which it has been logged. I am getting all the ID that are stored in the DB! but I just want the ID of the URL that the user has put in index.thml ...Please help me out!

以下是index.html的代码

Following is index.html's code

<form action="process.php" method="post">
URL(with "http://"): <input type="text" name="url">
<input type="submit">
</form>

,这是process.php的代码

and this is process.php's code

    <?php
$con=mysqli_connect("localhost","root","","url");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$url = $_POST[url];
$sql="INSERT INTO url (url) VALUES('$url')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "something";
echo '<br><br>';

$result = mysqli_query($con,"SELECT id FROM url WHERE url='$url'");
while($ids = mysqli_fetch_array($result))
  {
  echo "something";
  echo 'http://localhost/redirect/' . $ids['id'];
  }


mysqli_close($con);
?>


推荐答案

$url = $_POST[url];

您遗漏了数组键的单引号。

You missed single quotes around array key.

右表格

$url = $_POST['url'];

这篇关于无法使用MySQLi从数据库获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 12:32