connect to mysql issue

Howdy,

First things first folks, I’m a newb.

Here is my issue:
I get this error:

////////// error //////////////

Notice: Undefined variable: localhost in /Users/patrickmeaney/localhost/BobsSuits/storescripts/connect_to_mysql.php on line 21

Notice: Undefined variable: builder2 in /Users/patrickmeaney/localhost/BobsSuits/storescripts/connect_to_mysql.php on line 21

Notice: Undefined variable: builder2 in /Users/patrickmeaney/localhost/BobsSuits/storescripts/connect_to_mysql.php on line 21

Notice: Undefined variable: suitstore in /Users/patrickmeaney/localhost/BobsSuits/storescripts/connect_to_mysql.php on line 22
no database

/////////////error///////////

when I run my test file. Below are the files of my connect to mysql file and the test file. Also, I wanted to mention, my site documents are not in the MAMP htdocs folder, rather they’re in my user folder, under local host ( users/patrickmeaney/localhost/bobsuits/ ) I dunno if that matters…

My connect file
[php]<?php

// Created BY Adam Khoury @ www.flashbuilding.com - 6/19/2008
/*
1: “die()” will exit the script and show an error statement if something goes wrong with the “connect” or “select” functions.
2: A “mysql_connect()” error usually means your username/password are wrong
3: A “mysql_select_db()” error usually means the database does not exist.
*/
// Place db host name. Sometimes “localhost” but
// sometimes looks like this: >> ???mysql??.someserver.net
$db_host = “localhost”;
// Place the username for the MySQL database here
$db_username = “root”;
// Place the password for the MySQL database here
$db_pass = “root”;
// Place the name for the MySQL database here
$db_name = “suitstore”;

// Run the actual connection here
mysql_connect("$localhost","$builder2","$builder2") or die (“could not connect to mysql”);
mysql_select_db("$suitstore") or die (“no database”);
?>[/php]

My test file:

[php] <?php
// Connect to the file above here
error_reporting(E_ALL); ini_set(‘display_errors’, 1);
require_once(“storescripts/connect_to_mysql.php”);

echo "<h1>Success in database connection! Happy Coding!</h1>";   

// if no success the script would have died before this success message
?>

[/php]

Thanks for your help!

[php]
$db_host = “localhost”;
$db_username = “root”;
$db_pass = “root”;

mysql_connect("$localhost","$builder2","$builder2") or die (“could not connect to mysql”);
[/php]

mysql_connect is not using the database variables.

[php]
mysql_connect($db_host, $db_user, $db_pass) or die (“could not connect to mysql”);
[/php]

Hi Matt,

Thanks for the help man. I fixed that though, and it still doesn’t work. After fixing it, I got the same error. Then I changed the test file. And now I have a new error.

Here is the error:

///////// error //////////

Warning: require_once(/Users/patrickmeaney/localhost/BobsSuits/storescripts): failed to open stream: Not a directory in /Users/patrickmeaney/localhost/bobssuits/test.php on line 4

Fatal error: require_once(): Failed opening required ‘/Users/patrickmeaney/localhost/BobsSuits/storescripts’ (include_path=’.:/Applications/MAMP/bin/php/php5.4.4/lib/php’) in /Users/patrickmeaney/localhost/bobssuits/test.php on line 4

////////// error ///////////

Here is my code (its a lil different now)

connect file:
[php]<?php

// Created BY Adam Khoury @ www.flashbuilding.com - 6/19/2008
/*
1: “die()” will exit the script and show an error statement if something goes wrong with the “connect” or “select” functions.
2: A “mysql_connect()” error usually means your username/password are wrong
3: A “mysql_select_db()” error usually means the database does not exist.
*/
// Place db host name. Sometimes “localhost” but
// sometimes looks like this: >> ???mysql??.someserver.net
$db_host = “localhost”;
// Place the username for the MySQL database here
$db_username = “root”;
// Place the password for the MySQL database here
$db_pass = “root”;
// Place the name for the MySQL database here
$db_name = “suitstore”;

// Run the actual connection here
mysql_connect("$localhost","$root","$root") or die (“could not connect to mysql”);
mysql_select_db("$suitstore") or die (“no database”);
?>[/php]

test file:

[php] <?php
// Connect to the file above here
error_reporting(E_ALL); ini_set(‘display_errors’, 1);
require_once("/Users/patrickmeaney/localhost/BobsSuits/storescripts");

echo "<h1>Success in database connection! Happy Coding!</h1>";   

// if no success the script would have died before this success message
?>
[/php]

I really appreciate any help.

Btw, the fact that my root folder is not in mamp/htdocs is ok, right?

Are you using windows? If so you would need to specify the paths like this

[php]require_once(‘C:\localhost\Bobs…etc’);[/php]

Nope, using a Mac.

Do you think its ok that my root folder is not in my MAMP/htdocs folder?

I figured it out!

I simply needed this code in my connect file: (note the differences near the end of code when compared to the code I originally posted).

So, hopefully this helps out another newb :slight_smile:

[php]<?php

// Created BY Adam Khoury @ www.flashbuilding.com - 6/19/2008
/*
1: “die()” will exit the script and show an error statement if something goes wrong with the “connect” or “select” functions.
2: A “mysql_connect()” error usually means your username/password are wrong
3: A “mysql_select_db()” error usually means the database does not exist.
*/
// Place db host name. Sometimes “localhost” but
// sometimes looks like this: >> ???mysql??.someserver.net
$db_host = “localhost”;
// Place the username for the MySQL database here
$db_username = “root”;
// Place the password for the MySQL database here
$db_pass = “root”;
// Place the name for the MySQL database here
$db_name = “suitstore”;

// Run the actual connection here
mysql_connect(“localhost”,“root”,“root”) or die (“could not connect to mysql”);
mysql_select_db(“suitstore”) or die (“no database”);
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service