Go Back   HostGator Peer Support Forums > HostGator Peer Support Forums > Shared Hosting Support

Notices

Reply
 
Thread Tools
  #1  
Old 04-22-2008, 05:37 PM
atrigg atrigg is offline
Hatchling Croc
 
Join Date: Apr 2008
Posts: 2
Default Problems accessing SQL

Hi There, i do not want to bug support as its probably my error

I am new to SQL and PHP and have created a database and table and have all that ready

but i cannot connect to the database when trying to insert new values from a PHP page

The following is the 'latest' example that i used and is currently giving me 500 internal server error' message

-------------------------
<html>
<head>
<title>Untitled Document</title>
</head>
<body><?php
$name=$_POST['name'];
$cid=$_POST['cid'];
$phone=$_POST['phone'];
$contact=$_POST['contact'];
$tsales=$_POST['tsales'];
$f2f=$_POST['f2f'];
$date=$_POST['date'];
$dbh=mysql_connect ("localhost", "atrigg_admin", "admin") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("atrigg_LMT");
mysql_query("INSERT INTO `people` VALUES ('$name', '$cid','$phone','$contact','$tsales','$f2f', '$date')");
Print "Your information has been successfully added to the database.";
?>
</body>
</html>

----------------------------------
Now, is there anything i have wrong in the above, and yes, i have created the user for the database with full privilages, and the table name is people

Also.... i tried a slight variation, which is

----------------------------------
<html>
<head>
<title></title>
</head>
<body><?php
$name=$_POST['name'];
$cid=$_POST['cid'];
$phone=$_POST['phone'];
$contact=$_POST['contact'];
$tsales=$_POST['tsales'];
$f2f=$_POST['f2f'];
$date=$_POST['date'];
$dbh=mysql_connect ("localhost", "atrigg_admin", "admin") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("atrigg_LMT");
mysql_query("INSERT INTO `people` VALUES ('$name', '$cid','$phone','$contact','$tsales','$f2f', '$date')");
Print "Your information has been successfully added to the database.";
?></body>
</html>
_---------------------------------------------

What am i doing wrong, help!
Reply With Quote
  #2  
Old 04-22-2008, 05:38 PM
atrigg atrigg is offline
Hatchling Croc
 
Join Date: Apr 2008
Posts: 2
Default Re: Problems accessing SQL

Hmmm, i appear to have solved it, somehow, the second one decided to work now, dunno why.....

I shall do a happy dance now!
Reply With Quote
Reply

Bookmarks

Thread Tools

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

Forum Jump

All times are GMT -5. The time now is 11:55 PM.