Mysql help?

Questions about programming languages and debugging
Post Reply
User avatar
Swan
Knight of the Sword
Knight of the Sword
Posts: 827
Joined: 18 Oct 2006, 16:00
17
Contact:

Mysql help?

Post by Swan »

This code wont run, esp. the query

<?php
//connect to MySQL
$connect = mysql_connect('localhost', 'root', 'Jennysmith')
or die ('Hey loser, check your server connection.');
//make sure we’re using the right database
mysql_select_db('moviesite');
//insert data into 'movie' table
$insert = 'INSERT INTO movie (movie_id,movie_name, movie_type, ' .'movie_year, movie_leadactor, movie_director) . 'VALUES (1, ‘Bruce Almighty’, 5, 2003, 1, 2), ' . '(2, ‘Office Space’, 5, 1999, 5, 6),' . '(3, ‘Grand Canyon’, 2, 1991, 4, 3)';

$results = mysql_query($insert) or die(mysql_error());
//insert data into 'movietype' table


$type = 'INSERT INTO movietype (movietype_id, movietype_label) ' .
'VALUES (1,’Sci Fi’), ' .
'(2, ‘Drama’), ' .
'(3, ‘Adventure’), ' .
'(4, ‘War’), ' .
'(5, ‘Comedy’), ' .
'(6, ‘Horror’), ' .
'(7, ‘Action’), ' .

'(8, ‘Kids’)' ;
$results = mysql_query($type)
or die(mysql_error());
//insert data into 'people' table
$people = 'INSERT INTO people (people_id, people_fullname, ' .
'people_isactor, people_isdirector) ' .
'VALUES (1, ‘Jim Carrey’, 1, 0), ' .
'(2, ‘Tom Shadyac’, 0, 1), ' .
'(3, ‘Lawrence Kasdan’, 0, 1), ' .
'(4, ‘Kevin Kline’, 1, 0), ' .
'(5, ‘Ron Livingston’, 1, 0), ' .
'(6, ‘Mike Judge’, 0, 1)';
$results = mysql_query($people)
or die(mysql_error());
echo 'Data inserted successfully!';
?>

Also, is it possible to run a query outwith PHP?

Thanks guys, this code has been taken from my book.....not very good it seems!
[/b]

p99
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 291
Joined: 14 Oct 2006, 16:00
17
Location: Some hippy's van
Contact:

Post by p99 »

For starters post the error you are getting.

And yes you can use mysql withought php. Either from command line or using a tool such as phpmyadmin.

User avatar
Swan
Knight of the Sword
Knight of the Sword
Posts: 827
Joined: 18 Oct 2006, 16:00
17
Contact:

Post by Swan »

Ok when I try and run the program AS IS currently, I get the following error:

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\moviedata.php on line 8

Which happens to be my first query the line in bold in my first post.

p99
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 291
Joined: 14 Oct 2006, 16:00
17
Location: Some hippy's van
Contact:

Post by p99 »

$insert = 'INSERT INTO movie (movie_id,movie_name, movie_type, ' .'movie_year, movie_leadactor, movie_director) . 'VALUES (1, ‘Bruce Almighty’, 5, 2003, 1, 2), ' . '(2, ‘Office Space’, 5, 1999, 5, 6),' . '(3, ‘Grand Canyon’, 2, 1991, 4, 3)';

The dots are unneccisary

like right after movie_director

You want the query one solid string instead of all the conactations.

User avatar
Swan
Knight of the Sword
Knight of the Sword
Posts: 827
Joined: 18 Oct 2006, 16:00
17
Contact:

Post by Swan »

After removing the dots I then get the following error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

The modified code is as follows:

$insert = 'INSERT INTO movie (movie_id,movie_name, movie_type, ' 'movie_year, movie_leadactor, movie_director) 'VALUES (1, ‘Bruce Almighty’, 5, 2003, 1, 2), ' '(2, ‘Office Space’, 5, 1999, 5, 6),' '(3, ‘Grand Canyon’, 2, 1991, 4, 3)';

p99
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 291
Joined: 14 Oct 2006, 16:00
17
Location: Some hippy's van
Contact:

Post by p99 »

You still had some floating quotes

I removed what I could see:

$insert = "INSERT INTO movie (movie_id,movie_name, movie_type, movie_year, movie_leadactor, movie_director) VALUES (1, ‘Bruce Almighty’, 5, 2003, 1, 2), (2, ‘Office Space’, 5, 1999, 5, 6), (3, ‘Grand Canyon’, 2, 1991, 4, 3)";

Try that.

Post Reply