dqrzot2791 2015-06-07 11:19
浏览 43
已采纳

用MySQL搜索PHP错误[重复]

This question already has an answer here:

I tried to create a PHP search (searching in a MySQL DB). The Code should post the search results down below the form. So I wrote the following:

<?php
Session_Start();

$username=$_SESSION['username'];
$password=$_SESSION['password'];
$dbname=$_SESSION['dbname'];
$servername=$_SESSION['hostname'];

/*connection test...*/
$conn = new mysqli($servername, $username, $password, $dbname);    
if(!$conn){
    header("Location: LogIn.php");
    }  
echo "verbindung erfolgreich!";

/*tabellen suche...*/
$output = '';
if (isset($_POST['search'])) {
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);

    $query = mysql_query("SELECT * FROM patientenstamm WHERE Vorname   LIKE '%$searchq%' OR Nachname LIKE '%$searchq%'");
    $count = mysql_num_rows($query);
    if($count == 0){
        $output = 'Keine Ergebnisse gefunden!';
    }else{
    while($row = mysql_fetch_array($query)) {
        $Vname = $row['Vorname'];
        $Nname = $row['Nachname'];
        $id = $row['id'];

        $output .= '<div>'.$Vname.' '.$Nname.'</div>';
    }
}

/* tabelleaufruf...*/
$abfrage = "SELECT * FROM patientenstamm" ;
$ergebnis = mysqli_query($conn, $abfrage);
?>

and HTML:

<!DOCTYPE html>
<html>
    <head>
        <title> Suchen </title>
    </head>
    <body>
        <form method="POST" action="auflistenPatient.php">
            <input type="text" id="search" name="search" placeholder="search">
            <input type="submit" value="suchen">
        </form>
        <?php echo $output;?>
    </body>
</html>

Now I'm getting an error:

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\HTML\Rechnungs Programm\auflistenPatient.php on line 55

Does anybody know whats wrong here?

Thanks!

</div>
  • 写回答

1条回答 默认 最新

  • dongou4052 2015-06-07 11:24
    关注

    You're missing a closing curly brace here:

    if($count == 0){
        $output = 'Keine Ergebnisse gefunden!';
    }else{
    while($row = mysql_fetch_array($query)) {
        $Vname = $row['Vorname'];
        $Nname = $row['Nachname'];
        $id = $row['id'];
    
        $output .= '<div>'.$Vname.' '.$Nname.'</div>';
    }
    

    Notice how you close the while, but you never close the else. Just add a closing curly brace wherever you logically intended to close your code blocks. Making consistent use of whitespace will make these errors much easier to find.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来