Connecting to MySQL Database (1and1.co.uk)

Hi,

I’ll give as much detail as I can as I’m aware different servers respond in different ways.

I’m trying to learn how to build a PHP form which will write to a SQL database. My host is currently www.1and1.co.uk (though the SQL server carries a .com address).

I am using Webmatrix 2 to write the code, filezilla to upload to the FTP site and I upload the file to my 1and1.co.uk address.

Whenever I upload it will always load any text I put in my file in normal HTML but it won’t even recognize a hello world example like
[php]<? PHP
Print “Hello World”;
?>
[/php]

The code below is blanked as much as is needed to hide the log ins but no other changes have been made to the code. This includes the comments which I tried toying about with to see if I could get it to do some work for me!

[php]<?php
//ini_set(‘display_errors’,1);
//error_reporting(E_ALL);
//echo(“Starter for 10”);
$con = mysql_connect(“db4278xxxxx.db.1and1.com”, “dbo4278xxxxx”,“password used when setting up SQL database in 1and1 database”);
print “Connection”;
if (!$con){
die('Could not connect: '.mysql_error());
}

// print “If statement”;
mysql_select_db(“Logins”, $con);
// print “select db”;
$sql = ‘INSERT INTO Logins (Client_ID, Username, Password) VALUES (7, “Internet”, “Helper”)’;
mysql_query($sql);

mysql_close($con);

?>[/php]

the username, hostname and password are all specific to the SQL database and not the log in to the 1and1 admin account.

Any and all help would be amazing!

Thanks
Maudise

Are you actually connecting to the database?

If not then try changing

db4278xxxxx.db.1and1.com

to

localhost

Also try changing your print statements to echo

Is your table actually called Logins and not logins (case sensitive) also check your case sensitivity for your field names.

We really need a bit more information on any errors that you are getting.

Regarding the post by Aporponna:
Looks like forum moderators are lazy, seriously don’t ruin such an awesome community, be active.

On topic:

try
[php]

<?php echo "test"; ?>

[/php]

Let me know if it gets printed, if not you do not have a PHP processing webserver support.

Sponsor our Newsletter | Privacy Policy | Terms of Service