dregduc63699 2017-02-24 15:21
浏览 29

Javascript函数仅在PHP表包含数字(无字母)时才起作用

I adapted the following code for a project. The "updateTempDataClient.php simply INSERTS the selection into an SQL database. It works fine with one exception. If the table's first column has anything other than numbers in the field this function will not run.

> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<?php
echo "<table border='2'>";
echo "<tr><th>ClientNum</th><th>Company</th><th>Address</th><th>City</th><th>State</th></tr>";


    while($row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_BOTH)) 


{
    $resultArray[] = $row;

        echo "<tr>";
        echo "<td onClick='selection(" . $row[0] . ")'><a href><font color=blue><u>" . $row[0] . "</a></font></u></td>";
        echo "<td>" . $row[1] . "</td>";
        echo "<td>" . $row[2] . "</td>";
        echo "<td>" . $row[3] . "</td>";
        echo "<td>" . $row[4] . "</td>";
        //echo "<td>" . $row[5] . "</td>";
    //echo "<td>" . $row[6] . "</td>";
    echo "</tr>";

}


echo "</table>";

?>

<script>
function selection(myselection){

        $.post("updateTempDataClient.php?tabledata="+myselection,
            function(data){           


    }); 

}



</script>

Here is the INSERT query. The database has 3 columns. One is for id (int) the other 2 are client and vendor. Both are varchar(50). I tried adding an alert to the script. It will popup when a numbers only selection is made. However, if I click on anything with a letter in it the alert won't fire.

    <?php

$serverName = "palmbeach\sqlexpress";
$connectionInfo = array( "Database"=>"mylocaldb", "UID"=>"username", "PWD"=>"******");

$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
    //echo "Connected OK.";
}else{
    echo "Connection fail.<br />";
    die( print_r( sqlsrv_errors(), true));
}


$test = urldecode($_GET[‘tabledata]);


$sql = "UPDATE TempData SET client='$test' WHERE id=1";



$stmt = sqlsrv_query( $conn, $sql);

if( $stmt === false ) {
     die( print_r( sqlsrv_errors(), true));
}

// Close the connection.
sqlsrv_close( $conn );


?>      
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch