ZeroShade Posted October 14, 2007 Share Posted October 14, 2007 I'm trying to get the user to input a number into the textbox and as the user inputs a number a function is called with ajax to see if the number is correct or not... but I'm getting this error: Parse error: syntax error, unexpected T_STRING in c:\Inetpub\vhosts\domain.com\httpdocs\Index.php on line 62 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Guess My Number!</title> <script language="javascript" type="text/javascript"> var XMLHttpRequestObject = false; if (window.XMLHttpRequest) { XMLHttpRequestObject = new XMLHttpRequest(); } else if (window.ActiveXObject) { XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); } function getData(data, targetDiv) { if (XMLHttpRequestObject) { var obj = document.getElementById(targetDiv); XMLHttpRequestObject.open("GET", data, true); XMLHttpRequestObject.onreadystatechange = function() { if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Ready state is complete and status is 200. } } var rand = <?php print "'".$rand."'"; ?>; obj.innerHTML = rand; } } </script> </head> <body> <?php $username = "Martin"; $password = "Legends"; $hostname = "localhost"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); mysql_select_db ("RandomNumber", $dbh); srand((double)microtime()*1000000); $rand = rand(0, 5); mysql_query("INSERT INTO number (Number) VALUES ($rand)"); $select = mysql_query('SELECT COUNT( * ) AS `Rows` , `Number` FROM `number`; //mysql_query("DELETE FROM `number` WHERE `number`.`Number` = $rand LIMIT 1"); //mysql_close($dbh); ?> <h1>Pick Your Random Number</h1> <p />Please insert a number from 0 to 5. <form> <input type="text" value="guess" id="guess" onchange="getData('guess', 'targetDiv')" /> </form> <div id="targetDiv"> <p /> </div> </body></html> Link to comment Share on other sites More sharing options...
Synook Posted October 14, 2007 Share Posted October 14, 2007 The is no closing quote (or parenthesis) for the mysql_query on line 54, which leads to the entire code after that being treated as a string, until it reaches the single quote in the onchange handler, which is followed by an illegal string (T_STRING). Change line 54 to $select = mysql_query('SELECT COUNT( * ) AS `Rows` , `Number` FROM `number`'); By the way, your use of the <p> tag is incorrect, it is not empty! http://www.w3schools.com/tags/tag_p.asp Link to comment Share on other sites More sharing options...
ZeroShade Posted October 14, 2007 Author Share Posted October 14, 2007 Wow... I havn't done something like that for a good 2 years. Link to comment Share on other sites More sharing options...
ZeroShade Posted October 14, 2007 Author Share Posted October 14, 2007 Now that that error is freed up i can test my page. But I'm still having a problem with the ajax portion to pass the guessed variable through on the onchange. Any thoughts? Link to comment Share on other sites More sharing options...
ZeroShade Posted October 14, 2007 Author Share Posted October 14, 2007 NVM, i needed to put my php script in the head... wasn't thinking. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.