DanDemole Posted August 26, 2008 Share Posted August 26, 2008 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 More sharing options...
JasonLewis Posted August 26, 2008 Share Posted August 26, 2008 Run a PHP page with this in it: <?php phpinfo(); ?> And do a search for "mysql" and make sure that it is there. Are you running it off your own computer? If you have something like WAMP Server you can. Link to comment https://forums.phpfreaks.com/topic/121365-newb-question-connection-to-db/#findComment-625743 Share on other sites More sharing options...
fenway Posted August 26, 2008 Share Posted August 26, 2008 Sounds like you have the wrong login credentials. Link to comment https://forums.phpfreaks.com/topic/121365-newb-question-connection-to-db/#findComment-625990 Share on other sites More sharing options...
Maq Posted August 26, 2008 Share Posted August 26, 2008 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()); Link to comment https://forums.phpfreaks.com/topic/121365-newb-question-connection-to-db/#findComment-626016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.