Jump to content

Newb Question - Connection to DB


DanDemole

Recommended Posts

VERSION: MySQL 5.0.24

 

So I am trying to get going on my first PHP / MYSQL connection.

 

I have a html page that loads my search.php function and runs it.

 

Here is the code snippet of search.php

[pre]

<?php
$dbhost='www.freesql.org'; 

$dbuser='jingle'; 
$dbpass='REMOVED'; 
$dbname='jingle'; 

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die("Could not connect to MySQL server!" . mysql_error()); 

mysql_select_db("$dbname") or die ("could not open db".mysql_error());


$term = $_POST['term'];

$sql = mysql_query("select * from jingle where Sounds_Like like '%$term%'");

while ($row = mysql_fetch_array($sql)){
echo '<br/> Song Title: '.$row['Song_Title'];
echo '<br/> Writer: '.$row['Writer'];
echo '<br/> Track_Length: '.$row['Track_Length'];
echo '<br/><br/>';
}

?>

[/pre]

 

 

When I run this, I get the following error:

[pre]

Warning: mysql_connect() [function.mysql-connect]: in /mnt/w0713/d45/s27/b02794d9/www/jingle/search.php on line 8
Could not connect to MySQL server!

[/pre]

 

I have tried switching around the variables for direct calls and still the same error.

 

Can someone point out what I am missing?

 

Thanks,

Dan

Link to comment
https://forums.phpfreaks.com/topic/121365-newb-question-connection-to-db/
Share on other sites

Fenway's probably right, double check.

 

Actually check this line:

 

mysql_select_db("$dbname") or die ("could not open db".mysql_error());

 

I don't think you need quotes around $dbname.  Try:

 

mysql_select_db($dbname) or die ("could not open db".mysql_error());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.