Jump to content

Onchange a texbox


ZeroShade
 Share

Recommended Posts

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...