dongyun65343 2014-12-15 06:04
浏览 31

AJAX的成功有限。 有时没有返回任何内容或错误

So far I'm having limited success with AJAX. I have a couple of textboxes I want to fill with values from the database, only nothing is being inserted. Something is happening though which I guess is a good sign, but they're specific to 2 values and they're errors. Nothing seems to be out of the ordinary about these values either. The error report says: Parse error: syntax error, unexpected '}' in getemp.php, but everything lines up correctly and it never happens anywhere else in the database but these values that are back to back. Also since I'm using a table with listboxes no matter which box I choose from it only affects one entry into the table, however I thought the loop would take care of that.

So here's the code I'm trying to use AJAX on:

<? 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>' . "
";}//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>

Here's getemp.php which is being used in the script.

<? 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);
?>

As of right now the only way I can test for a reaction is by having "div" tags surrounding the textbox.

Thank you so much for the help or tips. I've spent so many hours on just this small thing and I can't make much more progress more than this. I've tried everything and looked everywhere for possible solutions, but none seemed to work. Thanks again!

  • 写回答

1条回答 默认 最新

  • douxiangui5011 2014-12-15 17:04
    关注

    In getemp.php:

    print $row['product_cost'] is missing a semicolon.

    Should be:

    print $row['product_cost'];

    Which is why you're seeing the error Parse error: syntax error, unexpected '}' in getemp.php

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号