darkwaters Posted February 4, 2007 Share Posted February 4, 2007 Hi there, I'm new to PHP and MySQL. I've self studied the basics online and I have worked through the basics by doing practical examples which I found on w3school.com. I am now trying to connect to and create a database through an example I'm working through. I don't have a localhost so I'm testing my work online with a page that is not linked to my site. In saying that, here is the code I a using: line) 1) <!-- Connecting and creating a table with PHP and MySQL --> 2) <?php 3) $con = mysql_connect("world-casino-guide.com","username","password"); 4) if (!$con) 5) { 6) die('Could not connect: ' .mysql_error()); 7) } // Create Database "newsletter" if (mysql_query("CREATE DATABASE newsletter", $con)) { echo "Database Created"; } else { echo "Error Creating Database: " . mysql_error(); } // Create Table "registrations" in "newsletter" database mysql_select_db("newsletter", $con); $sql = "CREATE TABLE registrations ( Name varchar(25), Email varchar(50), PRIMARY KEY(Email), Casino varchar(10), Poker varchar(10), Bingo varchar(10), )"; mysql_query($sql,$con); mysql_close($con); ?> However, when I upload and run the page, I receive this error: Warning: mysql_connect(): Can't connect to MySQL server on 'world-casino-guide.com' (111) in /home/content/d/o/n/username/html/wcg_new_design/include_mysql_test1.php on line 3 Could not connect: Can't connect to MySQL server on 'world-casino-guide.com' (111) I'm not sure how to resolve the above. Can anyone help me with this? My final goal is to have a double opt. in registration system. I do however want to learn at the same time so happy to work through the basics. If anyone could provide further information or code to have a double opt in system, it would be much appreciated. Thanks, Douglas Link to comment https://forums.phpfreaks.com/topic/37013-connecting-to-a-php-database/ Share on other sites More sharing options...
only one Posted February 4, 2007 Share Posted February 4, 2007 make sure you are connecting to the mysql server mysql_connect("world-casino-guide.com","username","password"); world-casino-guide.com is the web adress but not the place where the databases are stored Link to comment https://forums.phpfreaks.com/topic/37013-connecting-to-a-php-database/#findComment-176706 Share on other sites More sharing options...
.josh Posted February 4, 2007 Share Posted February 4, 2007 unless you are trying to access a database on some other server than the one the script is being run on, you should be able to use "localhost" as the server name. Link to comment https://forums.phpfreaks.com/topic/37013-connecting-to-a-php-database/#findComment-176729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.