选择值未传递给php

时间:2015-11-06 16:00:32

标签: php ajax variables

我的Dropbox有以下代码;

<select name="Symptom" id="Symptomid"  onchange="LSC(this.value)"> 

它的选择是;

 <option value="<?php echo $row_RsSymptom['name']?>"><?php echo     $row_RsSymptom['name']?></option>

完整的Html代码;

    <?php require_once('Connections/Connshifa.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }

      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }

    mysql_select_db($database_Connshifa, $Connshifa);
    $query_RsSymptom = "SELECT * FROM symptoms ORDER BY symptoms.name";
    $RsSymptom = mysql_query($query_RsSymptom, $Connshifa) or die(mysql_error());
    $row_RsSymptom = mysql_fetch_assoc($RsSymptom);
    $totalRows_RsSymptom = mysql_num_rows($RsSymptom);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Cure by Symptom</title>
    <?php
    // Start the session
    session_start();
    ?>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="css/coin-slider.css" />
    <style type="text/css">
    .main .content .content_resize .mainbar .article label {
        font-weight: bold;
    }
    </style>
    <script type="text/javascript" src="js/cufon-yui.js"></script>
    <script type="text/javascript" src="js/cufon-aller.js"></script>
    <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="js/script.js"></script>
    <script type="text/javascript" src="js/coin-slider.min.js"></script>
    </head>
    <body>
    <div class="main">
      <div class="header">
        <div class="header_resize">
          <div class="slider">
            <div id="coin-slider"></div>
            <div class="clr"></div>
          </div>
          <div class="clr"></div>
        </div>
      </div>
      <div class="content">
        <div class="content_resize">
          <div class="mainbar">
            <div class="article">
              <h2>Find Your Cure</h2>
              <p class="infopost">&nbsp;</p>
              <div class="clr"></div>
              <div class="clr"></div>
            </div>
            <div class="article">
              <h2>Every Disease has a Cure</h2>
    <?php


    echo "Welcome " . $_SESSION["username"] . " !" . ".<br>";

    ?> 


              <form id="form1" name="form1" method="post" action="">


              <label for="Uname">User Name/Email </label>
                <input name="Uname" type="text" id="Uname" value="<?php echo $_SESSION["username"] ?>" readonly="readonly" />
                <form method="post">
              </form>

                <label for="Symptom"><br />
                  Select your Symptom
                  <br />
                  <br />
                Symptom</label>





                    <?php
    do {  
    ?>
                    <option value="<?php echo $row_RsSymptom['name']?>"><?php echo $row_RsSymptom['name']?></option>
                    <?php
    } while ($row_RsSymptom = mysql_fetch_assoc($RsSymptom));
      $rows = mysql_num_rows($RsSymptom);
      if($rows > 0) {
          mysql_data_seek($RsSymptom, 0);
          $row_RsSymptom = mysql_fetch_assoc($RsSymptom);
      }
    ?>

                  <br />
                  <br />
                  <br />
                  <br />
    <br />
          <p id="demo"></p>
                    <script>
                        function Symselect() {
                            var x = document.getElementById("Symptomid").value;
                            document.getElementById("demo").innerHTML = "You selected: " + x;
                        }
           </script>


                <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script>
    function LSC() {
        // using jquery ajax method for calling the php script
        $.ajax({
            // set this to the url of your php script for calling the LSC function
            url: 'LoadSymptomDetails.php',

            // if the result of the ajax request is ok then this function is called
            success: function(response) {
                // the variable 'response' will contain the output from your php script
                // as an example we'll use a javascript alert to show the output of the response
                alert(response);
            }
        });
    }
    </script>




               <?php

//require("classes\LoadSymptomDetails.php");
            ?>
              <br />
            System</label>
          </form>
          <select name="System" id="System">
          </select>
          <p class="infopost">&nbsp;</p>
          <p class="infopost">&nbsp;</p>
        </div>
      </div>
    </div>
  </div>
  <div class="footer">
    <div class="footer_resize">
      <div style="clear:both;"></div>
    </div>
  </div>
</div>
</body>
</html>
<?php
mysql_free_result($RsSymptom);
?>

LoadSymptomDetails.php

<?php require_once('Connections/Connshifa.php'); ?>

<?php

//$q = 1

?>

<?php

$data = array();


{
    mysql_select_db("shifa",$Connshifa );

    $sql1 = mysql_query("SELECT name,description , comments
    FROM symptoms WHERE symptoms.name ='".$q."'") or die(mysql_error());

    //$sql="SELECT * FROM user WHERE ID = '".$q."'";

    while($row1 = mysql_fetch_assoc($sql1)){
        $data[] = $row1;
    }
}
?>
<?php
if($data){
?>
echo $q
<table border="1">
    <tr>
        <td>name</td>
        <td>description</td>
        <td>comments</td>
    </tr>

<?php
    if($data){
        foreach($data as $sy){
?>
    <tr>
        <td><?php echo $sy['name']; ?> </td>
        <td><?php echo $sy['description']; ?> </td>
        <td><?php echo $sy['comments']; ?> </td>

    </tr>
<?php
    }
}
?>
<?php
}

?>


</table>

q未被挑选。如果我删除它运行的where语句并显示表。

请帮忙。

阿扎

1 个答案:

答案 0 :(得分:0)

由于我们无法看到PHP的其余部分,请立即尝试:

$sql1 = mysql_query("SELECT name,description , comments
FROM symptoms WHERE symptoms.name ='".$_GET['q']."'") or die(mysql_error());