Jump to content

need help with php coding keep getting error


jman226

Recommended Posts

Keep getting this error no matter what I try :

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\a5Project.php on line 74

 

 

 

 

 

 

<?php
    require_once('auth.php');
    //*********************************************************************************
    //             a5Project.PHP  using the ProgrammingDatabase
    //
    //This is your PHP page code stub. You are to use this page to list the slips,
    //boat names and boat types from the ProgrammingDatabase.
    //
    //The user will then input a Cust_Num and you will use the PHP code stub page
    // named aServices_Student to list the service ID and descriptions for the slip
    //the user has entered.
    //
    //Use aOwner_Example.php and aBoats_Example.php as code templates to complete the
    //assignment. Good luck with it!
    //*********************************************************************************
?>
<!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"><!-- 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>
    <link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>

<body>
    <div id="innerWrapper">
<h1>Database queries for Final Project<?php echo $_SESSION['SESS_FIRST_NAME'];?></h1>

<a href="index.php">Login Page</a> |
<a href="amenu.php">Menu Page</a> |
<a href="logout.php">Logout</a>

<h2>List of Customers</h2>
    
<?php
//Verified passwords
$vlogin=$_SESSION['vlogin'];
$vpassword=$_SESSION['vpasswd'];

//set up your connection string
$con = mysql_connect("localhost",$vlogin,$vpassword); //CASE SENSITIVE

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

// select the database to use
mysql_select_db("projectdb", $con);

//The actual SQL code goes below into the structured variable $result
$result = mysql_query("SELECT cust_num, customer_name, contact, contact_phone FROM cust");

//constructing the table and column names
echo "<table border=''>
<tr>
<th>Cust Num</th>
<th>Customer Name</th>
<th>Contact</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
//do the while loop below with the variables from $result

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['cust_num'] . "</td>";
  echo "<td>" . $row['customer_name'] . "</td>";
  echo "<td>" . $row['contact'] . "</td>";
  echo "<td>" . $row['contact_phone'] . "</td>";
  echo "</tr>";
  }

echo "</table>";  


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

//The following stuff after PHP gets the customer number then calls a5projectb.php
?>
<br />
<form action="a5projectb.php " method="post">

Enter the Customer Number for Representative Customer has worked with: <input type="text" name="cust_num" />
<br />
<br />
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="submit" value="Submit" /><input type="Reset"  value="Reset">
[<a href="aMenu.php">Return to home page</a>]
</form>
</div>
    
</body>



</html>

That error is a sign that your query failed and so $result contains"false" instead of a valid result set.

 

outputting mysql_error() after calling the query will tell you why.

 

It may be because you are using $_SESSION data without calling session_start() at the top of the script and so the connection fails.

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.