Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page Can not connect with DB.
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
Junior Member
phalbachjr is on a distinguished road
 
Posts: 9
Join Date: Nov 2010
Default Can not connect with DB. - 11-28-2010, 06:00 PM

I'm new to php so I need help from anyone who knows what they are doing.

I've created a simple database to collect names and email addresses from those who want to receive an email from me. I have set up the db but I cannot get my webform to connect with the database. Below is the code I'm using but all that I get is "Page can not be found". I have blocked out the password for the database.

THANK YOU!!!!

<?php
$username = "a5134213_pth";
$password = "****";
$hostname = "http://mysql13.000webhost.com";

//connection to the database
$conn=mysql_connect ("http://mysql13.000webhost.com", "a5134213_pth", "****") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("a5134213_emad");

//select a database to work with
$selected = mysql_select_db("a5134213_emad")
or die("Could not select that database");



$data = "INSERT INTO email (name,address) VALUES ('$name', '$address')";



echo "Your Information Has Been Added";

$insert = "INSERT INTO table (name, address)
VALUES ('".$name."','".$address."')";

?>

Last edited by phalbachjr; 11-29-2010 at 03:04 PM.
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 4,609
Join Date: Jul 2009
Location: Spain
Default 11-28-2010, 06:42 PM

You can try change $hostname.

Where you are writed "http://mysql13.000webhost.com" you can write "mysql13.000webhost.com"

You could talk what error is you getting.


Si este mensaje te ha servido de ayuda no dudes en pulsar sobre el botón karma
Reply With Quote
(#3 (permalink))
Old
Junior Member
phalbachjr is on a distinguished road
 
Posts: 9
Join Date: Nov 2010
Default 11-28-2010, 08:52 PM

Thank you very much for taking a look at this for me.

I have made the change in the hostname but it still comes up as page not found "HTTP 404". Any clue as to what else I'm doing wrong?

I have read other posts where people can not connect to a db and some of the replies have been to use the IP address since some servers have DNS issues. I don't know what teh IP address is for mysql13.000webhost.com.
Reply With Quote
(#4 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 4,609
Join Date: Jul 2009
Location: Spain
Default 11-29-2010, 05:13 AM

Hi phalbackhjr,

If you have a 404 probably the problem is elsewhere.

If the mistake was connecting to the server for the database you would get the error that you have set in your code "I cannot connect to the database because:..."
and if not found the table in your database would get the other error that you put in your code "Could not select that database".

The error 404 is "web page not found", which has little to do with the error of connection to the database. Check your file name and where you saved it.


Si este mensaje te ha servido de ayuda no dudes en pulsar sobre el botón karma
Reply With Quote
(#5 (permalink))
Old
Junior Member
spiritnhiding is on a distinguished road
 
Posts: 4
Join Date: Jan 2010
Default 11-29-2010, 11:14 AM

Have you tried just putting $hostname = "localhost"; instead of the actual host link? May help depending on your files you have uploaded.
Reply With Quote
(#6 (permalink))
Old
Bad Karma[CORE]'s Avatar
Guilty as charged
Bad Karma[CORE] is on a distinguished road
 
Posts: 6,133
Join Date: May 2008
Default 11-29-2010, 11:19 AM

"localhost" won´t work as you need to specify the actual servername (mysql*.000webhost.com).

* stands for the number of the mysql server you have to use, which one it is can be found in your control panel under "MySQL"
Reply With Quote
(#7 (permalink))
Old
Junior Member
spiritnhiding is on a distinguished road
 
Posts: 4
Join Date: Jan 2010
Default 11-29-2010, 01:57 PM

Not precisely correct, I run a game, and have used localhost instead of the actual server name, so you said it wouldnt work that is wrong!
Reply With Quote
(#8 (permalink))
Old
Bad Karma[CORE]'s Avatar
Guilty as charged
Bad Karma[CORE] is on a distinguished road
 
Posts: 6,133
Join Date: May 2008
Default 11-29-2010, 02:06 PM

Quote:
Originally Posted by spiritnhiding View Post
Not precisely correct, I run a game, and have used localhost instead of the actual server name, so you said it wouldnt work that is wrong!
If hosting a site here you will have to use the correct mysql server name as localhost does not work. Therefore the answer i gave was correct.
Reply With Quote
(#9 (permalink))
Old
Junior Member
phalbachjr is on a distinguished road
 
Posts: 9
Join Date: Nov 2010
Default 11-29-2010, 02:10 PM

Great, I figured out why I was getting the HTTP 404 error and have corrected that. Thank again.

Now I run the form, input some data and I receive the message "Your Information Has Been Added" but there are no records inserted into my database when I go back and check it. I am not receiving any error messages but its not connecting.

Thank again for looking at this for me. I'm new to this and I have no idea what I'm doing.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com