doushi3189 2015-06-17 19:14
浏览 21
已采纳

搜索barre php + mysql“找不到页面”

I've a small issue with this search barre : When I search for the Author or the Session, the search is succesful and everything is fine. But if I search anything in the last box (the Name one) my page is redirected to the site homepage. (with "Page not found" as tab name) I'm really new to php. (and mysql) Is that because I don't give an "action" to the form ?

   <form method="post" action="">
    <table>
    <tbody>

    <tr>
    <td>Author :</td>
    <td><input name="a" type="text" /></td>
    <td>Session :</td>
    <td><input name="nos" type="text" /></td>
    <td>Publication :</td>
    <td><input name="name" type="text" /></td>

    </tr>
    <td>
    <input type="submit" value="Search" class="button" />
    </td>
    </label>
    </tbody>

    </table>
    </form>
    <?php

    $author = '%'.$_REQUEST['a'].'%'; 
    $nos = '%'.$_REQUEST['nos'].'%'; 
    $name = '%'.$_REQUEST['name'].'%'; 



    $mysqli = new mysqli('localhost', 'mydb', 'Prettygoodpwd', 'the table');
    if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
    }


    $sql = 'SELECT AuthorP, NameP
FROM wp_publications
WHERE AuthorP LIKE ?
AND NameOfSessionP LIKE ?
AND NameP LIKE ? ';

    if($stmt = $mysqli->prepare($sql))
    {
        $stmt->bind_param('sss', $author, $nos, $name);
        if($stmt->execute())
        {
            $stmt->store_result();
            if($stmt->num_rows >= 1)
            {
                $resultSet = array();

                $stmt->bind_result($au, $na);
                while($stmt->fetch())
                {
                    $resultSet[] = array('Author' => $au, 'Name' => $na);
                }
            }
        }else{

            echo $stmt->error;
        }
    }else{
        echo $mysqli->error;
    }
    if(is_array($resultSet))
    {
        print_r($resultSet);
    }

    $mysqli -> close();
    ?>

I tried to remove the last box from the search form : "publication". I expected the problem to be on the "name" box afterward but no. The two first search box work still fine.

  • 写回答

1条回答 默认 最新

  • dongzhuandian3292 2015-06-17 19:38
    关注

    Seems like in <td><input name="name" type="text" /></td> name isn't a appropriate variable name.... When i'm changing to nam it works.

    I'm sorry for writing an other useless question... But it's like each time the same... I'm stuck for hours trying to correct my stuff, I surrender and ask here. And the problem is solved in few minutes.

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

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号