Cannot update the form to the database - php

hod_view.php ## // the view of apply form from database
<?php
$sql= "SELECT * FROM form WHERE id='$formID'";
$result = mysql_query($sql) or die('Cannot get ID. ' . mysql_error());
$row=mysql_fetch_array($result);
$staffID=$row['staff_id'];
$sql2= "SELECT * FROM users WHERE staff_id='$staffID'";
$result2 = mysql_query($sql2);
$row2=mysql_fetch_array($result2);
?>
<form action="viewProcess.php?action=modifyView&id=<?php echo $row['id']?>" method="post" enctype="multipart/form-data" >
<h3 class="underlineLongest">USER APPLICATION FORM </h3>
<p align="right">Reference Number : <b> <?php echo $row['ref_no']; ?> </b> </p>
<table width='100%'>
<tr>
<td colspan='2' bgcolor="#C7C7C7"> Applicant Details</td>
</tr>
<tr>
<td width='30%'>Date of Application </td>
<td width='70%'> <textColor> <?php echo $row['app_date']; ?> </textColor> </td>
</tr>
<tr>
<td width='30%'>User Full Name </td>
<td width='70%'> <textColor> <?php echo $row2['name']; ?> </textColor> </td>
</tr>
<tr>
<td width='30%'>Designation/Staff ID </td>
<td width='70%'> <textColor> <?php echo $staffID; ?> </textColor> </td>
</tr>
<tr>
<td width='30%'>Department/Division </td>
<td width='70%'> <textColor> <?php echo $row2['department'].'/'.$row2['division']; ?> </textColor> </td>
</tr>
<tr>
<td width='30%'>Telephone Ext. No </td>
<td width='70%'> <textColor> <?php echo $row2['ext']; ?> </textColor> </td>
</tr>
<tr>
<td colspan='2' bgcolor="#C7C7C7" > Application Service Required </td>
</tr>
<tr>
<td width='30%'>Type of Application </td>
<?php
$type= $row['type'];
$result4 = mysql_query(" SELECT * FROM type WHERE type_code='$type'");
$row4=mysql_fetch_array($result4); ?>
<td width='70%'> <textColor> <?php echo $type.' - '.$row4['description']; ?> </textColor> </td>
</tr>
<tr>
<td width='30%'> Type of Facility </td>
<td width='70%'>
<textColor> <?php
$facility=explode(';',$row['facility']);
foreach($facility as $i =>$key)
{
echo $key .' - ';
$result5 = mysql_query(" SELECT * FROM facility WHERE fac_code='$key'");
while($row5=mysql_fetch_array($result5))
{
echo $row5['description'].' <br> ';
}
} ?>
</textColor> </td>
</tr>
<tr>
<td colspan='2' bgcolor="#C7C7C7" > Endorsed Status (Head of Department) </td>
</tr>
<tr>
<td width='30%'>Endorsed By </td>
<td width='70%'> <textColor> <?php echo $row['endorsed_by']; ?> </textColor> </td>
</tr>
<tr>
<td width='30%'>Status </td>
<td class="alt3">
<input name="radiobutton1" type="radio" value="APPROVED" checked >Approve
<input name="radiobutton2" type="radio" value="REJECTED" >Reject
</td>
</tr>
</tr>
<tr>
<td width='30%'>Date & Time </td>
<td width='70%'> <textColor> <?php echo $row['endorsed_time']; ?> </textColor> </td>
</tr>
<tr>
<td width='30%'>Remarks </td>
<!--<td width='70%'><textarea name="endorsed_remark" id = "endorsed_remark"></textarea> </td> -->
<td><input type="text" name="endorsed_remark" id="endorsed_remark" /></td>
</tr>
</table>
<br><br>
<center><p><input class="btnSuccess" type ="submit" name="submit" value="Submit" onclick="modifyView();" >
<input class="btnEdit" type="button" name="btnCancel" value="Cancel" onclick="goBack()" > </p>
This hod_view.php is the view form that have been applied by the user. Then, the approver need to approve this form by updating the endorsed_status and endorsed_remark into the database.
Unfortunately, the form is not updated in the database.
viewProcess.php ## // the update query to database
<?php
include 'includes/initial.php';
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch ($action)
{
case 'modifyView' :
break;
default :
header('Location: index.php');
}
function modifyView()
{
if(isset($_GET['id']) && $_GET['id'] > 0)
{
$formID = $_GET['id'];
}
else
{ // redirect to index.php if id is not present
header('Location: index.php');
}
echo $formID;
$sql = "UPDATE form SET endorsed_status='{$_POST['radiobutton1']}',endorsed_remark='{$_POST['endorsed_remark']}' WHERE id='$id'";
$result = mysql_query($sql) or die('Cannot update. ' . mysql_error());
if ($_POST['radiobutton2']=='REJECTED')
{
$sql = "UPDATE form SET endorsed_status='{$_POST['radiobutton2']}',endorsed_remark='{$_POST['endorsed_remark']}' WHERE id={$id} ";
$result = mysql_query($sql) or die('Cannot update. ' . mysql_error());
}
}
**This viewProcess.php is the sql query (update). Can you guys help me to make this coding correct?

