Please help undefined variabel: sql

Please help undefined variabel: sql
0

#1
<?php
//program untuk menampilkan data mahasiswa
session_start();
include "Inc_db.php";

//baca dari tabel student
	// $sql= "SELECT student_nim, student_name, student_program FROM tb_student";
	// $result=mysql_query($sql);
	//x$totalrow=mysql_num_rows($result);

?>
<html>
<head>
	<title>Mahasiswa</title>
</head>
<body>
	<form action="Student.php" name="frm_search" method="post" method="#">
		<table width="350" border="0" align="center" cellpadding="0">
			<td height="25" colspan="3">
				<strong>Searching Data</strong>
			</td>
			<tr><td>NIM</td>
				<td><input type="text" name="frm_nim"></td>
			<tr><td>Nama</td>
				<td><input type="text" name="frm_name"></td>
			<tr><td>Prodi</td>
				<td>
					<select name="frm_prodi">
						<option value="">--Pilih Semua--</option>
						<option value="MI">Manajemen Informatika</option>
						<option value="TI">Teknik Informatika</option>
						<option value="SI">Sistem Informasi</option>
					</select>
				</td>
			</tr>
			<tr>
				<td><input type="radio" name="logic" value="AND" checked>AND</td>
				<td><input type="radio" name="logic" value="OR">OR</td>
			</tr>
			<td></td>
			<td><input type="submit" name="submit" id="Submit" value="Search"></td>
			</tr>
			</tr>
		</table>
	</form>
<?php
	if(!isset($_POST['frm_nim']) && !isset($_POST['frm_name']) && !isset($_POST['frm_prodi']) && !isset($_POST['logic'])) {
		$sql="SELECT student_nim, student_name, student_program FROM tb_student";
	} else 
			$logic=$_POST['logic'];
		if (empty($_POST['frm_nim']) && empty($_POST['frm_name']) && empty($_POST['frm_prodi'])) {
			$sql="SELECT student_nim, student_name, student_program FROM tb_student";
		} else 
		if (!empty($_POST['frm_nim']) && empty($_POST['frm_name']) && empty($_POST['frm_prodi'])) {
			$sql="SELECT student_nim, student_name, student_program FROM tb_student WHERE student_nim='".$_POST['frm_nim']."'";
		} else
		if (!empty($_POST['frm_nim']) && !empty($_POST['frm_name']) && empty($_POST['frm_prodi'])) {
			$sql="SELECT student_nim, student_name, student_program FROM tb_student WHERE student_nim='".$_POST['frm_nim']."' $logic student_name='".$_POST['frm_name']."'";
		} else 
		if (!empty($_POST['frm_nim']) && !empty($_POST['frm_name']) && empty($_POST['frm_prodi'])) {
			$sql="SELECT student_nim, student_name, student_program FROM tb_student WHERE student_nim='".$_POST['frm_nim']."' $logic student_name='".$_POST['frm_name']."' $logic student_program='".$_POST['frm_prodi']."'";
		} else
		if (!empty($_POST['frm_nim']) && !empty($_POST['frm_name']) && empty($_POST['frm_prodi'])) {
			$sql="SELECT student_nim, student_name, student_program FROM tb_student WHERE student_program='".$_POST['frm_prodi']."'";
		}else
		if (!empty($_POST['frm_nim']) && !empty($_POST['frm_name']) && empty($_POST['frm_prodi']))  {
			$sql="SELECT student_nim, student_name, student_program FROM tb_student WHERE student_name='".$_POST['frm_name']."'";
		}else
		if (!empty($_POST['frm_nim']) && !empty($_POST['frm_name']) && empty($_POST['frm_prodi']))  {
			$sql="SELECT student_nim, student_name, student_program FROM tb_student WHERE student_name='".$_POST['frm_name']."' $logic student_program='".$_POST['frm_prodi']."'";
		}else
		if (!empty($_POST['frm_nim']) && !empty($_POST['frm_name']) && empty($_POST['frm_prodi'])) {
			$sql="SELECT student_nim, student_name, student_program FROM tb_student WHERE student_nim='".$_POST['frm_nim']."' $logic student_name='".$_POST['frm_name']."'";
		} else
		if (!empty($_POST['frm_nim']) && !empty($_POST['frm_name']) && empty($_POST['frm_prodi'])) {
			$sql="SELECT student_nim, student_name, student_program FROM tb_student WHERE student_nim='".$_POST['frm_nim']."' $logic student_program='".$_POST['frm_prodi']."'";
		}

	$result= mysql_query($sql);
	$baris="1";
	$var_nim="";
	$var_name="";
	$var_program="";
	//eksekusi query
	echo "<center>";
	//hitung jumlah record
	$totalRow= mysql_num_rows($result);
?>


    <h2 align="center">MAHASISWA</h2>
    <table border="1" width="800" border="0" align="center" cellpadding="0">
    <td>NIM</td><td>Nama</td><td>Prodi</td><td>Aksi</td>
    </tr>
    </html>
<?php
if($totalRow==0){
?>
	<tr><td colspan="4">Data belum tersedia</td></tr>
<?php
}
	else {
	while ($data=mysql_fetch_array($result)) {
		$nim= $data['student_nim'];
		$name= $data['student_name'];
		$program= $data['student_program'];
	
		?>
		<tr>
			<td><?php echo $nim ?></td>
			<td><?php echo $name ?></td>
			<td><?php echo $program ?></td>
		<td><a href="Student_edit.php">Edit</a>
			<a href="Student_delete.php">Hapus</a></br>
			</tr>
		<?php 
	} //-while
}
//}
?>
		</table>
		<br>
		<center>Jumlah Data : <?php echo $totalRow;?></center>
		<form action="Student_insert.php" method="POST">
		<tr>
			<br>
			<td><input type="submit" value="Tambah Data"> </td>
		</br>
		</tr>
	</form>
	<form action="Student.php" method="POST">
		<tr>
			<br>
			<td><input type="submit" value="Refresh"> </td>
		</br>
		</tr>
	</form>
	</body>
</html>

#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.


#3

Your lines 51 through 77 are all duplicates. What are you trying to accomplish?