954,116 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Form, SQL connectivity issues, please help.


<?php

$hostname = "myhostname";
$username = "myusername";
$password = "mypassword";
$dbname = "mydbname";
$sqlConn=@mssql_connect($hostname, $username, $password);

$query = "SELECT * FROM mytable ORDER BY fname";
$result = mysql_query($query) or die ("Query failed");
//number of rows in our result for loop
$numofrows = mysql_num_rows($result);

echo "\n";
echo "First NameLast NameE-mail\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from result set
if($i % 2) { //if there is a remainder
echo "\n";
} else { //if there isn't a remainder
echo "\n";
}
echo "".$row['fname']."".$row['lname']."".$row['email']."\n";
echo "\n";
}
//now let's close the table and be done with it
echo "\n";

?>

NolanVW
Newbie Poster
12 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

You have to indicate/select the database before the query is placed
[php]$dbhost = "hostname";
$dbuser = "dbuser";
$dbpass = "dbpwd";
$database = "dbname";

$sqlConn = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Unable to connect!");
mysql_select_db($database) or die ("Unable to open database!");[/php]
The digit after the hostname is not necessary.

zippee
Posting Whiz in Training
294 posts since Jan 2005
Reputation Points: 10
Solved Threads: 7
 

Notice they are using a mssql connection, not mysql, they may need to specify the port to make a connection, depending on the MS SQL server is configured.

Zachery
The Geek Father
Team Colleague
894 posts since Nov 2003
Reputation Points: 96
Solved Threads: 21
 
Notice they are using a mssql connection, not mysql, they may need to specify the port to make a connection, depending on the MS SQL server is configured.

yep....just realized that and got it straightened out with our hosting company. Just had to switch from SQL Server to MySQL since it was originally set up with SQL server....thanks for the help everyone.

NolanVW
Newbie Poster
12 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

The 4 digits after the hostname are the port number

phper
Posting Whiz in Training
213 posts since Nov 2006
Reputation Points: 22
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You