duanke6057 2014-12-18 11:59
浏览 34

尽管查询查找记录,为什么mysql数据不会拉入形式,查找值是否必须是唯一的?

I have the following code which is supposed to pull data from mysql database if search box value matches row & attribute Client_Name in MYSQL.

please see http://www.recruitingblt.comli.com/add-new-sales-record.html.

When a match is found, the form reverts back (try James Dean) and does not autopopulate the fields I want it to (for now I am just asking for Client_Address, Client_Phone & Attn_Email1 to test). These are the names of columns in mysql table bltrecruiting).

I am thinking that maybe Client_Name needs to be unique, say I have company Microsoft, and there is more than one row, will the query not be able to pull through address, phone etc despite being the same for all Microsoft records? Does the look up value need to be unique?

<?php
$regnum = $_GET['regnum']; 
//////////regnum is named box at top of form page (Client Name Box) 

//////Connection which seems to work fine 
$db_host = 'mysql6.000webhost.com';
$db_username = '********';
$db_password = '********';
$db_name = 'a8748341_bltrec';

mysql_connect( $db_host, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_name); 

////// Check for the Client Name which is a field Client_Name in the database - Should Client_Name be unique? 

$result = mysql_query("SELECT * FROM bltrecruiting WHERE Client_Name='$regnum'") or
die(mysql_error());
$row = mysql_fetch_array( $result );
if (empty($row[Client_Name]))
{
        echo "No previous record of Client: $regnum <br>";
        echo "Please try again <br>" ?>

        <div id=regcon>
            <FORM NAME = "reg" action=database.php>
            <div style=width:150px; float:left; display:inline-block; font-family: Verdana;
            font-size: 12px; padding-left:13px;> Client Name: </div>

            <input type="text" id="textbox" name="regnum" size="20"/>
            <input name="Submit"  type="submit" value="Get Form"/>

            </form>
        </div>
 }
else
{
///////// Get the fields from the database
    $address = $row['Client_Address'];
    $phonenumber = $row['Client_Phone'];
    $name= $row['Attn_Name1'];
    //add your additional fields here


    echo '<script    type="text/javascript"src="http://form.jotform.com/jsform/43438603456356?"Client_Name='.$regnum.'&Client_Address='.$address.'&Client_Phone='.$phonenumber.'&Attn_Name1='.$name.'"></script>';


}
?>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • doupin2013 2014-12-18 15:20
    关注

    i noticed that your empty($row[Client_Name]) did not have quotes around it but I tested the below code. Even tho you might have more than 1 row, your $row variable will have data for row 1 in its index (you are not doing a while loop thru the mysql_fetch_array).

    if (!is_array($row) && empty($row['Client_Name']))
        {
                echo "No previous record of Client: $regnum <br>";
                echo "Please try again <br>";
        ?>
    
            <div id=regcon>
                <FORM NAME = "reg" action=database.php>
                <div style=width:150px; float:left; display:inline-block; font-family: Verdana;
                font-size: 12px; padding-left:13px;> Client Name: </div>
    
                <input type="text" id="textbox" name="regnum" size="20"/>
                <input name="Submit"  type="submit" value="Get Form"/>
    
                </form>
            </div>
    <?php
     }
    else
    {
        ///////// Get the fields from the database
        $address = $row['Client_Address'];
        $phonenumber = $row['Client_Phone'];
        $name= $row['Attn_Name1'];
        //add your additional fields here
    
        echo '<script type="text/javascript"src="http://form.jotform.com/jsform/43438603456356?"Client_Name='.$regnum.'&Client_Address='.$address.'&Client_Phone='.$phonenumber.'&Attn_Name1='.$name.'"></script>';
    }
    

    i did a test locally and faked some values into the javascript URL - should they appear in that form?

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?