Someone please enlighten me.
I am just beginning to experiment with mysql and php on websites. I just took over a new site that had an exsisting sql file. I need to add a new table to the database and can not figure out how. If I just open the sql file and add the table I can not get it work with my php. I can add enough php for my pages to give me info that it is connecting to the database but then I recieve and error message when it comes to queries.
Please tell me how to actually add the table into the sql file and then get my php to work with it.
I hope I have described my problem in enough detail.

Re: Adding a new table 80 80

First, make sure that the SQL file has statements that read like this:

-- table definition goes here

Then you actually need to run the mysql query by typing the following into a terminal:

mysql DB_Name < script.sql
commented: You solved this post. +2
Re: Adding a new table 80 80

Post the code and error messages.

Re: Adding a new table 80 80

Table structure for table `eventStudent`

DROP TABLE IF EXISTS `eventStudent`;
CREATE TABLE `eventStudent` (
`idStudent` int(11) NOT NULL auto_increment,
`titleStudent` varchar(128) default NULL,
`descriptionStudent` blob,
`start_monthStudent` int(11) default NULL,
`start_dayStudent` int(11) default NULL,
`start_yearStudent` int(11) default NULL,
`end_monthStudent` int(11) default NULL,
`end_dayStudent` int(11) default NULL,
`end_yearStudent` int(11) default NULL,
`emailStudent` varchar(44) default NULL,
`urlStudent` varchar(128) default NULL,
PRIMARY KEY (`idStudent`)

-- Dumping data for table `eventStudent`

LOCK TABLES `eventStudent` WRITE;

This is the code I used to create the table.

$titleStudent = ($_POST);
$descriptionStudent = ($_POST);
$start_monthStudent = (int)$_POST;
$start_dayStudent = (int)$_POST;
$start_yearStudent = (int)$_POST;

$end_monthStudent = (int)$_POST;
$end_dayStudent = (int)$_POST;
$end_yearStudent = (int)$_POST;

$emailStudent = ($_POST);
$urlStudent = ($_POST);

$query = "INSERT INTO eventStudent(titleStudent,descriptionStudent,start_monthStudent, start_dayStudent,start_yearStudent,end_monthStudent,end_dayStudent,end_yearStudent,emailStudent,urlStudent) VALUES ";
$query .= "('$titleStudent','$descriptionStudent',$start_monthStudent, $start_dayStudent,$start_yearStudent,$end_monthStudent,$end_dayStudent,$end_yearStudent,'$emailStudent','$urlStudent') ";


echo "<br><b>$titleStudent</b> has been added to the database<br>";
echo "<br>Insertion failed<br>";
This is the php code where I am trying to use the table. I added a test and am successfully connecting to the database but I get the Insertion failed message when I click on the form.
Like I said I have never used mysql before and have had training in sql many years ago and then never had to use it.
I know the problem is running the mysql. All the php forms were created before I took over and work fine. I am just trying to add another form to do the exact same thing.
Thanks for the help

Re: Adding a new table 80 80

After you have created your eventStudent table can you DESCRIBE it?

DESCRIBE eventStudent;

If not, then the table has not been created. Like I said, you need to run your SQL file before trying to run your php script.

Re: Adding a new table 80 80

Thanks for your help. I finally realized I was using the wrong engine. I was able to describe the table and insert and then incorporate my php and everything is running smoothly.
Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.