duanpasi6287
2019-02-02 18:26使用php在html中显示数据库搜索结果?
I'm attempting to create a page, where I can search for case files from my database, however, I can't get my code to work.
I already have pages showing all content of the database and where I can add new content.
I've read guides, tutorials and questions on stackoverflow, but can't find an answer on how to proceed.
I have the following php code in searchcasescript.php
<?php
$servername = "localhost";
$username = "test";
$password = "";
$dbname = "test";
$conn = mysqli_connect($servername, $username, $password, $dbname) or
die("connection failed: " . mysqli_connect_error());
mysqli_select_db($conn, $dbname) or die("something went wrong");
if(isset($_GET["form_submit"]))
{
$journalnummer =$_GET["journalnummer"];
$stmt = $conn->prepare("select * from testcases where journalnummer=? ");
$stmt->bind_param("s",$journalnummer);
$stmt->execute();
$val = $stmt->get_result();
$row_count= $val->num_rows;
if($row_count >0)
{
$result =$val->fetch_assoc();
print_r($result);
}
else{
echo "wrong number";
}
$stmt->close();
$conn->close();
}
?>
and my html:
<div class="container-fluid">
<div class="form-group">
<form action="searchcasescript.php" method="post">
<label for="journalnummer">Journalnummer:</label>
<input type="text" name="journal" class="form-control" required>
<div class="form-group"> <br>
<input type="submit" name="form_submit" class="btn btn-basic" value="Søg">
</form>
I've had different results depending on my changes to the php, but currently I'm getting nothing. Pressing search opens a new, blank page.
What I would like to end up with was being able to enter full or part of a case number and the search results being displayed on the same or a new page.
Can anyone point me in the right direction to read more about this and/or where to proceed with my code?
And apologies, if I've somehow missed the answer in one of the questions here.
UPDATED WITH "LIKE":
$stmt = $conn->prepare("SELECT * FROM straffesager WHERE journalnummer LIKE ?");
$stmt->bind_param("s", '%' . $journal . '%');
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 如何使用ajax和jquery从我的数据库中检索记录?
- javascript
- ajax
- php
- jquery
- mysql
- 1个回答
- 从SQL数据库中搜索和显示数据
- html
- php
- 1个回答
- 使用php在html中显示数据库搜索结果?
- html
- mysql
- php
- 1个回答
- 从不同的数据库表获取搜索结果并显示它们?
- sql
- html
- search
- php
- mysql
- 3个回答
- 将从数据库检索的日期和时间输入到日期时间输入中
- html
- php
- 2个回答