chris93 Posted April 23, 2014 Share Posted April 23, 2014 hi guys , I`m trying to create a table called table with php , this is my code when i run the code im getting Parse error: syntax error, unexpected 'mysql_query' (T_STRING) in C:\xampp2\htdocs\tutorials\abc.php on line 16 <?php$user = 'root' ;$pass = 'fireman9' ;$db = 'testdb' ;$con = new mysqli('localhost', $user , $pass , $db) or die("UNABLE TO CONNECT");$selected = mysql_select_db($db,con)mysql_query(" CREATE TABLE people(firstname varchar(15)gender varchar())");?> Quote Link to comment https://forums.phpfreaks.com/topic/287958-first-try-at-creating-table/ Share on other sites More sharing options...
bsmither Posted April 23, 2014 Share Posted April 23, 2014 Please make sure every PHP statement ends with a semi-colon (a couple of exceptions). Quote Link to comment https://forums.phpfreaks.com/topic/287958-first-try-at-creating-table/#findComment-1477037 Share on other sites More sharing options...
IanA Posted April 23, 2014 Share Posted April 23, 2014 You will also need to add a comma after varchar(15) Quote Link to comment https://forums.phpfreaks.com/topic/287958-first-try-at-creating-table/#findComment-1477048 Share on other sites More sharing options...
ginerjm Posted April 23, 2014 Share Posted April 23, 2014 You might also use mysqlI_* functions since you opened up your connection that way. Quote Link to comment https://forums.phpfreaks.com/topic/287958-first-try-at-creating-table/#findComment-1477072 Share on other sites More sharing options...
Strider64 Posted April 24, 2014 Share Posted April 24, 2014 $con=mysqli_connect("localhost","root","your_password","demo"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql ="CREATE TABLE IF NOT EXISTS `people` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(15) NOT NULL, `gender` char(15) NOT NULL, `date_added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5" ; if (mysqli_query($con,$sql)) { echo "Database my_db created successfully"; } else { echo "Error creating database: " . mysqli_error($con); } Even threw in a timestamp. Quote Link to comment https://forums.phpfreaks.com/topic/287958-first-try-at-creating-table/#findComment-1477158 Share on other sites More sharing options...
ginerjm Posted April 24, 2014 Share Posted April 24, 2014 What is wrong with your NEW code? You didn't tell us. If there is a line number in the message, please indicate that in your next code posting. Quote Link to comment https://forums.phpfreaks.com/topic/287958-first-try-at-creating-table/#findComment-1477170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.