jman226 Posted May 18, 2015 Share Posted May 18, 2015 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 SENSITIVEif (!$con) { die('Could not connect: ' . mysql_error()); }// select the database to usemysql_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 namesecho "<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 $resultwhile($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 stringmysql_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 />                           <input type="submit" value="Submit" /><input type="Reset" value="Reset">[<a href="aMenu.php">Return to home page</a>]</form></div> </body></html> Quote Link to comment Share on other sites More sharing options...
Barand Posted May 18, 2015 Share Posted May 18, 2015 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. Quote Link to comment Share on other sites More sharing options...
grissom Posted May 19, 2015 Share Posted May 19, 2015 Temporarily put in a debugging statement echo 'Login = '.$vlogin.' password = '.$vpassword; just before setting up the connection string. This will allow you to check that you are setting up the right connection string Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.