I am just learning coding, but I have a friend who is helping me with learning. But anyway, I have this code, it's supposed to add a random number 1-10 in a database, and I am having an error with it. He is the one who told me to add "or die mysql_error();" at the end of the mysql_queries. But before that I had some error (I can't remember what it was) when I clicked on the button. But now I have an error just when loading the page. The error is "Parse error: parse error, unexpected T_STRING in H:\Program Files (x86)\xampp\htdocs\Test.php on line 12" And here's the code:
PHP Code:
<!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">
<?php
if (isset($_POST['update']))
{
mysql_connect('localhost', 'root', '');
mysql_select_db('a');
mysql_query('CREATE TABLE IF NOT EXISTS `b` (
`d` INT NOT NULL AUTO_INCREMENT ,
`c` INT NOT NULL ,
PRIMARY KEY ( `d` )
) TYPE = innodb;') or die mysql_error();
mysql_query('INSERT INTO `b`(`c`, `d`) ;
VALUES (' . mt_rand(1, 10) . ', 1)
ON DUPLICATE KEY UPDATE `c` = `c` + ' . mt_rand(1,10)) or die mysql_error();
$q = mysql_query('SELECT `c`
FROM `b`
WHERE `d` = 1
LIMIT 1') or die mysql_error();
$r = mysql_fetch_assoc($q);
print_r($r);
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>This is my basic page!</title>
Hello, if you got to this, you are hacking my computer. Please exit in a timely fashion otherwise I will be forced to <b>eat</b> your family. And I'll do it too. Don't believe me? Stay here then, when you get up to go to get something to eat, you'll see me cooking up your sister.
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input name="update" type="submit" value="Test" />
</form>
</body>
</html>
Comment