jcjst21
12-08-2009, 12:15 AM
Hello,
I have an html script and a .php script.
The .php requests a random word from a table of words in a mysql database.
I wrote a html form to display the requested word in a text box.
Here is my html file:
<html>
<body>
<script type="text/javascript">
function myfunction()
{
var xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp= newHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
document.myLingo.word.value=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "get_Word.php",true);
xmlhttp.send(null);
}
</script>
<form name="myLingo">
<input type="button" name="button" value="New Word" onClick="myFunction();" />
<input type="text" name="word" />
</form>
</body>
</html>
and here is my .php script:
<?php
$con=mysql_connect('localhost', 'xxxx', 'xxxx');
if (!$con)
{
die('Could not connect: '.mysql_error());
}
mysql_select_db("my_lingo", $con);
$sql=mysql_query("SELECT `word` FROM `words` ORDER BY RAND()") or trigger_error('Error: ' .mysql_error());
$word=mysql_fetch_array($sql);
echo $word[0];
mysql_close($con);
?>
When I run this in Internet Explorer; I get a error that is asking for an object on line 32 which is the line that has my button in the javascript.
When i run it in firefox, I don't receive an error, but the page still does nothing.
Any suggestions?
The main function of the page is that, when I click the button, it's supposed to return me a random word from the .php script
Thanks,
jcjst21
I have an html script and a .php script.
The .php requests a random word from a table of words in a mysql database.
I wrote a html form to display the requested word in a text box.
Here is my html file:
<html>
<body>
<script type="text/javascript">
function myfunction()
{
var xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp= newHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
document.myLingo.word.value=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "get_Word.php",true);
xmlhttp.send(null);
}
</script>
<form name="myLingo">
<input type="button" name="button" value="New Word" onClick="myFunction();" />
<input type="text" name="word" />
</form>
</body>
</html>
and here is my .php script:
<?php
$con=mysql_connect('localhost', 'xxxx', 'xxxx');
if (!$con)
{
die('Could not connect: '.mysql_error());
}
mysql_select_db("my_lingo", $con);
$sql=mysql_query("SELECT `word` FROM `words` ORDER BY RAND()") or trigger_error('Error: ' .mysql_error());
$word=mysql_fetch_array($sql);
echo $word[0];
mysql_close($con);
?>
When I run this in Internet Explorer; I get a error that is asking for an object on line 32 which is the line that has my button in the javascript.
When i run it in firefox, I don't receive an error, but the page still does nothing.
Any suggestions?
The main function of the page is that, when I click the button, it's supposed to return me a random word from the .php script
Thanks,
jcjst21