我为项目调整了以下代码。 “updateTempDataClient.php只是将选择插入到SQL数据库中。它可以正常工作,但有一个例外。如果表的第一列在字段中有除数字以外的任何内容,则此函数将不会运行。
> <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>
这是INSERT查询。该数据库有3列。一个是id(int),另一个是客户端和供应商。两者都是varchar(50)。我尝试向脚本添加警报。当仅进行数字选择时,它将弹出。但是,如果我点击任何带有字母的内容,警报就不会触发。
<?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 );
?>