Note that there are some explanatory texts on larger screens.

plurals
  1. POMySql database INSERT operation works on hard disk(localhost) but not when hosted on the Internet
    primarykey
    data
    text
    <p>I have a INSERT operation in my website which works like this.</p> <ol> <li>On index.html file when a button is pressed a javascript function is called.</li> <li>In the javascript function AJAX is used to send the request to the php file with necessary parameters</li> <li>The php file accesses the database inserts data.</li> </ol> <p>For your reference here is the code for the above tasks.</p> <p>2.Javascript function</p> <pre><code>function grandFinale() { 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("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","insert.php?q=&amp;name=" + encodeURIComponent(document.getElementById('name').value) + "&amp;txtScore1=" + encodeURIComponent(document.getElementById('txtScore1').innerHTML),true); xmlhttp.send(); document.location.reload(); } </code></pre> <p>1.HTML button</p> <pre><code>&lt;p id="txtScore1" align="center" style="color: #cc6699; font-size: 18px; "&gt;&lt;/p&gt; &lt;label class="control-label" for="input01"&gt;Name&lt;/label&gt; &lt;a href="#" class="btn btn-primary" onclick="javascript:grandFinale()" &gt;Submit My Score&lt;/a&gt; </code></pre> <p>3.PHP Script</p> <pre><code>&lt;?php $con = mysql_connect("host","uname","pword"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbname", $con) or die( "Unable to select database"); $sql="INSERT INTO 'masterTable' ('Name', 'Score') VALUES ('{$_GET['name']}','{$_GET['txtScore1']}')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con); ?&gt; </code></pre> <p>Things work fine when I try locally on harddisk but after I host it on 000webhost.com the INSERT doesnt work. Can you suggest where I went wrong?</p>
    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