Hello Guys, I just started learning PHP. I come from C++ background. I was looking into database stuff. I wrote following: <?php $name = $_REQUEST['name']; $faculty = $_REQUEST['faculty']; mysql_connect("localhost","","") or die("Can not connect to the database"); mysql_select_db(test); $query=insert into test_table(name,faculty) values('".$name."','".$faculty."'); mysql_query(query) or die("Can not post anything"); echo "Data successfully posted to the database."; ?> It gives me following error. Parse error: syntax error, unexpected T_STRING in /Users/basantathapa/Sites/blahsubmit.php on line 14 Any idea what am I doing wrong? Thanks
$query=insert into test_table(name,faculty) values('".$name."','".$faculty."'); Above is the 14th line.
I would reccommend you don't go any further with that code, you shouldn't be using old mysql functions any more as it is soon to be deprecated, look into using PDO or mysqli, it's much more secure
Its should work now! <?php $name = $_REQUEST['name']; $faculty = $_REQUEST['faculty']; mysql_connect("localhost","","") or die("Can not connect to the database"); mysql_select_db(test); $query="INSERT INTO `test_table` (`name`, `faculty`) VALUES ('".$name."', '".$faculty."')"; $result = mysql_query($query) or die("Can not post anything"); echo "Data successfully posted to the database."; ?> Code (markup): You forgot a few qoutes and the dollar sign before query.