Jump to content

Recommended Posts

I keep getting this error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in  on line 21

 

<html>
<body>
<h1> Database </h1>
<?php

mysql_connect('localhost', 'cw2395', 'tNlkcI6k') or die(mysql_error());
mysql_select_db('cw2395') or die (mysql_error());
$reference = mysql_query("SELECT * FROM contacts");
?>
<table border = "3" cellspacing = "3" cellpadding = "3">
        <tr>
                <th> First Name </th>
                <th> Last Name </th>
                <th> Address </th>
                <th> State </th>
                <th> Zip </th>
                <th> Telephone </th>
                <th> Email </th>
        </tr>
<?php
        while($row = mysql_fetch_array($reference)) {         THIS IS LINE 21
                $cell1 = $row['Fname']; //Contacts first name
                $cell2 = $row['Lname']; //Contacts last name
                $cell3 = $row['Address']; //Contacts address
                $cell4 = $row['State']; //Contacts state of residence
                $cell5 = $row['Zip']; //Contacts zip code of residence
                $cell6 = $row['Phone']; //Contacts phone number
                $cell7 = $row['Email']; //Contacts email address
?>
 

 

help would be very appreciated :(

Link to comment
https://forums.phpfreaks.com/topic/292688-keep-getting-same-error/
Share on other sites

I keep getting this error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in  on line 21

 

means that your query is incorrect and hence failing.

 

Add this lines after your <?php opening tag or better yet setup how to manage and display errors in your php.ini. It should give your indication of what is going on.

   // Define how to display/report errors
   ini_set("display_errors", "1");
   error_reporting(-1);

In additional note:

- You should not be using mysql_ API it has been already deprecated; you should be using mysqli_ or PDO

1 - It means your query failed.  Since you checked the connect and the select that means you probably specified the table name incorrectly in your query statement.

 

2 - You should cease and desist from using the MySQL_* functions.  Period.  Read the manual for any one of these functions and see why.

Then your query

$reference = mysql_query("SELECT * FROM contacts");

has failed.

 

Check to see what mysql_error() contains.

 

NOTE: you should not be using mysql_ functions, they are deprecated. Use mysqli_ or PDO instead.

Its saying

Database

Table 'cw2395.contacts' doesn't exist

 

Im suppose to br creating basically a contact index that stores in a Database name, location, phone etc.

 

I know I should be using mysqli, but this is the last assignment for the class and he has been using this the whole time

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.