Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将跨度值插入数据库?_Javascript_Php_Database_Drop Down Menu_Html - Fatal编程技术网

Javascript 如何将跨度值插入数据库?

Javascript 如何将跨度值插入数据库?,javascript,php,database,drop-down-menu,html,Javascript,Php,Database,Drop Down Menu,Html,我似乎找不到将跨度值插入数据库的正确解决方案。或者,关于如何通过从下拉列表中选择来显示数据库中的值,还有其他选项吗?这是我的密码 下面是我的javascript,它从下拉列表中获取要选择的值 <script type="text/javascript"> function showUser(userNumber, str) { if (str=="") { document.getElementById("value" + userNumber).innerHTML=

我似乎找不到将跨度值插入数据库的正确解决方案。或者,关于如何通过从下拉列表中选择来显示数据库中的值,还有其他选项吗?这是我的密码

下面是我的javascript,它从下拉列表中获取要选择的值

<script type="text/javascript"> 
function showUser(userNumber, str) 
{ 

if (str=="") 
{ 
  document.getElementById("value" + userNumber).innerHTML=""; 
  return; 
}   
if (window.XMLHttpRequest) 
{// code for IE7+, Firefox, Chrome, Opera, Safari 
  xmlhttp=new XMLHttpRequest(); 
} 

xmlhttp.onreadystatechange=function() 
{ 
  if (xmlhttp.readyState==4 && xmlhttp.status==200) 
  { 
    //document.getElementById("txtHint" + userNumber).innerHTML=xmlhttp.responseText;
    var responseText = xmlhttp.responseText;
    var coron = responseText;
    var meas = "";
    var unit ="";

    if (responseText.indexOf("NOT A VALID") == -1)
    {
      coron = responseText.substring(12, responseText.indexOf(",Value:")); 
      meas = responseText.substring(responseText.indexOf(",Value:")+7,      responseText.indexOf(",Weight:")); 
      unit = responseText.substring(responseText.indexOf(",Weight:")+8);

    }

    document.getElementById("value" + userNumber).innerHTML = coron;
    document.getElementById("meas" + userNumber).innerHTML = meas; 
    document.getElementById("unit" + userNumber).innerHTML = unit;
  } 
} 
xmlhttp.open("GET","coron.php?q="+str,true); 
xmlhttp.send();
}
</script>

这就是我要做的,从填充的下拉菜单中选择一个项目,然后在选择后,它会自动显示其相应的值、测量值和单位。我找到了适合我的项目的代码,然后提出了javascript代码。发现代码只使用span或div显示。但据推测,我真的想将其显示在文本框中。现在,我想通过将它们提交到数据库来存储它们,但我似乎不知道如何存储。是否有其他方法通过从下拉列表中选择自动获取相应的值、测量值和单位?请帮帮我。我对这真的很陌生。提前谢谢

旁注:停止使用不推荐的
mysql.*
函数。请改用MySQLi或PDO。sidenote:您的代码会受到SQL注入攻击,因为您直接允许在查询中插入POST值。sidenote:建议使用jQuery来减少XHR上的麻烦;您的JS代码看起来很笨拙。输入字段值不是span的值。您可以使用jquery:
$(“value1”).val()我该怎么办?我真的不知道该怎么做,因为我是新手。
<form name="mainform" method="post" action="submit.php">
<table align = "center" border = "1" ><tr align = "center"><td class = "laman">Qty.
    <td class = "laman">Units
    <td class = "description">Desciprtion of Articles
    <td class = "laman">Value
    <td class = "laman">Meas/Weight
    <td class = "laman">Freight Charge</tr>
    <tr align = "center"><td class = "laman"><input size = "5" type = "text" name = "qty" onkeyup = "calculateTotal()" />
    <td class = "laman"><span id="unit1"></span>
    <td class = "description"><? 
                                $con = mysql_connect("localhost","root","") or die(mysql_error());
                                mysql_select_db("ler_marineland", $con) or die(mysql_error());

                                $sql="SELECT product_id, description FROM product"; 
                                $result=mysql_query($sql); 

                                $options=""; 


                                while ($row=mysql_fetch_array($result)) { 

                                    $product_id=$row["product_id"]; 
                                    $description=$row["description"]; 
                                    $options.="<OPTION VALUE=\"$product_id\">".$description.'</option>'; 

                                } 
                                ?> 

                                <SELECT id=myselect onchange="showUser(1, this.value);"> 
                                <OPTION VALUE=0>
                                <?=$options?>
                                </SELECT>

    <td class = "laman"><span id="value1" name="value"></span>
    <td class = "laman"><span id="meas1" name="meas"></span>
    <td class = "laman"><span id="fc" name="fc"></span></tr>
            <tr><td>Voyage No. <td><input size = "8" type = "text" name = "voyage_no" />
$con = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("ler_marineland", $con) or die(mysql_error());


            $qty= $_POST['qty'];
            $units= $_POST['units'];
            $description= $_POST['description'];
            $value= $_POST['value'];
            $meas= $_POST['meas'];
            $fcharge= $_POST['fc'];
                            $voyage_no= $_POST['voyage_no'];


$sql = 'SELECT * FROM coron WHERE voyage_no = "'.mysql_real_escape_string($voyage_no).'"'; 

    mysql_query("INSERT INTO coron (voyage_no, qty, units, description, value, meas, fc) VALUES ('$voyage_no', '$qty', '$units', '$description', '$value', '$meas', '$fc')") or die(mysql_error());