Google Answers Logo
View Question
 
Q: MySQL Database Connection ( No Answer,   2 Comments )
Question  
Subject: MySQL Database Connection
Category: Computers > Programming
Asked by: brettuzzi-ga
List Price: $9.50
Posted: 09 Dec 2004 14:16 PST
Expires: 10 Dec 2004 07:43 PST
Question ID: 440534
When attempting to store data in a MySQL database, it refuses to find
the database, thought I'm sure it is typed correctly (I am
copy/pasting it from phpMyAdmin). Here is the coding in question:

<?php
$username="username"; // Not actual username
$password="password"; // Not actual password
$database="brettuz_sdm"; // Copy and pasted from phpMyAdmin

$Time=$_POST['Time'];
*/ Submitted from a form, there are many variables, all in the same
fashion as this */

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO sdms VALUES ('','$Time')";

mysql_query($query1);
mysql_close();
?>

When submitting the form, I get a blank white page with "Unable to
select database" (just as specified in coding)

All my server host could tell me was "Check the database connection in
the page that the form submits to".... DUH =/

What is the problem here?

Clarification of Question by brettuzzi-ga on 09 Dec 2004 14:17 PST
the variable $query is $query1, typo. that's not the problem.
Answer  
There is no answer at this time.

Comments  
Subject: Re: MySQL Database Connection
From: shane43-ga on 09 Dec 2004 15:14 PST
 
Try removing the @ from your select_db call. That supresses the real error message.
Subject: Re: MySQL Database Connection
From: tequila2k-ga on 10 Dec 2004 02:48 PST
 
I think you'll need to quote the "localhost" reference in the
mysql_connect() function.

Also, you can use the function mysql_error() in your 'or die' messages
- this should give you a nice error. So try something like:


mysql_connect("localhost",$username,$password) or die("Could not
connect - ".mysql_error() );

@mysql_select_db($database) or die( "Unable to select database - ".mysql_error() );


Hope it helps,

Paul

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy