简体   繁体   English

错误的原因可能是什么?

[英]What could be the cause of the error?

I'm writing code to fetch data from the database but it keeps on flagging the error: 我正在编写代码以从数据库中获取数据,但它一直在标记错误:

Notice: Undefined variable: word in C:\\xampp\\htdocs\\Zubby\\admin\\updateword.php on line 7 注意:未定义的变量:第7行的C:\\ xampp \\ htdocs \\ Zubby \\ admin \\ updateword.php中的单词

<?php 

if(isset($_POST['submit']))
    $word = $_POST['word'];

    include '../include/config.php' ;
    $sql = "SELECT FROM word WHERE word = $word";

    $fetch = mysqli_query($connect, $sql);
    if ($fetch) {
        echo $word;
    }else{
        echo "No such word exists in the database";
    }

?>

<form name="word-Add" method="POST" action="">
    <input type="text" name="word" placeholder="  Type the Word "><br><br><br><br>
    <input type="submit" name="submit" id="submit" value="Search Word"><br><br><br><br>

</form>

Try 尝试

<?php 

if(isset($_POST['submit']))
{
    $word = $_POST['word'];

    include '../include/config.php' ;
    $sql = "SELECT * FROM word WHERE word = '".$word."'";

    $fetch = mysqli_query($connect, $sql);
    if ($fetch) {
        echo $word;
    }else{
        echo "No such word exists in the database";
    }
}

?>

<form name="word-Add" method="POST" action="">
    <input type="text" name="word" placeholder="  Type the Word "><br><br><br><br>
    <input type="submit" name="submit" id="submit" value="Search Word"><br><br><br><br>

</form>

Please note though that your code is highly insecure! 请注意,尽管您的代码非常不安全! Never use user input directly in a query! 切勿在查询中直接使用用户输入! Better use prepared statements: http://php.net/manual/en/pdo.prepared-statements.php 更好地使用准备好的语句: http : //php.net/manual/zh/pdo.prepared-statements.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM