Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with MySQL connection

Status
Not open for further replies.

mrsbean

Technical User
Jul 14, 2004
203
US
Dear Great Ones,

I admittedly don't know what I'm doing, and I'll take all the help I can get.

The following part of the code works:

Code:
<?
include("dbconnection.php");
include_once("header.php");

blah blah blah 
form data

include_once("footer.php");
?>

The following code in the footer doesn't work <i>when there has been some connection above.</i> If the page that calls the footer did not have a connection, the footer code works. I also tried the include_once for the dbconnection, but that didn't make a difference.

Code:
<? 
include("dbconnection.php");
$SPhID = $_SESSION['userID'];

$sql = "SELECT  * FROM phUser WHERE phID = '$SPhID'";
$result = MYSQL_QUERY($sql);
$numberOfRows = MYSQL_NUMROWS($result);
if ($numberOfRows==0) {  
?>

Sorry. No records found !!
<?
}
else if ($numberOfRows>0) {

	$i=0;
	$thisPhID = MYSQL_RESULT($result,$i,"phID");
	$thisUserName = MYSQL_RESULT($result,$i,"userName");
	$thisUserPass = MYSQL_RESULT($result,$i,"userPass");
	$thisUserFirstName = MYSQL_RESULT($result, $i, "userFirstName");
	$thisUserLastName = MYSQL_RESULT($result, $i, "userLastName");
	$thisIsAdmin = MYSQL_RESULT($result,$i,"isAdmin");
	$thisUserGroup = MYSQL_RESULT($result,$i,"userGroup");
	$thisSessionID = MYSQL_RESULT($result,$i,"sessionID");
	$thisLastLog = MYSQL_RESULT($result,$i,"lastLog");
	$thisUserRemark = MYSQL_RESULT($result,$i,"userRemark");
	$thisUserEmail = MYSQL_RESULT($result,$i,"userEmail");
	$thisUserHomePhone = MYSQL_RESULT($result,$i,"userHomePhone");
	$thisUserCellPhone = MYSQL_RESULT($result,$i,"userCellPhone");
	$thisUserOtherPhone = MYSQL_RESULT($result,$i,"userOtherPhone");
	$thisUserWebsite = MYSQL_RESULT($result,$i,"userWebsite");
	$thisUserStatesLicensed = MYSQL_RESULT($result,$i,"userStatesLicensed");
	$thisUserDesignations = MYSQL_RESULT($result,$i,"userDesignations");
	$thisUserLanguages = MYSQL_RESULT($result,$i,"userLanguages");
	$thisUserSpecialties = MYSQL_RESULT($result,$i,"userSpecialties");

} ?>

<a href="[URL unfurl="true"]http://www.acertainwebsite.com/">main[/URL] website</a> 
 <?	   If ($thisIsAdmin !== 0) {
   echo "<a href = '[URL unfurl="true"]http://www.acertainwebsite.com/adminindex.php'>administrative[/URL] menu</a>";
   }
   ?>
</div>

<div id="left-menu">
<p>	<a href="[URL unfurl="true"]http://www.phoenicianproperties.com/">Main[/URL] Website</a></p>
<?	   If ($thisIsAdmin !== 0) {
   echo "<p><a href = '/phoenix/adminindex.php'>Administrative Menu</a></p>";
   }
   ?>

</div>

The error messages I get are as follows:

Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /a_certain_server .../common/footer.php on line 8

Warning: mysql_query(): A link to the server could not be established in /a_certain_server .../common/footer.php on line 8

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /a_certain_server ... /common/footer.php on line 9
Sorry. No records found !! main website administrative menu


What I'm trying to do is to include the administrative menu link if the currently logged in user is an administrator. I don't want it if they're not an administrator. I am use adminpro to secure the site. In spite of the errors which appear, the link for the administrative menu does appear when the user is an administrator. The errors are there, but the link appears, and it works.

Can somebody tell me how to fix?

MrsBean
 
The dbConnection works except as I outlined above. I was mistaken in my earlier post. When I get the errors, the link for the administrative portion of the site does not show up.

Code:
<?php

      $dbHostname = "mysql.myhostname.com";
      $dbUsername = "myusername";
      $dbPassword = "mypassword";
      $dbName     = "mydatabasename";      
       
      //  Make connection to database 
      //  If no connection made, display error Message          
      $dblink = MYSQL_CONNECT($dbHostname, $dbUsername, $dbPassword) OR DIE("Error !! Unable to connect to database");       
	       
	  
      // Select the database name to be used or else print error message if unsuccessful*/
      @mysql_select_db($dbName) or die( "Unable to select database ".$dbName); 

?>

Thanks for your help,

MrsBean
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top