Try this.
<?php
include 'includes/initial.php';
$action = isset($_POST['action']) ? $_POST['action'] : '';
switch ($action)
{
case 'modifyView' :
break;
default :
header('Location: index.php');
}
function modifyView()
{
if(isset($_POST['id']) && $_POST['id'] > 0)
{
$formID = $_POST['id'];
}
else
{ // redirect to index.php if id is not present
header('Location: index.php');
}
echo $formID;
$sql = "UPDATE form SET endorsed_status='{$_POST['radiobutton1']}',endorsed_remark='{$_POST['endorsed_remark']}' WHERE id='$id'";
$result = mysql_query($sql) or die('Cannot update. ' . mysql_error());
if ($_POST['radiobutton2']=='REJECTED')
{
$sql = "UPDATE form SET endorsed_status='{$_POST['radiobutton2']}',endorsed_remark='{$_POST['endorsed_remark']}' WHERE id={$id} ";
$result = mysql_query($sql) or die('Cannot update. ' . mysql_error());
}
}

Related

SQL query fails in prod environment on IIS but works in test environment running Apache

I'm having a bit of an issue with quires failing when I upload to the live environment while they are fully functional in the test environment, I'm at a loss at this point about where the error may be so I finally broke down and decided to ask those of stack overflow that may be much more skilled than myself if there's something I've missed. The quires look at serial number information from two different tables to pull system specs and any hard drive information associated with the parent serial
<?php
$Dev_HDD = 0;
$con=mysqli_connect("localhost","username","user_password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_POST["serial"]))
{
$SerialNumber = $_POST["serial"];
$sql ="SELECT system.Manufacturer, system.Model, system.SerialNumber, system.Processor, system.Memory FROM system WHERE SerialNumber = '" .$SerialNumber. "'" ;
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
$System_Manufacturer = $row[0];
$System_Model = $row[1];
$System_SerialNumber = $row[2];
$System_Processor = $row[3];
$System_Memory = $row[4];
?>
<table border="0" height="100%" width="100%" align="left" valign="top">
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2" valign="top">System Summary:</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>System Manufacturer</td>
<td>
<?php echo $System_Manufacturer; ?>
</td>
</tr>
<tr>
<td>System Model:</td>
<td>
<?php echo $System_Model; ?>
</td>
</tr>
<tr>
<td valign="top">System Serial Number</td>
<td valign="top">
<?php echo $System_SerialNumber; ?>
</td>
</tr>
<tr>
<td valign="top">System Processor</td>
<td valign="top">
<?php echo $System_Processor; ?>
</td>
</tr>
<tr>
<td valign="top">System Memory</td>
<td valign="top">
<?php echo $System_Memory; ?>
</td>
</tr>
<?php
}
// Free result set
mysqli_free_result($result);
}
else
{
echo "The serial number specified could not be located<br>";
}
$sql ="SELECT device.recid, device.Manufacturer, device.Model, device.SerialNumber, device.Capacity, device.RPM, device.ErasureMethod, device.ErasureResults FROM device WHERE SystemSerialNumber = '" . $System_SerialNumber . "'" ;
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
$Dev_Recid = $row[0];
$Dev_Manufacturer = $row[1];
$Dev_Model = $row[2];
$Dev_DeviceSerialNumber = $row[3];
$Dev_Capacity = $row[4];
$Dev_RPM = $row[5];
$Dev_ErasureMethod = $row[6];
$Dev_ErasureResults = $row[7];
?>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2" valign="top">Storage Summary(<?php echo $Dev_HDD = $Dev_HDD + 1; ?>):</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>Hard Drive Manufacturer</td>
<td>
<?php echo $Dev_Manufacturer; ?>
</td>
</tr>
<tr>
<td>Hard Drive Model:</td>
<td>
<?php echo $Dev_Model; ?>
</td>
</tr>
<tr>
<td valign="top">Serial Number Lookup</td>
<td valign="top">
<?php echo $Dev_DeviceSerialNumber; ?>
</td>
</tr>
<tr>
<td valign="top">Hard Drive Capacity</td>
<td valign="top">
<?php echo $Dev_Capacity; ?>
</td>
</tr>
<tr>
<td valign="top">Hard Drive Speed</td>
<td valign="top">
<?php echo $Dev_RPM; ?>
</td>
</tr>
<tr>
<td>Erasure Method:</td>
<td>
<?php echo $Dev_ErasureMethod; ?>
</td>
</tr>
<tr>
<td>Erasure Results:</td>
<td>
<?php echo $Dev_ErasureResults; ?>
</td>
</tr>
<tr>
<td>Parent Serial Number:</td>
<td>
<?php echo "<a href='logs/" .$Dev_DeviceSerialNumber.".log' target='_blank'>".$Dev_DeviceSerialNumber."</a> <br>";?>
</td>
</tr>
</table>
<?php
}
}
// Free result set
mysqli_free_result($result);
mysqli_close($con);
}
?>
<?php
echo " <br>";
echo "<pre></pre>";
?>

