一些错误我遇到了麻烦

时间:2011-09-11 17:07:33

标签: php mysql ajax phpmyadmin

注意:未定义的索引:第20行的C:\ xampp \ htdocs \ Self Exercise \ proj \ order.php中的dValue 注意:未定义的变量:第31行的C:\ xampp \ htdocs \ Self Exercise \ proj \ order.php中的id

注意:未定义的变量:第15行的C:\ xampp \ htdocs \ Self Exercise \ proj \ order.php中的名称

注意:未定义的变量:第17行的C:\ xampp \ htdocs \ Self Exercise \ proj \ order.php中的名称

<?php 

session_start(); 
include("Connection.php");
    if (isset($_POST['submit']))  
    $name = $_POST['customerName'];
    mysql_query("INSERT INTO  `starbucks`.`orders` (
`ID` ,
`NAME` ,
`TOTAL_PRICE` ,
`TOTAL_ITEMS` ,
`TIME`
)
VALUES (
'' ,  '$name',  '', '',NOW())");

$_SESSION['user'] = $name; 

$dTime = time();
$myValue = $_REQUEST['dValue'];
echo "The time is: {$dTime}<br/>
The choice is {$myValue} ";

$sql = "Select * from product where NAME = '{$myValue}'";
 $result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
    $price = $row['PRICE'];
    $id = $row['ID'];
    echo $id;
}
$sql2 ="INSERT INTO `starbucks`.`order_details` (`ID`, `ORDER_ID`, `PRODUCT_ID`, `QTY`) VALUES ('', '', '$id', '1')";

$result2 = mysql_query($sql2);
    ?>

这是我的JS代码

function change_sidebar(dElement) {
    //alert ("oist");
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("tochange").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","order.php?dValue="+dElement.defaultValue,true);
    xmlhttp.send();
}

1 个答案:

答案 0 :(得分:1)

你可能想要

<?php 

session_start(); 
include("Connection.php");
    if (isset($_POST['submit'])){  
    $name = $_POST['customerName'];
    mysql_query("INSERT INTO  `starbucks`.`orders` (
`ID` ,
`NAME` ,
`TOTAL_PRICE` ,
`TOTAL_ITEMS` ,
`TIME`
)
VALUES (
'' ,  '$name',  '', '',NOW())");

$_SESSION['user'] = $name; 
}
$dTime = time();
$myValue = $_REQUEST['dValue'];
echo "The time is: {$dTime}<br/>
The choice is {$myValue} ";

$sql = "Select * from product where NAME = '{$myValue}'";
 $result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
    $price = $row['PRICE'];
    $id = $row['ID'];
    echo $id;
}
$sql2 ="INSERT INTO `starbucks`.`order_details` (`ID`, `ORDER_ID`, `PRODUCT_ID`, `QTY`) VALUES ('', '', '$id', '1')";

$result2 = mysql_query($sql2);
    ?>

请注意此部分if (isset($_POST['submit'])){

(添加括号)