到目前为止,我在AJAX方面的成功有限。我有几个文本框要填充数据库中的值,只插入任何内容。虽然事情正在发生,但我认为这是一个好兆头,但它们具体针对2个值并且它们是错误的。关于这些价值观似乎也没有什么特别的。错误报告说:解析错误:语法错误,意外'}'在getemp.php中,但是所有内容都正确排列,它永远不会发生在数据库中的任何其他地方,但这些值是背靠背的。此外,由于我使用带有列表框的表,无论我选择哪个框,它只影响表中的一个条目,但我认为循环会处理这个。
所以这里是我尝试使用AJAX的代码:
<? require_once("connect_to_DB.php"); // inserts contents of this file here ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>New Order Form/Edit Order Form</title>
<link rel="stylesheet" href="hw2.css"/>
<?
connectDB();
session_start();?>
<script src="validation.js"></script>
<script src="jquery.js"></script>
<script type="text/javascript">
function showUser(str){
if(str==""){
$("#txtHint").html("");
return;
}else{
$("#txtHint").load("getemp.php?q="+str);
};
}
</script>
</head>
<body>
<?
include ('navbar_func.php');
echo navbar();
// Establish a connection with the data source, and define the SQL
$strSQL = "SELECT product_name FROM product";
$rs = mysqli_query($db, $strSQL) or die("Error in SQL statement: " . mysqli_error());
$row = mysqli_fetch_array($rs);
// Establish a connection with the data source, and define the SQL for the orders
$newID = 101;
$rndSQL = "Select order_id FROM salesorder WHERE order_id = ".$newID;
while(mysqli_num_rows(mysqli_query($db, $rndSQL)) > 0){
echo "<script>console.log($newID)</script>";
$newID++;
$rndSQL = "Select order_id FROM salesorder WHERE order_id =". $newID;
}
?>
<?$today = date("F j, Y");?>
<form name="orderform" method="post" action="new_order_result.php" onsubmit="return validate_order()">
<table>
<tr>
<td>Order Number:</td>
<td><label id="order" type="text" name="ordernumber" value="<?=$newID?>"><?=$newID?></label>
</td>
<td>Order Date:</td>
<td><label type="text" name="orderdate" value="<?=$today?>"/><?=$today?></label></td>
</tr>
<tr>
<td> Customer:</td>
<td><input id="customer"type="text" name="customer" value=""/></td>
</tr>
<tr>
<td>Sale Agent:</td>
<td><input id="salesagent" type="text" name="salesagent" value=""/></td>
<td>Order Status:</td>
<td><input id="orderstatus" type="text" name="orderstatus" value=""/></td>
</tr>
</table>
<table border = "1">
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<?$rs = mysqli_query($db, $strSQL) or die("Error in SQL statement: " . mysqli_error());?>
<?for($x=0; $x <= 19; $x++)
//just needs to post quantity not which
{?>
<tr>
<td>
<select name="P<?=$x?>" onchange="showUser(this.value)">
<option value="">Choose the product you'd like to purchase:</option>
<?while($row = mysqli_fetch_array($rs)){?>
<?print '<option value="'.$row[0].'">' . $row[0] . '</option>' . "\n";}//This is uses the datebase values?>
</select>
</td>
<td>
<div id="txtHint"><input type="text" name="M<?=$x?>" value="0"></input></div>
</td>
<td><select name="Q<?=$x?>" value="$row[1]">
<?for($i = 0; $i < 10; $i++){
print "<option value=$i>$i</option>";}//This uses the datebase values?>
</select></td>
</tr>
<? $rs = mysqli_query($db, $strSQL); //resets pointer in database.?>
<?}?>
</table>
<center>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</center>
</form>
</body>
</html>
这是在脚本中使用的getemp.php。
<? require_once("connect_to_DB.php"); // connect to furniture database
// ###################### retrieve data from database #################
connectDB();
$sql = "SELECT * FROM product WHERE product_name = " . $_GET["q"];
$result = mysqli_query($db, $sql) or die("SQL error: " . mysqli_error());
// ###############################################################
while($row = mysqli_fetch_array($result))
{
print $row['product_cost']
}
mysqli_close($db);
?>
截至目前,我可以测试反应的唯一方法是使用&#34; div&#34;文本框周围的标签。
非常感谢你的帮助或提示。我花了这么多时间来处理这件小事,我不能比这更进步。我已经尝试了所有方面并且到处寻找可能的解决方案,但似乎都没有。再次感谢!
答案 0 :(得分:0)
在getemp.php中:
print $row['product_cost']
缺少分号。
应该是:
print $row['product_cost'];
这就是您看到错误Parse error: syntax error, unexpected '}' in getemp.php