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.

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.

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`

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.

Does it output any errors at all? If it does then could you please post them here.

die(mysql_error() outputs:

No database selected

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);

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.