Jump to content

first try at creating table


chris93

Recommended Posts

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()


)");


?>
 

Link to comment
https://forums.phpfreaks.com/topic/287958-first-try-at-creating-table/
Share on other sites

$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. :tease-03:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.