Jump to content

mysql_fetch_array() expects parameter 1 to be resource, boolean is given


SK1990

Recommended Posts

I'm trying to embed a sql query into my php on my html page. I keep getting the error mysql_fetch_array() expects parameter 1 to be resource, boolean is given. What am I doing wrong? (Please note I'm not well versed in PHP and need specific directions on how to change my code)

<?php
require_once('auth.php');
?>
<html>
<!-- This is the stub page for tying in your final project database into the 
	website
-->

<!-- Don't forget to add premissions to your final project database 
	so that your user can access it 
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title>Final Project</title>
</head>

<body>

<h1>Final project page <?php echo $_SESSION['SESS_FIRST_NAME'];?></h1>

<p>This is where you will link in your final project database</p></br>

<p>Good luck!</p></br>

<div id="innerWrapper">

<!--start of sql embedding -->
	
<a href="index.php">Login Page</a> | 
<a href="amenu.php">Menu Page</a> | 
<a href="logout.php">Logout</a>

<h2>Customer Contact Info:</h2>
	
<?php
//Verified passwords
$vlogin=$_SESSION['vlogin'];
$vpassword=$_SESSION['vpasswd'];

//This is the connection string for the database, server, username and password

$con = mysql_connect("localhost",$vlogin,$vpassword); //CASE SENSITIVE

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

//This is the connection string for the database, server, username and password

$con = mysql_connect("localhost",$vlogin,$vpassword); //CASE SENSITIVE

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
// Actually using the connection string and connecting to the database like the 'use' command
mysql_select_db("finalprojectdb", $con);

//The actual SQL code that will return a table structure into the local variable $result
//Important note, PHP variables are case sensitive
$result = mysql_query("SELECT Cust_Num, Contact_Name, Contact_Phone from Customer order by Cust_Num");

//constructing the table and column names
//ECHO allows HTML to go through PHP to the server
echo "<table border=''>
<tr>
<th>Customer Number</th>
<th>Contact Name</th>
<th>Contact Phone</th>
</tr>";

// Looping until there are no more records from $result
//If there are records, print the colum for that row
//also ECHO allows HTML to pass through PHP
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['CUST_NUM'] . "</td>";
  echo "<td>" . $row['CONTACT_NAME'] . "</td>";
  echo "<td>" . $row['CONTACT_PHONE'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

//Closing the SQL connection string
mysql_close($con);
?>

</div>

<div>
	[<a href="aMenu.php">Return to home page</a>]
</div>

</body>

</html>

try

$result = mysql_query("SELECT Cust_Num, Contact_Name, Contact_Phone from Customer order by Cust_Num");
if (!$result) die(mysql_error());

Post any error message that it outputs

do some error checking, the error you are getting is because the query could not successfully execute, hence no resource. try this:

$result = mysql_query("SELECT Cust_Num, Contact_Name, Contact_Phone from Customer order by Cust_Num") or die(mysql_error());

//that will tell you what is wrong with your query

Archived

This topic is now archived and is closed to further replies.

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