获取了ajax值但无法存储

时间:2015-05-11 13:04:52

标签: php ajax

当我在bill.php中选择一些东西时,它调用ajax并从get user.php获取值然后它在bill.php页面上显示内容但是如何在bill.php页面中的变量中保存这些值以便进一步在php中使用

<?php
include('db.php');
?>
<html>
<head>
<style>
table, tr th{
    border: green;
}

th {

}
</style>


<script type="text/javascript">
function updatesum()
{
document.form.sum.value =  (document.form.sum2.value -0);
document.form.sumone.value = (document.form.sum3.value -0) ;
document.form.sumtotal.value = (document.form.sum.value -0) * (document.form.sumone.value -0);
document.form.sumtotalgiven.value=(document.form.sumtotalmoney.value -0) - (document.form.sumtotal.value -0);

}
</script>
<script>
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
         //document.getElementById("txtHin").innerHTML = "";
        return;
    } else { 
        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("txtHint").innerHTML = xmlhttp.responseText;
                //document.getElementById("txtHin").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.send();
    }
}
</script>
<script>
function shoUser(str) {
    if (str == "") {
        document.getElementById("txtHin").innerHTML = "";
        return;
    } else { 
        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("txtHin").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.send();
    }
}
</script>
</head>
<body bgcolor="#C7CBE1">
<form method="get" name="form">
<table border="0" bordercolor="#D83E41">




   <tr>                     
     <td>&nbsp;&nbsp;&nbsp;&nbsp; medicine &nbsp;&nbsp;&nbsp;&nbsp; </td>


            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; price&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   batchno
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expire date</td>
             <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

               quantity</td>
               <td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               Total </td>





                        </tr>



<tr>




                   <td>
                        <?php
                            $qry="select * from inventory";
                            $rs=mysql_query($qry);
                        ?>
                        <select name="user" onchange="showUser(this.value)">
                            <option value=>selet medicine name</option> 

                        <?php
                            while($rw=mysql_fetch_array($rs)){

                        ?>
                            <option value="<?php echo $rw['id']?>"><?php echo $rw['medicine']?></option>    
                        <?php

                            }
                        ?>
                        </select>


               </td>
               <td>
                  <div id="txtHint">


                        </div>
               </td>


             <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


              <input type="text" name="sum2" style="width: 70px" onChange="updatesum()" ></td>

             <td>
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input name="sum" readonly " style="width: 70px"></td>



</tr>
<tr>




                   <td>
                        <?php
                            $qry="select * from inventory";
                            $rs=mysql_query($qry);
                        ?>
                        <select name="user" onchange="shoUser(this.value)">
                            <option value=>selet medicine name</option> 

                        <?php
                            while($rw=mysql_fetch_array($rs)){

                        ?>
                            <option value="<?php echo $rw['id']?>"><?php echo $rw['medicine']?></option>    
                        <?php

                            }
                        ?>
                        </select>


               </td>
               <td>
                  <div id="txtHin">


                        </div>
               </td>
               <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


              <input type="text" name="sum3" style="width: 70px" onChange="updatesum()" ></td>

             <td>
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input name="sumone" readonly " style="width: 70px"></td>


           <td>

</td>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</tr>  
<tr>
<td></td>
<td></td>
<td></td>
<td>                  total<input name="sumtotal" readonly style="border:0px;"> </td>
</tr>  
<tr>
<td></td>
<td></td>
<td></td>
<td>                   paid<input type="text" name="sumtotalmoney" style="border:0px;" onChange="updatesum()"> </td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>                 Return<input name="sumtotalgiven" readonly style="border:0px;" > </td>
</tr>         
                 </table>
</form>



<br>


</body>
</html>












<?php
include("db.php");
?>
<!DOCTYPE html>
<html>
<head>
<style>
table {

   border-collapse: collapse;
}

table, td, th {
   /* border: 1px solid black;*/
   /* padding: 5px;*/
   text-align: center;
}

th {text-align: left;}
</style>

<body>

<?php
$q = intval($_GET['q']);

//echo $q;




$qry="SELECT * FROM inventory WHERE id = '".$q."'";
$rs=mysql_query($qry);
?>



<?php
while($rw=mysql_fetch_array($rs)){
?>
<table>
<tr>
<td>
<?php echo "&nbsp". "&nbsp". "&nbsp". "&nbsp". "&nbsp" . "&nbsp". "&nbsp". "&nbsp" ?>
 <?php  echo $rw['price']?> <?php echo "&nbsp". "&nbsp" . "&nbsp" . "&nbsp" . "&nbsp". "&nbsp". "&nbsp". "&nbsp". "&nbsp". "&nbsp". "&nbsp". "&nbsp"
. "&nbsp". "&nbsp". "&nbsp" ?>
 <?php echo $rw['batchno'] ?> 
 <?php echo "&nbsp". "&nbsp" . "&nbsp" . "&nbsp" . "&nbsp". "&nbsp". "&nbsp". "&nbsp". "&nbsp". "&nbsp". "&nbsp". "&nbsp"
. "&nbsp". "&nbsp". "&nbsp" ?>
  <?php echo $rw['expire'] ?>
  </td>


</tr>
</table>








<?php 
}
?>



</body>
</html>

1 个答案:

答案 0 :(得分:0)

详细了解sessions in php

如果你需要在php文件之间存储一些值,你可以这样做:

<?php
session_start();

$_SESSION['myVariable'] = $_GET['myVariable'];

在另一个php文件中,您可以将以前定义的变量作为:

<?php
session_start();

echo $_SESSION['myVariable'];