Getting radio button value in while loop

I'm doing a simple examination program using PHP.
Here is my code for taking the quiz, it's still in testing so don't mind the design.
This is the session for the person who is taking the quiz (no problem here):
<?php
session_start ();
$_SESSION['username'];
?>
<div id="wrap">
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="myproject"; // Database name
$tbl_name="q_quiz"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['q_id'];
$sql="SELECT * FROM $tbl_name WHERE q_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" frame="box" cellpadding="3" cellspacing="1" bgcolor="#CCFFCC">
<tr>
<td bgcolor="#CCFFCC"><h3>Quiz Info : </h3></td>
</tr>
<tr>
<td bgcolor="#CCFFCC"><strong>Quiz Name : </strong><?php echo $rows['q_name']; ?></td>
</tr>
</table>
</td>
</tr>
</table>
<font size="6">
<div style="font-weight: bold" id="quiz-time-left"></div>
<script type="text/javascript">
var max_time = <?php echo $rows['q_time'] ?>;
var c_seconds = 0;
var total_seconds =60*max_time;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
function init(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
setTimeout("CheckTime()",999);
}
function CheckTime(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds' ;
if(total_seconds <=0){
setTimeout('document.quiz.submit()',1);
} else {
total_seconds = total_seconds -1;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",999);
}
}
init();
</script>
</font>
<form action="result.php" method="post">
<?php
$score = 0;
$tbl_name2="a_quiz"; // Switch to table "forum_answer"
$sql2="SELECT * FROM $tbl_name2 WHERE q_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
$q_question = $rows['q_question'];
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr style='overflow:hidden; word-wrap:break-word;'>
<input type="text" name="q_id" value="<?php echo $rows['q_id'];?>">
<td bgcolor="lightgreen"><strong>Question:</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen" style="max-width: 1000px;"><?php echo $rows['q_question']; ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>A</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $q_question; ?>" value="a"><?php echo $rows['a'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>B</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $q_question; ?>" value="b"><?php echo $rows['b'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>C</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $q_question; ?>" value="c"><?php echo $rows['c'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>D</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $q_question; ?>" value="d"><?php echo $rows['d'] ?></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
$connection=mysql_connect('localhost', 'root','');
mysql_select_db('thesis');
$username= $_SESSION['username'];
$query6 = mysql_query("SELECT * FROM student WHERE username='$username'");
$row6 = mysql_fetch_assoc($query6);
$s_id = $row6['id'];
$name = $row6['name'];
$email = $row6['email'];
$position = $row6['position'];
?>
<input type="text" name="s_id" value="<?php echo $s_id ?>">
<input type="submit" name="submit" value="Submit Answer" class="btn">
</form>
</div>
I provided an image (I inputted two questions, this is the output of the code above):
http://i60.tinypic.com/2lu8doh.jpg
(2 is the quiz id, no problem on this, 12 near the submit button is the examiner id)
There's no problem in the code above.
My problem starts here. I am only getting the answer of the (examiner/person taking the quiz) of the question number 1 only and I already found my error.
This code below initiates when I click the submit button:
if(isset($_POST['submit']))
{
$con = mysql_connect ("localhost","root","");
if (!$con)
{
die("Error:".mysql_error());
}
mysql_select_db("myproject",$con);
}
I'm only getting the answer in the question number 1 of the examiner, because of this. It is not a loop so I'm only getting one answer even if theres 2-3 more answers.
$stud_id = $_POST['s_id'];
$quiz_id = $_POST['q_id'];
$score = 0;
$tbl_name2="a_quiz";
$sql2="SELECT * FROM $tbl_name2 WHERE q_id='$quiz_id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
$q_question=$rows['q_question'];
$question1 = $rows['answer'];
echo $q_question;
echo '<br>';
echo $question1;
echo '<br>';
if(isset($_POST[$q_question])){
$s_answer = $_POST[$q_question];
echo $s_answer;
if ($question1 == $s_answer){
$score = $score + 1;
}
}
}
echo $score;
So, for example, I got question 1 and question 2 and I selected the correct answer in number 1 I'm getting and $score++ but when my answer in question 2 is also correct is doesn't do $score++.
My problem here is: How can I get the value of radio button which I outputted them in while loop? Do I need to do a while loop for the answer too? How?
First, you are using each question as name attribute for your radio buttons, which is far from perfect. You might consider add a column to the table 'a_quiz' with a unique namespace for each question with no space in it (for instance question-one, question-two...) and call this column 'namespace'.
After this is done, you questions loop should look like this:
<?php
$score = 0;
$tbl_name2="a_quiz"; // Switch to table "forum_answer"
$sql2="SELECT * FROM $tbl_name2 WHERE q_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
$q_question = $rows['q_question'];
$namespace = $rows['namespace'];
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr style='overflow:hidden; word-wrap:break-word;'>
<input type="text" name="q_id" value="<?php echo $rows['q_id'];?>">
<td bgcolor="lightgreen"><strong>Question:</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen" style="max-width: 1000px;"><?php echo $rows['q_question']; ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>A</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $namespace; ?>" value="a"><?php echo $rows['a'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>B</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $namespace; ?>" value="b"><?php echo $rows['b'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>C</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $namespace; ?>" value="c"><?php echo $rows['c'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>D</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $namespace; ?>" value="d"><?php echo $rows['d'] ?></td>
</tr>
</table></td>
</tr>
<hr>
</table><br>
<?php
}
?>
Then, for the results part, use this code:
$stud_id = (int)$_POST['s_id'];
$quiz_id = (int)$_POST['q_id'];
$score = 0;
$tbl_name2 = "a_quiz";
$sql2 = "SELECT * FROM $tbl_name2 WHERE q_id='$quiz_id'";
$result2 = mysql_query($sql2);
$result = '';
while($rows=mysql_fetch_array($result2)){
$q_question = $rows['q_question'];
$question1 = $rows['answer'];
$namespace = $rows['namespace'];
$result .= $q_question;
$result .= <br>;
$result .= $question1;
$result .= <br>;
if(isset($_POST[$namespace])){
$s_answer = $_POST[$namespace];
$result .= $s_answer;
if ($question1 == $s_answer)
$score++;
}
}
$result .= $score;
echo $result;
}
?>

Back to previous page after deletion of row

<?php
include_once "library/inc.sesadmin.php";
include_once "library/inc.library.php";
include_once "mhsfunc.php";
$filterSQL = "";
if(isset($_POST['btnSubmit'])) {
$txtNim = trim($_POST['txtNim']);
$txtNama = trim($_POST['txtNama']);
$cmbProdi = trim($_POST['cmbProdi']);
$txtSmt = trim($_POST['txtSmt']);
$cmbSmt = trim($_POST['cmbSmt']);
if($cmbSmt<>""){
$filterSQL = "WHERE khs.nim='$txtNim' AND khs.smt='$cmbSmt'";
}else {
$filterSQL = "WHERE khs.nim='$txtNim'";
}
} else {
$filterSQL = "WHERE khs.nim='zzz'";
}
#tampilkan hasil isian di form
$dataNim =isset($_POST['txtNim']) ? $_POST['txtNim'] : '';
$dataNama =isset($_POST['txtNama']) ? $_POST['txtNama'] : '';
$dataProdi =isset($_POST['cmbProdi']) ? $_POST['cmbProdi'] : '';
$dataSmtMhs =isset($_POST['txtSmt']) ? $_POST['txtSmt'] : '';
$dataSmtKrs =isset($_POST['cmbSmt']) ? $_POST['cmbSmt'] : '';
# FOR PAGING (PEMBAGIAN HALAMAN)
$baris = 50;
$hal = isset($_GET['hal']) ? $_GET['hal'] : 1;
$pageSql = "SELECT * FROM khs $filterSQL";
$pageQry = mysql_query($pageSql, $koneksidb) or die ("error paging: ".mysql_error());
$jumlah = mysql_num_rows($pageQry);
$maks = ceil($jumlah/$baris);
$mulai = $baris * ($hal-1);
$jmlsks = 0;
$jmlbobot = 0;
$ipk = 0;
?>
<table width="800" border="0" cellpadding="2" cellspacing="0" class="table-border">
<tr>
<td colspan="3" align="right"><h1><b>DATA KRS MAHASISWA </b></h1></td>
</tr>
<tr>
<td colspan="3">
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="form1" target="_self">
<table class="table-list" width="1000" border="0" cellpadding="2" cellspacing="1" >
<tr>
<td colspan="3" style="font-size:20px; font-family:Cambria" bgcolor="#F5F5F5"><b>FILTER DATA</b></td>
</tr>
<tr>
<td width="169"><b>NIM Mahasiswa</b></td>
<td width="5"><b>:</b></td>
<td width="260"><input name="txtNim" type="text" id="txtNim" value="<?php echo $dataNim; ?>" size="15" maxlength="12" /></td>
</tr>
<tr>
<td><b>Nama Mahasiswa</b></td>
<td><b>:</b></td>
<td><input name="txtNama" type="text" id="txtNama" value="<?php echo $dataNama; ?>" size="40" maxlength="40" /></td>
</tr>
<tr>
<td><b>Program Studi</b></td>
<td><b>:</b></td>
<td><select name="cmbProdi" id="cmbProdi">
<option value="KOSONG">....</option>
<?php
$dataSql = "SELECT * FROM prodi ORDER BY kode";
$dataQry = mysql_query($dataSql, $koneksidb) or die ("Gagal Query".mysql_error());
while ($dataRow = mysql_fetch_array($dataQry)) {
if ($dataRow['kode'] == $cmbProdi) {
$cek = " selected";
} else { $cek=""; }
echo "<option value='$dataRow[kode]' $cek> [$dataRow[kode]] $dataRow[nama]</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td><b>Semester Mahasiswa</b></td>
<td><b>:</b></td>
<td><input name="txtSmt" type="text" id="txtSmt" value="<?php echo $dataSmtMhs; ?>" size="3" maxlength="1" /></td>
</tr>
<tr>
<td><b>Semester KRS</b></td>
<td><b>:</b></td>
<td><select name="cmbSmt" id="cmbSmt">
<option value="">ALL</option>
<?php
$pilihan = array("1", "2", "3", "4", "5","6");
foreach ($pilihan as $semester) {
if ($dataSmtKrs==$semester) {
$cek="selected";
} else { $cek = "";}
echo "<option value='$semester' $cek>$semester</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input name="btnSubmit" type="submit" value=" Submit" id="btnSubmit" /></td>
</tr>
</table>
</form>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3">
<table class="table-list" width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td colspan="5"><img src="images/btn_add_data.png" height="30" border="0" /></td>
</tr>
<tr>
<td width="28" align="center" bgcolor="#F5F5F5"><b>No</b></td>
<td width="63" bgcolor="#F5F5F5"><b>NIM</b></td>
<td width="53" bgcolor="#F5F5F5"><b>KDMK</b></td>
<td width="368" bgcolor="#F5F5F5"><b>NAMA MK</b></td>
<td width="35" bgcolor="#F5F5F5"><b>SMT</b></td>
<td width="30" bgcolor="#F5F5F5"><b>SKS</b></td>
<td width="26" bgcolor="#F5F5F5"><b>TM</b></td>
<td width="21" bgcolor="#F5F5F5"><b>PR</b></td>
<td width="19" bgcolor="#F5F5F5"><b>LP</b></td>
<td width="252" bgcolor="#F5F5F5"><b>DOSEN (NIDN/NAMA)</b></td>
<td align="center" bgcolor="#CCCCCC"><b>Tools</b></td>
</tr>
<?php
$mySql = "SELECT khs.id_khs, khs.nim, khs.kdmk, khs.nmmk, khs.smt, mtkul.sks, mtkul.tm, mtkul.pr, mtkul.lp,mtkul.nodos
FROM khs
INNER JOIN mtkul
ON khs.tahun=mtkul.tahun AND khs.prodi=mtkul.prodi AND khs.smt=mtkul.smt AND khs.kdmk=mtkul.kode $filterSQL
ORDER BY khs.smt, khs.kdmk LIMIT $mulai, $baris";
$myQry = mysql_query($mySql, $koneksidb) or die ("Query salah : ".mysql_error());
$nomor = $mulai;
while ($myData = mysql_fetch_array($myQry)) {
$nomor++;
$nidn = $myData['nodos'];
$Kode = $myData['id_khs'];
$jmlsks = $jmlsks+$myData['sks'];
$qryDosen = "SELECT * from dosen WHERE nidn=$nidn";
$qryCek = mysql_query($qryDosen, $koneksidb) or die ("Eror Query".mysql_error());
$myData2 = mysql_fetch_assoc($qryCek);
if(mysql_num_rows($qryCek)>=1){
$namaDosen=$myData2['nama'];
} else {$namaDosen=$nidn;}
// Gradasi warna baris
if($nomor%2==1) { $warna="#FFFFFF"; } else {$warna="#F5F5F5";}
?>
<tr bgcolor="<?php echo $warna; ?>">
<td align="center"><?php echo $nomor; ?></td>
<td><?php echo $myData['nim']; ?></td>
<td><?php echo $myData['kdmk']; ?></td>
<td><?php echo $myData['nmmk']; ?></td>
<td align="center"><?php echo $myData['smt']; ?></td>
<td align="center"><?php echo $myData['sks']; ?></td>
<td><?php echo $myData['tm']; ?></td>
<td><?php echo $myData['pr']; ?></td>
<td><?php echo $myData['lp']; ?></td>
<td><?php echo $namaDosen ?></td>
<td width="56" align="center">Delete</td>
//here is the KRS-Delete.php
<?php
include_once "library/inc.sesadmin.php";
// Get From URL
if(empty($_GET['Kode'])){
echo "<b>Data yang dihapus tidak ada</b>";
}
else {
$Kode = $_GET['Kode'];
$mySql = "DELETE FROM khs WHERE id_khs='$Kode'";
$myQry = mysql_query($mySql, $koneksidb) or die ("Eror hapus data".mysql_error());
if (mysql_affected_rows() > 0) {
header('location: ' .$_GET['Kode']);
echo "<script type=\"text/javascript\">".
"alert('Data Berhasil Di Hapus');".
"</script>";
echo "<meta http-equiv='refresh' content='0; url=?open=KRS-Data'>";
} else {
echo "Data tidak ditemukan !! <br><br>";
}
My Problem is that when I successfully delete a row, I want my page to go back showing the previous table shown, minus the row that I have already deleted with the exact same page number. What I need to parse into and out of KRS-Delete.php
When building UI pages that involve multiple steps, I prefer to put all steps in the same PHP file. I start with $foo = #$_GET['foo']; if ($foo) DoFoo(); to see if this call needs to do the "foo" step (such as doing the DELETE). After DoFoo(), I usually fall into the main code, which presents the UI page identical to (or similar to) the original page.
In addition to avoiding navigation problem you mentioned, it allows me to have 'all' the stuff for this UI in one file. Often there is a lot of common code, too.

simple members inquiry that can be access for members only

I'm creating a membership page
My login page seems to be okay when entering a account number it display the certain details about the account.
Now I created a two relational tables, I need to add this to the member page? I don't know where to put the code so when I enter the account number and login the details from two relational will automatically display.
Login Code:
<p align="center"<h2>Please Sign in to Inquire your Account</h2></p>
<?php
//Start session
session_start();
//Unset the variables stored in session
unset($_SESSION['SESS_MEMBER_ID']);
unset($_SESSION['SESS_FIRST_NAME']);
unset($_SESSION['SESS_LAST_NAME']);
?>
<form name="loginform" action="login_exec.php" method="post">
<table width="309" border="0" align="center" cellpadding="2" cellspacing="5">
<tr>
<td colspan="2">
<?php
if( isset($_SESSION['ERRMSG_ARR']) &&
is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
echo '<ul class="err">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>',$msg,'</li>';
}
echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
</td>
</tr>
<tr>
<td width="116"><div align="right">Account Number: </div></td>
<td width="177"><input name="Account_Number" type="text" /></td>
</tr>
<tr>
<td><div align="right">Password: </div></td>
<td><input name="password" type="text" /></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input name="" type="submit" value="Sign in" /></td>
</tr>
</table>
</form>
My Members Page Code with one table without the two relational tables:
<?php
require_once('connection.php');
$id=$_SESSION['SESS_MEMBER_ID'];
$result3 = mysql_query("SELECT * FROM member where mem_id='$id'");
while($row3 = mysql_fetch_array($result3))
{
$fname=$row3['fname'];
$lname=$row3['lname'];
$address=$row3['address'];
$contact=$row3['contact'];
$picture=$row3['picture'];
$gender=$row3['gender'];
}
?>
</h2>
</span>
<table width="597" border="0" cellpadding="0">
<tr>
<td height="26" colspan="2" class="style11"></td>
</tr>
<tr>
<td width="166" rowspan="5" class="style11"><div align="left"><img src="style/LOGO
GRAY.jpg" alt="no image found"" width="129" height="129" border="1" "<?php echo
$picture ?>/></div></td>
<td width="126" valign="top" class="style11"><div align="left">First Name:</div>
</td>
<td width="297" valign="top" class="style11"><span class="style16"><?php echo
$fname ?></span></td>
</tr>
<tr>
<td valign="top" class="style11"><div align="left">Last Name:</div></td>
<td valign="top" class="style11"><span class="style16"><?php echo $lname ?></span>
</td>
</tr>
<tr>
<td valign="top" class="style11"><div align="left">Gender:</div></td>
<td valign="top" class="style11"><span class="style16"><?php echo $gender ?></span>
</td>
</tr>
<tr>
<td valign="top" class="style11"><div align="left">Address:</div></td>
<td valign="top" class="style11"><span class="style16"><?php echo $address ?>
</span></td>
</tr>
<tr>
<td height="42" valign="top" class="style11"><div align="left">Contact No.: </div>
</td>
<td valign="top" class="style11"><span class="style16"><?php echo $contact ?>
</span></td>
</tr>
</table>
This is the code supposedly for the members page with two relational table.
My problem here I don't know how to combine the two.
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$memid = 3; // example
$sql = "SELECT member.*, account.* FROM member, account WHERE member.mem_id =
account.mem_id AND member.mem_id = '".$memid."' ";
mysql_select_db('databaseName');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "Account Number:{$row['Account_Number']} <br> ".
"First Name: {$row['fname']} <br> ".
"Last Name: {$row['lname']} <br> ".
"Address: {$row['address']} <br> ".
"Contact: {$row['contact']} <br> ".
"Share Capital: {$row['Share_Capital']} <br> ".
"Regular Savings: {$row['Regular_Savings']} <br> ".
"Power Savings: {$row['Power_Savings']} <br> ".
"--------------------------------<br>";
}
echo "Fetched data successfully\n";
mysql_close($conn);
?>
thanks for helping.

Rows are not being deleted

Here is my php code to select and delete rows form table:
<h1>Deleting Multiple Records using PHP & MySQL</h1>
<p> </p>
<?php
These are my db connection:
$host = "localhost"; // Host name
$username = "root"; // Mysql username
$password = ""; // Mysql password
$db_name = "project"; // Changed database name
$tbl_name = "users";
mysql_connect($host, $username, $password) or die("cannot connect");
mysql_select_db($db_name) or die("cannot select DB");
$sql = "SELECT * FROM $tbl_name";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
?>
Here is my html code to retrieve data from database:
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr><td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"><tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td> </tr>
<tr><td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>First Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Last Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Gender</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Phone Number</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Experiance</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>User Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Password</strong></td>
</tr>
<?php while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['fname']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['lname']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $rows['gend']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $rows['phone']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $rows['exp']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $rows['uname']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $rows['pwd']; ?> </td>
</tr>
<?php } ?>
<tr><td colspan="5" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete" onclick="javascript:confirm('Are you sure to delete')"></td></tr>
<?php
if(isset($_POST['delete'])){
$checkbox = $_POST['checkbox'];
for($i=0;$i<count($_POST['checkbox']);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
print $sql;
$result = mysql_query($sql);}
if($result){echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";}}
mysql_close();
?>
</table></form></td></tr></table>
<p>Record count: <?php echo number_format($count) ?></p>*/
I tried many times but it not deleting a single row from table.
just now i changed the code of executing query....please check it and inform me...
What is this query
$sql = "DEFRE FROM users WHERE id in (" . implode(",", $deleteIds) . ") ";
??
For deleting you should do something like this
$sql = "DELETE FROM users WHERE id IN (" . implode(",", $deleteIds) . ") ";
In the code
if (isset($_POST['checkbox']) && count($_POST['checkbox']) > 0)
{
$deleteIds = $_POST['checkbox']; // it will be an array
$sql = "DELETE FROM users WHERE id in (" . implode(",", $deleteIds) . ") ";
// run the query
}
We need to see the actual code trying to "delete". The usual mysql_query($sql) won't work. You have to use mysql_exec() instead of mysql_query().
Update: Sorry, I was confusing another form of query. mysql_query("delete from table where (whatever)") should work, though it returns true on success or false on failure, not a rowset.
I deleted one line ID from my program and i got the answer and it's working fine.
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value='<?php echo $row['id']; ?>'></td>
<td bgcolor="#FFFFFF"><?php echo $row['fname']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['lname']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $row['gend']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $row['phone']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $row['exp']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $row['uname']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $row['pwd']; ?> </td>
</tr>
<?php } ?>
<tr><td colspan="5" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete" onclick="javascript:confirm('Are you sure to delete')"></td></tr>
<?php
if(isset($_POST['delete'])){
$checkbox = $_POST['checkbox'];
for($i=0;$i<count($_POST['checkbox']);$i++){
$del_id = $checkbox[$i];
//print '$del_id';
$sql = "DELETE FROM users WHERE id='$del_id'";
//print $sql;
$result = mysql_query($sql);}
}
if($result){
echo"successfully deleted";
}
mysql_close();
?>
</table></form></td></tr></table>
<p>Record count: <?php echo number_format($count) ?></p>

Categories