Hello world.
I'll try to be specific. I'm using a form and some javascript in my HTML page to make an xmlhttp request to a php file.
The form has three inputs which are sent via an xmlhttp request.
I intend to use the collected data in the php file to query a mysql database and send back a response that I can then use in the javascript.
In the response onready function of the initial javascript I assign the response to a textbox so I can then do what I like with it.
At the moment, I'm not worrying about the mysql syntax becuase I'm still having problems returning a response to the textbox. I've tried for example just using a single line php file with an echo 'here is a test response'; but I don't receive anything back.
I've also tried using both POST and GET and if I run the php file directly and tag on some input to the query string then any echos in the file are output directly so it seems the problem is either the xmlhttp request or the on ready function in the javascript.
For now - I've got both my html file and php file in the same directory.
I tried all day yesterday to find out what the problem is without success. I'm hoping somebody here will identify something stupid I am doing.
Here is the html file..
<html>
<head>
<script>
// ---------------------------------------------------------------------------------------------------------------------------------------
function get2server() { var input1=document.testform.input1.value;
var input2=document.testform.input2.value;
var input3=document.testform.input3.value'
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)
{
// output server resonse ie: In this case confirmation variable has been set at the server
document.testform.output1.value=xmlhttp.responseText;
}
}
xmlhttp.open("GET","serverget.php?input1="+input1+"&input2="+input2+"&input3="+input3,true);
xmlhttp.send();
} // End function Serverget
</script>
</head>
<body>
<BR>
<H2>Server Test</H4>
<BR>
<H4> Specify Command, Variable and Value</H3>
<form NAME="testform">
<INPUT TYPE="TEXT" NAME="input1" SIZE=16><BR>
<INPUT TYPE="TEXT" NAME="input2" SIZE=16><BR>
<INPUT TYPE="TEXT" NAME="input3" SIZE=16><BR>
<BR>
<INPUT TYPE="button" VALUE="- Send to server -" onClick="get2server()"><BR>
<INPUT TYPE="TEXT" NAME="output1" SIZE=30>
</body>
</html>
and here is the php file...
<?php
define('DB_NAME','xxxxxxxxx'); // I have got my actual details in the real one
define('DB_USER','xxxxxxxxx');
define('DB_PASSWORD','xxxxxxxxx');
define('DB_HOST','localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); // connect to Host computer
if (!$link) { echo 'Error connecting'; }
$db_selected = mysql_select_db(DB_NAME, $link); // Select database
if (!$db_selected) { die('Can\'t use ' . DB_NAME . ': ' . mysql_error()); }
echo 'Connected successfully';
$value1= $_GET['input1']; // command
$value2= $_GET['input2']; // name // Retrieve input passed in from form
$value3= $_GET['input3']; // value
echo 'You got this far !';
echo $value1;
echo $value2;
echo $value3;
$result = mysql_query("SELECT * FROM value WHERE name ='$_POST[input2]'");
if (!mysql_query($sql)) { die('Error: ' . mysql_error()); }
$row = mysql_fetch_row($result);
echo $row[0];
echo $row[1];
echo $row[2];
$response=$row[0]+$row[2]+$row[3];
mysql_close();
?>
I really hope someone can point me in the right direction here becuase I'm lost to what I can try next. Thanks in advance for any replies.
---------- Post added at 04:21 PM ---------- Previous post was at 09:54 AM ----------
Hi again,
Well I feel a bit schizophrenic answering my own post but I thought I better record the fact that the problem is solved just in case anyone decides to go through the rather jumbled script I left here.
I found a really minimalist example of the request and response and it works ! so I'm using it as a template and gradually building it up bit by bit until I've transfered everything that I want into it. At the moment I can't see what is causing the problem but I expect I will find out when I move over into to the new script whatever is causing it.
Thanks for looking
I'll try to be specific. I'm using a form and some javascript in my HTML page to make an xmlhttp request to a php file.
The form has three inputs which are sent via an xmlhttp request.
I intend to use the collected data in the php file to query a mysql database and send back a response that I can then use in the javascript.
In the response onready function of the initial javascript I assign the response to a textbox so I can then do what I like with it.
At the moment, I'm not worrying about the mysql syntax becuase I'm still having problems returning a response to the textbox. I've tried for example just using a single line php file with an echo 'here is a test response'; but I don't receive anything back.
I've also tried using both POST and GET and if I run the php file directly and tag on some input to the query string then any echos in the file are output directly so it seems the problem is either the xmlhttp request or the on ready function in the javascript.
For now - I've got both my html file and php file in the same directory.
I tried all day yesterday to find out what the problem is without success. I'm hoping somebody here will identify something stupid I am doing.
Here is the html file..
<html>
<head>
<script>
// ---------------------------------------------------------------------------------------------------------------------------------------
function get2server() { var input1=document.testform.input1.value;
var input2=document.testform.input2.value;
var input3=document.testform.input3.value'
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)
{
// output server resonse ie: In this case confirmation variable has been set at the server
document.testform.output1.value=xmlhttp.responseText;
}
}
xmlhttp.open("GET","serverget.php?input1="+input1+"&input2="+input2+"&input3="+input3,true);
xmlhttp.send();
} // End function Serverget
</script>
</head>
<body>
<BR>
<H2>Server Test</H4>
<BR>
<H4> Specify Command, Variable and Value</H3>
<form NAME="testform">
<INPUT TYPE="TEXT" NAME="input1" SIZE=16><BR>
<INPUT TYPE="TEXT" NAME="input2" SIZE=16><BR>
<INPUT TYPE="TEXT" NAME="input3" SIZE=16><BR>
<BR>
<INPUT TYPE="button" VALUE="- Send to server -" onClick="get2server()"><BR>
<INPUT TYPE="TEXT" NAME="output1" SIZE=30>
</body>
</html>
and here is the php file...
<?php
define('DB_NAME','xxxxxxxxx'); // I have got my actual details in the real one
define('DB_USER','xxxxxxxxx');
define('DB_PASSWORD','xxxxxxxxx');
define('DB_HOST','localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); // connect to Host computer
if (!$link) { echo 'Error connecting'; }
$db_selected = mysql_select_db(DB_NAME, $link); // Select database
if (!$db_selected) { die('Can\'t use ' . DB_NAME . ': ' . mysql_error()); }
echo 'Connected successfully';
$value1= $_GET['input1']; // command
$value2= $_GET['input2']; // name // Retrieve input passed in from form
$value3= $_GET['input3']; // value
echo 'You got this far !';
echo $value1;
echo $value2;
echo $value3;
$result = mysql_query("SELECT * FROM value WHERE name ='$_POST[input2]'");
if (!mysql_query($sql)) { die('Error: ' . mysql_error()); }
$row = mysql_fetch_row($result);
echo $row[0];
echo $row[1];
echo $row[2];
$response=$row[0]+$row[2]+$row[3];
mysql_close();
?>
I really hope someone can point me in the right direction here becuase I'm lost to what I can try next. Thanks in advance for any replies.
---------- Post added at 04:21 PM ---------- Previous post was at 09:54 AM ----------
Hi again,
Well I feel a bit schizophrenic answering my own post but I thought I better record the fact that the problem is solved just in case anyone decides to go through the rather jumbled script I left here.
I found a really minimalist example of the request and response and it works ! so I'm using it as a template and gradually building it up bit by bit until I've transfered everything that I want into it. At the moment I can't see what is causing the problem but I expect I will find out when I move over into to the new script whatever is causing it.
Thanks for looking
Last edited: