2019-02-02 18:26


  • php
  • html
  • mysql

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


$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");

    $journalnummer =$_GET["journalnummer"];

    $stmt = $conn->prepare("select * from testcases where journalnummer=? ");


    $val = $stmt->get_result();
    $row_count= $val->num_rows;

    if($row_count >0)
        $result =$val->fetch_assoc();

        echo "wrong number";



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">

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.


$stmt = $conn->prepare("SELECT * FROM straffesager WHERE journalnummer LIKE ?");

        $stmt->bind_param("s", '%' . $journal . '%');
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享