Page 1 of 1

selecting a database error

Posted: Mon Jan 05, 2009 2:59 pm
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

Re: selecting a database error

Posted: Mon Jan 05, 2009 3:00 pm
by VladSun
You missed a semicolon on line 6

Re: selecting a database error

Posted: Mon Jan 05, 2009 3:03 pm
by Drezek
wow i feel like a retard thanks :banghead:

Re: selecting a database error

Posted: Mon Jan 05, 2009 3:09 pm
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

Re: selecting a database error

Posted: Mon Jan 05, 2009 3:12 pm
by LiveFree
You need a '}' to end the while() loop