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
(#11 (permalink))
Old
Junior Member
phalbachjr is on a distinguished road
 
Posts: 9
Join Date: Nov 2010
Default 11-29-2010, 03:04 PM

Ok, I added the query to my php page. Below is a copy of the what it looks like. When I run it the database creates a new record but does not enter any information into it. Every suggestion has moved us closer to the solution but I'm still a few steps away.

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

//connection to the database
$conn=mysql_connect ("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')";
$result = mysql_query($data) or die(mysql_error());


echo "Your Information Has Been Added";

$insert = "INSERT INTO Email (Name, Address) VALUES ('".$Name."','".$Address."')";
$result = mysql_query($insert) or die(mysql_error());


?>
Reply With Quote
Sponsored Links
(#12 (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, 03:18 PM

Here´s an example that is working for me. Very basic, but does the job. You just need to replace the values for your fields/variables/mysql to match yours
PHP Code:
<?php
$name 
$_POST['name']; //pass the name from your HTML form
$email $_POST['email']; //pass the email from your HTML form

//connect to the database
$conn=mysql_connect ("server""user""password") or die ('I cannot connect to the database because: ' mysql_error());
mysql_select_db("name_of_your_database");

//prepare and execute the query
$data "INSERT INTO details (name,email) VALUES ('$name', '$email')";
$result mysql_query($data) or die(mysql_error());

//ouput information after adding
echo "Your Information Has Been Added";
?>
Reply With Quote
(#13 (permalink))
Old
Junior Member
phalbachjr is on a distinguished road
 
Posts: 9
Join Date: Nov 2010
Default 11-29-2010, 03:40 PM

THANK YOU SO VERY MUCH!!! It worked with modifying your code to match my info!!

THANK YOU ALL FOR TAKING TIME OUT TO HELP ME!!!! YOU ARE ALL AWESOME!!!
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