selecting a database error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Drezek
Forum Newbie
Posts: 3
Joined: Mon Jan 05, 2009 2:57 pm

selecting a database error

Post by Drezek »

im a big noob and well im trying to select a database after connecting but i have a problem heres the code

Code: Select all

<?php
$connection = mysql_connect('localhost', 'root', 'password');
if (!$connection) {
    die('Could not connect: ' . mysql_error());
}
$db_select = mysql_select_db("test", $connection)
if (!$db_select) {
    die('database selection failed' . mysql_error());
}
?>
this is the error i get
Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\sand\connection.php on line 7
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: selecting a database error

Post by VladSun »

You missed a semicolon on line 6
There are 10 types of people in this world, those who understand binary and those who don't
Drezek
Forum Newbie
Posts: 3
Joined: Mon Jan 05, 2009 2:57 pm

Re: selecting a database error

Post by Drezek »

wow i feel like a retard thanks :banghead:
Drezek
Forum Newbie
Posts: 3
Joined: Mon Jan 05, 2009 2:57 pm

Re: selecting a database error

Post by Drezek »

Code: Select all

<?php
$result = mysql_query("SELECT * FROM example", $connection);
 
while ($row = mysql_fetch_array($result)) {
echo $row["name"]. " " .$row["age"];
?>
whats the problem here
error
Parse error: syntax error, unexpected $end in C:\xampp\htdocs\sand\index.php on line 13
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Re: selecting a database error

Post by LiveFree »

You need a '}' to end the while() loop
Post Reply