Jump to content

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());

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.