Page 1 of 1

Connect to DB - error

Posted: Thu Mar 25, 2010 5:06 am
by dhammikai
Dear all I am a beginer of PHP, MySQL,
I installed the WAMP 2.0 server and I try to following code:

Code: Select all

<?php echo $_SERVER['SCRIPCT_NAME']. "<br>"; ?>
 
<?php
    echo "<b> Intro: let's do a little genric database owork !</b> <br><br>";
    $user="user1";
    $passwd = "test";
    $Loc="locaalhost";
    //connecting to and selecting a database 
    $Connect=mysql_connect('localhost',$User,$passwd, , ) or die('Could not connect : ' );
    echo '<b> Step 1:</B> Connected successfully! <br> ';s
    
    $db = 'samples'; 
    mysql_select_db ($db) or die ('Could not select database ('.$db.') because of : ');
    echo '<b> Step 2: </b> Connected to ('.$db.') successeful! <br>';
    
    mysql_close ($connect) ;
?>
 
Anyway I add a user1 and pass wd "testing" from previlages. and also I change the passwd of root (in previlages) as "test" also i change the pass wd in "C:\Program_files\wamp\apps\phpmyadmin3.2.0.1\config.inc.php" fie set passwd as foloows;

Code: Select all

<?php
 
/* Servers configuration */
$i = 0;
 
/* Server: localhost [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = [i]'test';[/i]
$cfg['Servers'][$i]['AllowNoPassword'] = true;
 
/* End of servers configuration */
 
$cfg['DefaultLang'] = 'en-utf-8';
$cfg['ServerDefault'] = 1;
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
 
?>
 
 
then after I run this above code in the local host there have the error in line 9, which is
"$Connect=mysql_connect('localhost',$User,$passwd, , ) or die('Could not connect : ' );"

ERROR IS DISPLAY AS
"Parse error: parse error in C:\Program_files\wamp\www\connectDB.php on line 9"

please give me a help to find out where is the wrong in my coding or WAMP configuration process.


Thanks

Re: Connect to DB - error

Posted: Thu Mar 25, 2010 6:16 am
by Zlobcho
Hi,

Next time post your code in "bb code" tag. :)

You have few typo errors:
 
$Connect=mysql_connect('localhost',$User,$passwd, , ) or die('Could not connect : ' );
echo '<b> Step 1:</B> Connected successfully! <br> ';s
 

Re: Connect to DB - error

Posted: Fri Mar 26, 2010 12:24 am
by dhammikai
Hi, Thank you very much for Ur reply and comments.
I change my programe as U mentioned sa follows;

Code: Select all

 
<?php echo $_SERVER['SCRIPCT_NAME']. "<br>"; ?>
 
<?php
    echo "<b> Intro: let's do a little genric database owork !</b> <br><br>";
    $user="user1";
    $passwd = "testing";
    //connecting to and selecting a database 
    $connect=mysql_connect[b]('localhost', $user, $passwd)[/b] or die('Could not connect : ' );
    [b]echo '<b> Step 1:</B> Connected successfullty! <br> ';[/b]
    
    $db = 'samples'; 
    mysql_select_db ($db) or die ('Could not select database ('.$db.') because of : ');
    echo '<b> Step 2: </b> Connected to ('.$db.') successeful! <br>';
    
    mysql_close ($connect) ;
?>
 
But, the error msg is same as in line 9.

have anything else to do?

thanks

==============================================================

Zlobcho wrote:Hi,

Next time post your code in "bb code" tag. :)

You have few typo errors:
 
$Connect=mysql_connect('localhost',$User,$passwd, , ) or die('Could not connect : ' );
echo '<b> Step 1:</B> Connected successfully! <br> ';s
 

Re: Connect to DB - error

Posted: Mon Apr 05, 2010 5:02 am
by dhammikai
Hi Zlobcho,
Thank you very much for Ur help, Now it is solved and connect it successfully. Thank again.