Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert SPAN value to DB
    primarykey
    data
    text
    <p>I have tried many ways to insert the value from SPAN to DB? The value displayed into span is from Javascript. Currently when i run, 0.00 from both UP and TP will get displayed with values from javascript functions. And when i insert into MYSQL Database, i get all other data inserted except for the values from UP and TP. I am using input type = "hidden" to just pass the value. THis is my code. Can anyone help? Thank you. </p> <pre><code> &lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;b&gt;UnitPrice: &lt;span id="UP"&gt;0.00&lt;/span&gt; &lt;/b&gt;&lt;/div&gt;&lt;p&gt; &lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;b&gt;TotalPrice: &lt;span id="TP"&gt;0.00&lt;/span&gt; &lt;/b&gt;&lt;/div&gt;&lt;p&gt; &lt;input type="hidden" name="UnitPrice" value="', document.getElementById("UP").value '"/&gt; &lt;input type="hidden" name="TotalPrice" value="', document.getElementById("TP").value '"/&gt; $UnitPrice = (trim($_POST['UnitPrice'])); $TotalPrice= (trim($_POST['TotalPrice'])); $query = "INSERT INTO `OrderItem` (`UnitPrice`, `TotalPrice`) VALUES ('$UnitPrice','$TotalPrice')"; $result = mysql_query($query) or die($query."&lt;br/&gt;&lt;br/&gt;".mysql_error()); </code></pre> <hr> <pre><code>&lt;script type="text/javascript"&gt; function showUP(str) { if (str==""){ document.getElementById("UP").innerHTML=""; return; } 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 &amp;&amp; xmlhttp.status==200){ document.getElementById("UP").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getunitprice.php?q="+str,true); xmlhttp.send(); } function multiply(Quantity) { var totalPrice = parseFloat(document.getElementById("UP").innerHTML)*Quantity; document.getElementById("TP").innerHTML = totalPrice; } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload