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>

Link to comment
Share on other sites

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.

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.