connecting to database

This is a discussion on "connecting to database" within the PHP Forum section. This forum, and the thread "connecting to database are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 22nd, 2006, 23:05
Junior Member
Join Date: Jun 2006
Location: usa
Age: 29
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
connecting to database

I been trying to connecto to this database just to add content into a website but i can't connect to the database can anyone please help me here..


PHP: Select all

 
<?
$host 
="localhost";
$username ="silvapro_franknu";
$password ="abc123";
$database ="silvapro_prueba";
 
 
// artist.. 
$artist_name addslashes($artist_name);
$artist_releaseaddslashes($artist_release);
$artist_bio addslashes($artist_bio);
$artist_newsaddslashes($artist_news);
$artist_extraaddslashes($artist_extra);
$artist_pictureaddslashes($artist_picture);
 
$dbh=mysql_connect ("localhost""Silvapro_franknu ""abc123") or die ('I cannot connect to the database because: ' mysql_error());
mysql_select_db ("silvapro_prueba"); 
 
 
 
 
if(!
$db)
{
echo 
" Error: could not connect to database.";
 
}
 
//business owner
$sql="INSERT INTO `artist`(`artist_name`,`artist_release`,`artist_bio`,`artist_news`,`artist_extra`, `artist_picture`)
VALUES ('"
.$artist_name."','".$artist_release."','".$artist_news."','".$artist_extra."')";
$result mysql_query($sql);
echo 
mysql_error();
if(
$result)
{
echo 
mysql_affected_rows()." .artist information Inserted. <br>";
}
 
 
?>
<?php
echo "<br>";
print(
htmlspecialchars(dirname(__FILE__))."<br>");
 
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.
if(!empty($_FILES["picture1"]))
{
$uploaddir realpath("/home/silvapro/public_html");
var_dump($uploaddir);
var_dump($_FILES);
var_dump($_FILES["picture1"]["error"]);
if (
move_uploaded_file($_FILES["picture1"]["tmp_name"], $uploaddir $_FILES["picture1"]["name"])) {
echo(
"file uploaded");
} else {
echo (
"error!");
}
}
 
?>
the error message that i am getting is

Error: could not connect to database can anyone please tell me what is the deal here
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 22nd, 2006, 23:39
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: connecting to database

I use this to connect to my database

i
PHP: Select all

nclude_once("includes/connection.php");

mysql_connect($host,$user,$password);
@
mysql_select_db($database) or die( "Unable to select database"); 
connection.php has the username,password etc much like you put at the top...it's for added security.

Hope this helps
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 23rd, 2006, 00:15
Junior Member
Join Date: Jun 2006
Location: usa
Age: 29
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Re: connecting to database

all the password and user name are fine it is something else that i am missing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 23rd, 2006, 00:21
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: connecting to database

Quote:
Originally Posted by franknu View Post
I been trying to connecto to this database just to add content into a website but i can't connect to the database can anyone please help me here..


[php]

$dbh=mysql_connect ("localhost", "Silvapro_franknu ", "abc123") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("silvapro_prueba");




if(!$db)
{
echo " Error: could not connect to database.";

}

That could be you problem
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jul 23rd, 2006, 08:39
Up'n'Coming Member
Join Date: Jan 2006
Location: East Sussex
Age: 27
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: connecting to database

looks like you havent defined $db anywhere which is why it always shows the error message.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
connecting, database

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
connecting to CSV file madhuri.t Classic ASP 0 Jul 10th, 2006 13:50
connecting to CSV file madhuri.t Classic ASP 1 Jul 8th, 2006 09:36
problems connecting to database benbacardi Classic ASP 8 Apr 15th, 2005 16:16
connecting to web-email via pop using php... Billydakid PHP Forum 7 Feb 12th, 2004 08:42
Connecting to my Database.... courtjester Classic ASP 3 Jan 16th, 2004 09:11


All times are GMT. The time now is 16:19.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42