0

category_manager.php

<?php
		//LOAD USER
		$result = mysql_query("SELECT * FROM kategori_berita");
while ($data = mysql_fetch_array($result)){
		?>
			<tr>
				<td><?php echo $data['kategori'];?></td>
				<td>
					<a href="./category_manager.php?id=<?php echo $data['id']; ?>&mode=delete">Hapus</a> | 
					<a href="./category_manager.php?id=<?php echo $data['id']; ?>&mode=edit">Edit</a>
				</td>
			</tr>
		<?php

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

What should I do so that the error would not appear.

Thanks.

Edited by davy_yg: n/a

4
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by Matthew N.
0

Connect to the database first, using mysql_connect and mysql_select_db .

If you do:

$result = mysql_query("SELECT * FROM kategori_berita") or die(mysql_error());

you can see what error is returned.

Edited by pritaeas: n/a

0

Normally in this case it means one of two things.
1) You mis-spelt the table name "kategori_berita" or
2) On older versions of Mysql you will need to change the query string to the below with the special quotes.

SELECT * FROM `kategori_berita`
0

I modify the codes:

<?php
		
		// connect to database
	  
	  		$con = mysql_connect('localhost', 'root', '');
	  
	  		if (!$con) {
    			die('Could not connect: ' . mysql_error());
				}
				echo 'Connected successfully <br>';

	  
	   		$db_selected = mysql_select_db("template", $con);

	   		if (!$db_selected)
  				{
  				die ("Can't use template : " . mysql_error());
  				}
			else echo 'database template connected <br>';
			
	  		mysql_close($con);

				
		
			//LOAD USER		
		
		$result = mysql_query("SELECT * FROM kategori_berita") or die(mysql_error());
		while ($data = mysql_fetch_array($result)){
		?>

Category Manager


Kategori :

--------------------------------------------------------------------------------
Kategori Berita Action
Connected successfully
database template connected
No database selected

The error contradict itself. I wonder which is correct whether the database already connected or not. There no data yet in the table. The database named template.

0

Try replacing line 14 with the following

$db_selected = mysql_select_db("template");

Also remove the following function from your script as it may cause some problems further along.

mysql_close($con);
0

Also, on some servers, you need to add a @ sign before mysql_num_rows and mysql_fetch_assoc/array.
This is to do with error_reporting.
To stop the @ sign being needed, change error_reporting to 0 in php.ini, or add

error_reporting(0);

to the top of your code.
Matthew

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.