banner_manager.php

//Cek apakah ada file yang diupload
		if((!empty($_FILES["uploaded_file"])) && ($_FILES["uploaded_file"]['error'] == 0)){
			$gambar = uploadPicture("uploaded_file");
		}
		
		if (empty($id))
			$sqlstr = "INSERT INTO banner(link, gambar) VALUES('".$link."','".$gambar."')";
		else
			$sqlstr = "UPDATE banner SET link = '".$link."',gambar = '".$gambar."' WHERE id =".$id;
		
		$result = mysql_query($sqlstr) or die(mysql_error());
		
		$confirmation = ($result)? "Data telah tersimpan.":"Gagal menyimpan data.";
		$gambar = "";
		$link = "";
		$id = "";
	}
	
	//EDIT / DELETE MODE
	if (!empty($_REQUEST['id']) && !empty($_REQUEST['mode'])){
		if ($_REQUEST['mode'] == 'delete'){
			$result = mysql_query("DELETE FROM banner WHERE id=".$_REQUEST['id']) or die(mysql_error());
			$confirmation = ($result)? "Data telah terhapus.":"Gagal menghapus data.";
		}elseif ($_REQUEST['mode'] == 'edit'){
			$result = mysql_query("SELECT * FROM banner WHERE id=".$_REQUEST['id']) or die(mysql_error());
			$data = mysql_fetch_array($result);
			$id = $data['id'];
			$link = $data['link'];
			$gambar = $data['gambar'];
		}
	}
	?>

<div align="center">
	<div style="width:700px;text-align:left;padding-top:25px;">
	<div class="pageTitle">Banner Manager</div>
	<?php echo $confirmation; ?><br/>
	<form method="post" enctype="multipart/form-data" action="<?php $_SERVER['file:///C|/xampp/htdocs/garuda_news/PHP_SELF']?>">
		<table width="700px" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td>Link</td>
			<td>
<input type="text" name="link" value="<?php echo $link; ?>"/> Contoh: http://www.garudanews.co.cc
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
			</td>
		</tr>
		<tr>
<td>Gambar</td>
<td><input type="file" name="uploaded_file"/></td>
		</tr>
		<tr>
			<td colspan="2">
				<?php
				if (!empty($_REQUEST['id'])){
				?>
<img src="<?php echo $gambar;?>" alt="gambar"/>
<input type="hidden" name="gambar" value="<?php echo $gambar; ?>"/>
				<?php
				}
				?>
			</td>
		</tr>
		<tr>
<td colspan="2"><input type="submit" name="simpan" value="Simpan"/></td>
		</tr>
	</table>
	</form>
	<hr/>
	
