<b>Warning</b>: mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (28000/1045): Access denied for user 'root'@'localhost' (using password: YES) in <b>C:\xampp\htdocs\projectli\excel.php</b> on line <b>9</b><br />
Unable to select database
This is the codes for excel.php
Code: Select all
<?php
header("Content-Disposition: attachment; filename=Rekod.xls");
include("connect.php");
mysqli_connect("localhost","root"," ", "project");
@mysqli_select_db($dbcon) or die("Unable to select database");
$queryt = "SELECT * FROM schools";
$export = mysqli_query($query);
$count = mysqli_num_fields($export);
for ($i = 0; $i < $count; $i++) {
$header .= mysql_field_name($export, $i)."\t";
}
while($row = mysqli_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r", "", $data);
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
print "$header\n$data";
?>
This is the connect.php
Code: Select all
<?php
$dbcon=mysqli_connect("localhost","root","", "project")or trigger_error(mysqli_error(),E_USER_ERROR);
?>
This is the searchschoolsthis.php which have a button to display the searched data in tables and a button to generate an excel file of the searched data.
Code: Select all
<form method="post" action="searchschoolsthis.php">
<input type="hidden" name="submitted" value="true" />
<label><span class="style2">Pilih Kategori:</span>
<span class="style1">
<select name="category">
<option value="negeri">NEGERI</option>
<option value="daerah">DAERAH</option>
<option value="kod_sekolah">KOD SEKOLAH</option>
</select>
</span></label>
<span class="style1">
<span class="style2">Taip Kriteria
<label>:</label>
</span>
<label>
<input type="text" name="criteria" onKeyUp="this.value = this.value.toUpperCase();"/>
</label>
<input type="submit" value="Cari" />
</form>
<form action="excel.php" method="post" name="cetak" target="_blank" id="cetak">
<input type="submit" name="cetak" id="cetak" value="Cetak" />
</form>
</span>
<table width='100%' color='black' id='header'>
<thead>
<tr>
<td width="40%" scope="col"><div align="center"><span class="style2">Kod Sekolah</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">Nama Sekolah</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">PTJ</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">Server</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">PC</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">NB</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">Mono Laser</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">Color Laser</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">Dot Matrix</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">LCD</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">Set LAN</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">Jumlah Kos</span></div></td>
<td width="40%" scope="col"><div align="center"><span class="style2">Dibayar</span></div></td>
<td width="50%" scope="col"><div align="center"><span class="style2">Tanggungan</span></div></td>
</tr>
</thead>
</table>
<?php
if(isset($_POST['submitted'])){
include('connect.php');
$category=$_POST['category'];
$criteria=$_POST['criteria'];
$query="SELECT * FROM schools WHERE $category = '$criteria'";
$result=mysqli_query($dbcon,$query) or die('error getting data');
echo "<table width='120%' border='2' color='black' id='header'>";
while ($row = mysqli_fetch_array($result,MYSQL_ASSOC)){
echo"<tr><td>";
echo $row['kod_sekolah'];
echo"</td><td>";
echo $row['nama_sekolah'];
echo"</td><td>";
echo $row['ptj'];
echo"</td><td>";
echo $row['server'];
echo"</td><td>";
echo $row['pc'];
echo"</td><td>";
echo $row['nb'];
echo"</td><td>";
echo $row['mono_laser'];
echo"</td><td>";
echo $row['color_laser'];
echo"</td><td>";
echo $row['dot_matrix'];
echo"</td><td>";
echo $row['lcd'];
echo"</td><td>";
echo $row['set_lan'];
echo"</td><td>";
echo $row['jumlah_kos'];
echo"</td><td>";
echo $row['dibayar'];
echo"</td><td>";
echo $row['tanggungan'];
//echo"</td><td style='text-align:right'>";
echo"</td></tr>";
}
echo "</table>";
}
?>