dreamfly2016 2014-01-29 21:29
浏览 1243
已采纳

从php代码运行sql查询的问题

I have written this code to create a search form and get results from mysql table:

<?
$db_hostname = 'localhost';
$db_username = 'root';
$db_password = '';
$db_database = 'jatc_university_j32';

// Database Connection String
$con = mysql_connect($db_hostname, $db_username, $db_password);
if (!$con) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db($db_database, $con);
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <form action="" method="post">
            Search: <input type="text" name="FieldValue" /><br />
            <input type="submit" value="Submit" />
        </form>
        <?
        if (!empty($_REQUEST['FieldValue'])) {

            $FieldValue = mysql_real_escape_string($_REQUEST['FieldValue']);

            $result = mysqli_query($con, "SELECT Fieldvalue from #__rsform_submission_values WHERE FieldName = 'candidatname'");

            while ($row = mysqli_fetch_array($result)) {
                echo $row;
                echo "<br>";
            }
        }
        ?>
    </body>
</html>

In my database table I have FieldName: candidatname, candidatsurname and FieldValue: John, Wayne etc. I want to search entering a name and return the other details for this candidate Anyway when I run code nothing happens Can you please check if I am doing wrong something because I get the same result in a lot of trials

  • 写回答

2条回答 默认 最新

  • dras2334 2014-01-31 07:07
    关注

    1.Nothing happens beacuse you are using <? ?> for php, but you should use <?php ?>
    2.Your form method is post then you should check variblae like this on form submit:
    if (!isset($_POST['FieldValue']))
    3. "SELECT Fieldvalue from #__rsform_submission_values WHERE FieldName = 'candidatname'"
    instead of candidatename, give the value that you got from the form:

    "SELECT Fieldvalue from #__rsform_submission_values WHERE FieldName = '".$FieldValue."'" <BR>
    

    4. <input type="submit" value="Submit" /> add a name property to this like:

    <input type="submit" value="Submit" name="Submit"/>
    



    and it will work, i tested after applying these changes!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重