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.
Thanks!

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

CREATE TABLE IF NOT EXISTS Example
-- 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

Post the code and error messages.

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`)
) ENGINE=MyISAM AUTO_INCREMENT=25 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `eventStudent`
--

LOCK TABLES `eventStudent` WRITE;
UNLOCK TABLES;

This is the code I used to create the table.
if(isset($_POST))
{
include_once('db.php');
include_once('functions_student.php');

$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') ";

safe_query($query);

echo "<br><b>$titleStudent</b> has been added to the database<br>";
}
else
{
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

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.

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.