<table width="400px" border="1" cellpadding="2" cellspacing="0">
		<tr>
			<th>Banner</th>
			<th>Action</th>
		</tr>
		<?php
		//LOAD USER
		$result = mysql_query("SELECT * FROM banner");
		while ($data = mysql_fetch_array($result)){
		?>
			<tr>

The above codes produces the following output:

Banner Manager

Notice: Undefined variable: confirmation in C:\xampp\htdocs\php_template2\banner_manager.php on line 51


Link Contoh: http://www.garudanews.co.cc
Gambar


--------------------------------------------------------------------------------
Banner Action

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


Line 51: <?php echo $confirmation; ?><br/>

Line 92: while ($data = mysql_fetch_array($result)){

Why those error appears?

Thanks before.

Member Avatar for Zagga

Hi davy_yg,

The first error message is telling you that $confirmation has not been assigned a value anywhere. Check where this variable should be assigned.

The second error message is telling you that $result is not the value you expect it to be (you expect it to be a resource containing data from your database, but it is actually either "true" or "false"). Check your database connection code.


(your second IF statement is not enclosed in curly braces {} )

Zagga

Also, in link form, right above gambar(translate: picture):

<br /><b>Notice</b>: Undefined variable: link in <b>C:\xampp\htdocs\php_template2\banner_manager.php</b> on line <b>73</b><br />


line 73:<input type="text" name="link" value="<?php echo $link; ?>"/> Contoh: http://www.garudanews.co.cc


I just add the database connection, some errors disappeared (the first one) and the second one disappears only after I disable conformation: <?php //echo $confirmation; ?>. Line 73 is an error that still appears.

Member Avatar for Zagga

All of these error messages are caused by a single coding error. You forgot to use curly braces in your second IF statement.

if (empty($id))
$sqlstr = "INSERT INTO banner(link, gambar) VALUES('".$link."','".$gambar."')";
else
$sqlstr = "UPDATE banner SET link = '".$link."',gambar = '".$gambar."' WHERE id =".$id;
 
$result = mysql_query($sqlstr) or die(mysql_error());
 
$confirmation = ($result)? "Data telah tersimpan.":"Gagal menyimpan data.";
$gambar = "";
$link = "";
$id = "";

Change to ...

if (empty($id))[B]{[/B]
$sqlstr = "INSERT INTO banner(link, gambar) VALUES('".$link."','".$gambar."')";
[B]}[/B]else[B]{[/B]
$sqlstr = "UPDATE banner SET link = '".$link."',gambar = '".$gambar."' WHERE id =".$id;
 
$result = mysql_query($sqlstr) or die(mysql_error());
 
$confirmation = ($result)? "Data telah tersimpan.":"Gagal menyimpan data.";
$gambar = "";
$link = "";
$id = "";
[B]}[/B]
//SIMPAN DATA
	if (isset($_REQUEST['simpan'])){
		$link = mysql_real_escape_string($_REQUEST['link']);
		$id = $_REQUEST['id'];
		$gambar = $_REQUEST['gambar'];
		}
		
		//Cek apakah ada file yang diupload
		if((!empty($_FILES["uploaded_file"])) && ($_FILES["uploaded_file"]['error'] == 0)){
			$gambar = uploadPicture("uploaded_file");
		}
		
		if (empty($id)){
			$sqlstr = "INSERT INTO banner(link, gambar) VALUES('".$link."','".$gambar."')";
		}else{
			$sqlstr = "UPDATE banner SET link = '".$link."',gambar = '".$gambar."' WHERE id =".$id;
		
		$result = mysql_query($sqlstr) or die(mysql_error());
		
		$confirmation = ($result)? "Data telah tersimpan.":"Gagal menyimpan data.";
		$gambar = "";
		$link = "";
		$id = "";
		}
		
	
	//EDIT / DELETE MODE
	if (!empty($_REQUEST['id']) && !empty($_REQUEST['mode'])){
		if ($_REQUEST['mode'] == 'delete'){
			$result = mysql_query("DELETE FROM banner WHERE id=".$_REQUEST['id']) or die(mysql_error());
			$confirmation = ($result)? "Data telah terhapus.":"Gagal menghapus data.";
		}elseif ($_REQUEST['mode'] == 'edit'){
			$result = mysql_query("SELECT * FROM banner WHERE id=".$_REQUEST['id']) or die(mysql_error());
			$data = mysql_fetch_array($result);
			$id = $data['id'];
			$link = $data['link'];
			$gambar = $data['gambar'];
		}
	}
	?>

<div align="center">
	<div style="width:700px;text-align:left;padding-top:25px;">
	<div class="pageTitle">Banner Manager</div>
	<?php //echo $confirmation; ?><br/>
	<form method="post" enctype="multipart/form-data" action="<?php $_SERVER['file:///C|/xampp/htdocs/garuda_news/PHP_SELF']?>">
		<table width="700px" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td>Link</td>
			<td>
				<input type="text" name="link" value="<?php echo $link; ?>"/> Contoh: http://www.garudanews.co.cc
				<input type="hidden" name="id" value="<?php echo $id; ?>"/>
			</td>
		</tr>

Errors:

Connected successfully
Notice: Undefined variable: link in C:\xampp\htdocs\php_template2\banner_manager.php on line 38

Notice: Undefined variable: gambar in C:\xampp\htdocs\php_template2\banner_manager.php on line 38


Banner Manager


Link [_Undefined variable: link ] Contoh: http://www.garudanews.co.cc
Gambar [________________]

--------------------------------------------------------------------------------
Banner Action


<br /><b>Notice</b>: Undefined variable: link in <b>C:\xampp\htdocs\php_template2\banner_manager.php</b> on line <b>75</b><br />

Line 38: $sqlstr = "INSERT INTO banner(link, gambar) VALUES('".$link."','".$gambar."')";

Member Avatar for Zagga

Hi again davy_yg,

You need to look at the structure of your code.
At the moment, if $_REQUEST is not set, no value is being assigned to $link or $gambar but you are still trying to use these variables in your SQL statements ($sqlstr).
You always need to assign variables before you can use them.

// I add these

   $_REQUEST['simpan'] = isset($_POST['simpan']) ? $_POST['simpan'] : '';
   $_REQUEST['link'] = isset($_POST['link']) ? $_POST['link'] : '';
   $_REQUEST['gambar'] = isset($_POST['gambar']) ? $_POST['gambar'] : '';
   $_REQUEST['id'] = isset($_POST['id']) ? $_POST['id'] : '';

	//SIMPAN DATA
	if (isset($_REQUEST['simpan'])){
		$link = mysql_real_escape_string($_REQUEST['link']);
		$id = $_REQUEST['id'];
		$gambar = $_REQUEST['gambar'];
		}
		
		//Cek apakah ada file yang diupload
		if((!empty($_FILES["uploaded_file"])) && ($_FILES["uploaded_file"]['error'] == 0)){
			$gambar = uploadPicture("uploaded_file");
		}
		
		if (empty($id)){
			$sqlstr = "INSERT INTO banner(link, gambar) VALUES('".$link."','".$gambar."')";
		}else{
			$sqlstr = "UPDATE banner SET link = '".$link."',gambar = '".$gambar."' WHERE id =".$id;
		
		$result = mysql_query($sqlstr) or die(mysql_error());
		
		$confirmation = ($result)? "Data telah tersimpan.":"Gagal menyimpan data.";
		$gambar = "";
		$link = "";
		$id = "";
		}

Well, the value of link and gambar suppose to be captured when I press "Simpan" button (translate: save button). It captures from : link form field and gambar uploaded (translate: picture uploaded) form field.

Now, the error disappeared. Just one more thing, why am I carried to:
http://youtubedownloader.mybrowserbar.com/cgi/errors.cgi?q=http://localhost/php_template2/%253Cbr%2520/%253E%253Cb%253ENotice%253C/b%253E:%2520%2520Undefined%2520index:%2520file:///C%257C/xampp/htdocs/garuda_news/PHP_SELF%2520in%2520%253Cb%253EC:/xampp/htdocs/php_template2/banner_manager.php%253C/b%253E%2520on%2520line%2520%253Cb%253E76%253C/b%253E%253Cbr%2520/%253E&type=dns&ISN=F079DE32B1A641F3A05B78CA8944C78F&ccv=136&cnid=937811&cco=US&ct=1&sc=403

whenever I press "Simpan" button (translate: save button) ?

Here is the form syntax as an addition to the above codes:

<table width="700px" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td>Link</td>
			<td>
				<input type="text" name="link" value="<?php echo $link; ?>"/> Contoh: http://www.garudanews.co.cc
				<input type="hidden" name="id" value="<?php echo $id; ?>"/>
			</td>
		</tr>
		<tr>
			<td>Gambar</td>
			<td><input type="file" name="uploaded_file"/></td>
		</tr>
		<tr>
			<td colspan="2">
				<?php
				if (!empty($_REQUEST['id'])){
				?>
					<img src="<?php echo $gambar;?>" alt="gambar"/>
					<input type="hidden" name="gambar" value="<?php echo $gambar; ?>"/>
				<?php
				}
				?>
			</td>
		</tr>
		<tr>
			<td colspan="2"><input type="submit" name="simpan" value="Simpan"/></td>
		</tr>
	</table>
	</form>
	<hr/>
	
	<table width="400px" border="1" cellpadding="2" cellspacing="0">
		<tr>
			<th>Banner</th>
			<th>Action</th>
		</tr>
		<?php
		//LOAD USER
		$result = mysql_query("SELECT * FROM banner");
		while ($data = mysql_fetch_array($result)){
		?>
			<tr>
				<td><?php echo $data['link'];?></td>
				<td>
					<a href="file:///C|/xampp/htdocs/garuda_news/banner_manager.php?id=<?php echo $data['id']; ?>&amp;mode=delete">Hapus</a> | 
					<a href="file:///C|/xampp/htdocs/garuda_news/banner_manager.php?id=<?php echo $data['id']; ?>&amp;mode=edit">Edit</a>
				</td>
			</tr>
		<?php
		}
		?>
	</table>
	</div>
</div>

Any clue?

Member Avatar for Zagga

Hi again davy_yg,

the redirection problem is not to do with your code, but probably to do with a rogue toolbar installed in your browser. Do a search for mybrowserbar for more info on this.

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.