Jump to content

MySQL could not connect...


wmguk

Recommended Posts

Hi,

 

I have a script, and the connect script is in the correct folder etc.. however when i view the page it doesnt load properly and then if i view the source it says Could not connect, and everything stops (it doesnt even give the error or finish loading the page

 

<?php
include "../admin/scripts/connection.php";  
if (!$con)  
{  
  die( 'Could not connect: ' . mysql_error() );  
} 
mysql_select_db($db, $con); 

$sqlcms = "SELECT * FROM cmssystem WHERE active = 'yes'"; 
$resultcms = mysql_query( $sqlcms ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sqlcms<br><br>" ); 

while($row = mysql_fetch_array($resultcms)) 
{ 
?>
<li><a href="../admin/cms/edit.php?name=<?php echo $row['name']; ?>"><?php echo $row['displayname']; ?></a></li>
<?php
}
?>

 

is there anything obvious?

Link to comment
Share on other sites

<?php

$host = "localhost"; //Host name

$dbUser = "XXX"; //MySQL Username

$dbPass = "XXXX"; //MySQL Password

$db = "XXXX" ; //Database name

 

$con = mysql_connect($host,$dbUser,$dbPass) or die(mysql_error());

mysql_select_db($db, $con) or die(mysql_error());

?>

Link to comment
Share on other sites

this is the page script:

 

<?php
session_start(); 
if (!isset($_SESSION['username'])) {
header('Location: http://www.XXXXXX.co.uk/admin');
    exit; } 
$name = $_SESSION['name'] ;
$admin = $_SESSION['admin'];
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/admin.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>XXXXX is a highly professional and Independent Recruitment Agency</title>
<link href="../../XXXXX.css" rel="stylesheet" type="text/css" />

<script src="../../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<link href="../../SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<script src="../../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<link href="../../SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
</head>

<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2" align="center"><img src="../../images/demotop.gif" alt="XXXXX" width="800" height="122" /></td>
  </tr>
  <tr>
    <td height="21" bgcolor="#006699"><span class="adminheader">   Welcome to the XXXXXX Control Panel</span></td>
    <td align="right" bgcolor="#006699"><span class="adminheader">You are currently logged in as: <? echo $name ; ?>   </span></td>
  </tr>
  <tr>
    <td colspan="2" align="right" class="header">User Level: <? echo $admin; ?>   </td>
  </tr>
  <tr>
    <td colspan="2"><table width="100%" border="0" cellspacing="10" cellpadding="0">
      <tr>
        <td align="left" valign="top">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              
              <tr>
                <td width="130" valign="top"><ul id="MenuBar1" class="MenuBarVertical">
                  <li><a class="MenuBarItemSubmenu" href="../main.php">Clients</a>
                      <ul>
                        <li><a href="../clientlist.php">View List</a></li>
                        <li><a href="../create.php?type=client">Create Client</a></li>
                        <li><a href="../amend.php?type=client">Amend Client</a> </li>
                        <li><a href="../create.php?type=contact">Create Contact</a></li>
                        <li><a href="../amend.php?type=contact">Amend Contact</a></li>
                      </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">General Admin</a>
                    <ul>
                      <li><a href="../sector.php">Business Sector</a></li>
                    </ul>
                    </li>
                  <li><a class="MenuBarItemSubmenu" href="../main.php">Candidates</a>
                      <ul>
                        <li><a href="#">View List</a></li>
                        <li><a href="../create.php?type=candidate">Create Candidate</a></li>
                        <li><a href="../amend.php?type=candidate">Amend Candidate</a></li>
                      </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">Prospective Clients</a>
                    <ul>
                      <li><a href="../prospectlist.php">View List</a></li>
                      <li><a href="#">Add Prospect</a></li>
                      <li><a href="#">Amend Prospect</a></li>
                    </ul>
                    </li>
                  <li><a href="../main.php" class="MenuBarItemSubmenu">Communications</a>
                    <ul>
                      <li><a href="#">Client Communications</a></li>
                      <li><a href="#">Candidate Communications</a></li>
                    </ul>
                    </li>
                  <li><a href="../main.php" class="MenuBarItemSubmenu">Cowper Staff</a>
                      <ul>
                        <li><a href="create.php">Create Staff</a></li>
                        <li><a href="edit.php">Edit Staff</a></li>
                        <li><a href="delete.php">Delete Staff</a></li>
                      </ul>
                  </li>
                  <li><a href="../main.php" class="MenuBarItemSubmenu">Main Website</a>
				  <ul>
<?php
include "../admin/scripts/connection.php";  
if (!$con)  
{  
  die( 'Could not connect: ' . mysql_error() );  
} 
mysql_select_db($db, $con); 

$sqlcms = "SELECT * FROM cmssystem WHERE active = 'yes' && team != '1'"; 
$resultcms = mysql_query( $sqlcms ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sqlcms<br><br>" ); 

while($row = mysql_fetch_array($resultcms)) 
{ 
?>
<li><a href="../cms/edit.php?name=<?php echo $row['name']; ?>"><?php echo $row['displayname']; ?></a></li>
<?php
}
?>

                        <li><a href="../cms/theteam.php" class="MenuBarItemSubmenu">Our Team</a>
                          <ul>
<?php
$sqlteam = "SELECT * FROM cmssystem WHERE active = 'yes' && team == '1'"; 
$resultteam = mysql_query( $sqlteam ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sqlteam<br><br>" ); 

while($row = mysql_fetch_array($resultteam)) 
{ 
?>
<li><a href="../cms/edit.php?name=<?php echo $row['name']; ?>"><?php echo $row['displayname']; ?></a></li>
<?php
}
?>

                          </ul>
                        </li>
                        <li><a href="../cms/contact.php">Contact Us</a></li>
                      </ul>
                  </li>
                  <li><a href="../main.php">Timesheets</a></li>
                  <? if ($admin == 'User')
                  { } else {?>
                  <li><a href="../main.php" class="MenuBarItemSubmenu">Reports</a>
                    <ul>
                      <li><a href="#" class="MenuBarItemSubmenu">Current</a>
                        <ul>
                          <li><a href="#">Report 1</a></li>
                          <li><a href="#">Report 2</a></li>
                        </ul>
                        </li>
                      <li><a href="#" class="MenuBarItemSubmenu">Archived</a>
                        <ul>
                          <li><a href="#">Report 1</a></li>
                          <li><a href="#">Report 2</a></li>
                        </ul>
                        </li>
                    </ul>
                    </li><?php } ?>
                </ul></td>
                <td align="left" valign="top"><!-- InstanceBeginEditable name="mainpage" -->
                  <table width="600" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#006699" background="../../images/pageback.gif">
                    <tr>
                      <td bgcolor="#006699" class="adminheader">Staff Editing Page</td>
                    </tr>
                    <tr>
                      <td><p class="general">Please select the member of staff below:</p>
                        <p class="general">
                        <form>
			<select name="direct" class="general" onchange="if(this.selectedIndex) document.getElementById('editu').src = 'editu.php?username='+this.options[this.selectedIndex].value;">
                <option selected="selected">- Select -</option>
<?php 
/*
include "../scripts/connection.php";  
if (!$con)  
{  
  die( 'Could not connect: ' . mysql_error() );  
} 
mysql_select_db($db, $con); 

$sql = "SELECT * FROM users"; 
$result = mysql_query( $sql ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sql<br><br>" ); 
*/
while($row = mysql_fetch_array($result)) 
{ 
			echo "<option value=". $row['username'] . ">". $row['name'] . "</option>";
}
?>

              </select>
            </form>
</p>
<iframe id="editu" width="500" height="300" frameborder="0" scrolling="no" src="blankpage.html"></iframe>
                      </td>
                    </tr>
                  </table>
                  <p class="general">
                <!-- InstanceEndEditable --></td>
              </tr>
            </table>            
          <script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"});
//-->
            </script>        </td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="2" align="center" bgcolor="#006699">    <table width="800" border="0" cellspacing="3" cellpadding="0">
      <tr>
        <td><span class="adminheader">©2008 XXXX Limited.</span></td>
        <td align="right" class="adminheader">Telephone: XXX</td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>

Link to comment
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/admin.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>XXXXLimited is a highly professional and Independent Recruitment Agency</title>

<link href="../../XXXX.css" rel="stylesheet" type="text/css" />

<script src="../../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<link href="../../SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<script src="../../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<link href="../../SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
</head>

<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2" align="center"><img src="../../images/demotop.gif" alt="XXXXLimited is a highly professional and Independent Recruitment Agency" width="800" height="122" /></td>
  </tr>
  <tr>
    <td height="21" bgcolor="#006699"><span class="adminheader">   Welcome to the XXXXXControl Panel</span></td>
    <td align="right" bgcolor="#006699"><span class="adminheader">You are currently logged in as: XXX   </span></td>
  </tr>
  <tr>
    <td colspan="2" align="right" class="header">User Level: Administrator   </td>
  </tr>
  <tr>
    <td colspan="2"><table width="100%" border="0" cellspacing="10" cellpadding="0">
      <tr>
        <td align="left" valign="top">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              
              <tr>
                <td width="130" valign="top"><ul id="MenuBar1" class="MenuBarVertical">
                  <li><a class="MenuBarItemSubmenu" href="../main.php">Clients</a>
                      <ul>
                        <li><a href="../clientlist.php">View List</a></li>
                        <li><a href="../create.php?type=client">Create Client</a></li>
                        <li><a href="../amend.php?type=client">Amend Client</a> </li>
                        <li><a href="../create.php?type=contact">Create Contact</a></li>
                        <li><a href="../amend.php?type=contact">Amend Contact</a></li>
                      </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">General Admin</a>
                    <ul>
                      <li><a href="../sector.php">Business Sector</a></li>
                    </ul>
                    </li>
                  <li><a class="MenuBarItemSubmenu" href="../main.php">Candidates</a>
                      <ul>
                        <li><a href="#">View List</a></li>
                        <li><a href="../create.php?type=candidate">Create Candidate</a></li>
                        <li><a href="../amend.php?type=candidate">Amend Candidate</a></li>
                      </ul>
                  </li>
                  <li><a href="#" class="MenuBarItemSubmenu">Prospective Clients</a>
                    <ul>
                      <li><a href="../prospectlist.php">View List</a></li>
                      <li><a href="#">Add Prospect</a></li>
                      <li><a href="#">Amend Prospect</a></li>
                    </ul>
                    </li>
                  <li><a href="../main.php" class="MenuBarItemSubmenu">Communications</a>
                    <ul>
                      <li><a href="#">Client Communications</a></li>
                      <li><a href="#">Candidate Communications</a></li>
                    </ul>
                    </li>
                  <li><a href="../main.php" class="MenuBarItemSubmenu">Cowper Staff</a>
                      <ul>
                        <li><a href="create.php">Create Staff</a></li>
                        <li><a href="edit.php">Edit Staff</a></li>
                        <li><a href="delete.php">Delete Staff</a></li>
                      </ul>
                  </li>
                  <li><a href="../main.php" class="MenuBarItemSubmenu">Main Website</a>
				  <ul>
Could not connect: 

 

this is the source of the page that is displayed

Link to comment
Share on other sites

thats what i mean, the page stops..... there is nothing at all after could not connect:

 

(I ran

 

<?php

// we connect to your website

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

if (!$link) {

    die('Could not connect: ' . mysql_error());

}

echo 'Connected successfully';

mysql_close($link);

 

?>

 

and got connected successfully

Link to comment
Share on other sites

hmmm, that failed so I just made a new page:

 

<?php

$host = "localhost"; //Host name
$dbUser = "XXX"; //MySQL Username
$dbPass = "XXX"; //MySQL Password
$db = "X_X" ; //Database name 

$con = mysql_connect($host,$dbUser,$dbPass) or die(mysql_error());
if (!$con)  
{  
  die( 'Could not connect: ' . mysql_error() );  
} 
mysql_select_db($db, $con) or die(mysql_error());

$sqlcms = "SELECT * FROM cmssystem WHERE active = 'yes' && team != '1'"; 
$resultcms = mysql_query( $sqlcms ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sqlcms<br><br>" ); 

while($row = mysql_fetch_array($resultcms)) 
{ 
?>
<li><a href="../admin/cms/edit.php?name=<?php echo $row['name']; ?>"><?php echo $row['displayname']; ?></a></li>
<?php
}
?>

 

and it worked fine, so there must be a code issue....

Link to comment
Share on other sites

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.