Jump to content

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:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.