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>
Link to comment
Share on other sites

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