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.
Related
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>";
?>
Im trying to show the respective comments to the respective question ID but all the comments are shown in every post.
actually the value of qusetion ID is not going to the desired table where it suppose to be and that table
name: add_topic.php
<body>
<?php
$con=mysqli_connect('localhost','root','');
if(!$con)
{
die("could not connect to the server".mysqli_error());
}
mysqli_select_db($con,'forum');
// Get value of id that sent from hidden field
$id=$_POST['id'];
// Find highest answer number.
$q="SELECT MAX(a_id) AS Maxa_id FROM forum_ans WHERE que_id='$id'";
$result=mysqli_query($con,$q);
$row=mysqli_fetch_assoc($result);
// add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1
if ($row) {
$Max_id = $row['Maxa_id']+1;
}
else {
$Max_id = 1;
}
// get values that sent from form
$a_name=$_POST['a_name'];
$a_email=$_POST['a_email'];
$a_ans=$_POST['a_ans'];
$datetime=date("d/m/y H:i:s"); // create date and time
// Insert answer
$q2="INSERT INTO forum_ans(que_id, a_id, a_name, a_email, a_ans, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_ans', '$datetime')";
$result2=mysqli_query($con,$q2);
if($result2){
echo "Successful<BR>";
echo "<a href='view_topic.php?id=".$id."'>View your answer</a>";
// If added new answer, add value +1 in reply column
$q3="UPDATE forum_que SET reply='$Max_id' WHERE id='$id'";
$result3=mysqli_query($con,$q3);
}
else {
echo "ERROR";
}
// Close connection
mysqli_close($con);
?>
</body>
block that named as que_id is showing the value of 0 (as i have set 0 as its default value) and that is the main reason of it but im not able to solve this problem. plz help...
name: view_topic.php
<body>
<?php
$con=mysqli_connect('localhost','root','');
if(!$con)
{
die("could not connect to the server".mysqli_error());
}
mysqli_select_db($con,'forum');
// get value of id that sent from address bar
$id=$_GET['id'];
$q="SELECT * FROM forum_que WHERE id='$id'";
$result=mysqli_query($con,$q);
$row=mysqli_fetch_assoc($result);
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong><?php echo $row['topic']; ?></strong></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><?php echo $row['detail']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>By :</strong> <?php echo $row['name']; ?> <strong>Email : </strong><?php echo $row['email'];?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/time : </strong><?php echo $row['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?php
// Switch to table "forum_answer"
$q2="SELECT * FROM forum_ans WHERE que_id='$id'";
$result2=mysqli_query($con,$q2);
while($row2=mysqli_fetch_assoc($result2)){
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong>ID</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><?php echo $row2['a_id']; ?></td>
</tr>
<tr>
<td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
<td width="5%" bgcolor="#F8F7F1">:</td>
<td width="77%" bgcolor="#F8F7F1"><?php echo $row2['a_name']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Email</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><?php echo $row2['a_email']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Answer</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><?php echo $row2['a_ans']; ?></td>
</tr>
<tr>
<td bgcolor="#F8F7F1"><strong>Date/Time</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><?php echo $row2['a_datetime']; ?></td>
</tr>
</table></td>
</tr>
</table><br>
<?php
}
$q3="SELECT view FROM forum_que WHERE id='$id'";
$result3=mysqli_query($con,$q3);
$row3=mysqli_fetch_assoc($result3);
$view=$row3['view'];
// if have no counter value set counter = 1
if(empty($view)){
$view=1;
$q4="INSERT INTO forum_que(view) VALUES('$view') WHERE id='$id'";
$result4=mysqli_query($con,$q4);
}
// count more value
$addview=$view+1;
$q5="update forum_que set view='$addview' WHERE id='$id'";
$result5=mysqli_query($con,$q5);
mysqli_close($con);
?>
<BR>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="add_ans.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="18%"><strong>Name</strong></td>
<td width="3%">:</td>
<td width="79%"><input name="a_name" type="text" id="a_name" size="45"></td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td>:</td>
<td><input name="a_email" type="text" id="a_email" size="45"></td>
</tr>
<tr>
<td valign="top"><strong>Answer</strong></td>
<td valign="top">:</td>
<td><textarea name="a_ans" cols="45" rows="3" id="a_ans"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" value="<? echo $id; ?>"></td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
name: add_topic.php
<body>
<?php
// get data that sent from form
$topic=$_REQUEST['topic'];
$detail=$_REQUEST['detail'];
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$datetime=date("d/m/y h:i:s"); //create date time
$con=mysqli_connect('localhost','root','');
if(!$con)
{
die("could not connect to the server".mysqli_error());
}
mysqli_select_db($con,'forum');
$q="INSERT INTO`forum`.`forum_que`(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')";
if(mysqli_query($con,$q))
{
echo '<script>alert("Data Inserted Now redirecting to login page");</script>';
header('location:main_forum.php');
}
else
{
echo "error inserting record" . mysqli_error($con,$query);
echo '<script>alert("Error while inserting data");</script>';
}
mysqli_close($con);
?>
</body>
You have two add_topic.php should one be add_ans.php
I don't see any exact problems with this code are you sure that the $id is being used correctly in the hidden field of your form?
Possibly try doing a print_r($_POST); on the add_ans.php page to see what data is actually being passed by the form
<?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.
i am constructing a registration page for new members. after filling in the form, it will proceed to the confirm page. after confirmation, it will proceed to the reg_add.php to add the data from the form to the database.
reg_new.php --> reg_confirm.php --> reg_add.php
i am trying to edit the code in the confirm page (reg_confirm.php) to include the email availability check. it seems that it can automatically detect the duplicate email and after clicking the confirm button.
Duplicate entry 'shop#gmail.com' for key 'PRIMARY' will be shown.
yet, it is not success to have a pop up alert and stay in the confirm page. please help.
<?php
session_start();
$_SESSION['email'] = $_POST['email_reg'];
$_SESSION['password'] = $_POST['password_reg'];
$_SESSION['name_reg'] = $_POST['name_reg'];
$_SESSION['month'] = $_POST['month'];
$_SESSION['telephone_reg'] = $_POST['telephone_reg'];
$_SESSION['room_reg'] = $_POST['room_reg'];
$_SESSION['floor_reg'] = $_POST['floor_reg'];
$_SESSION['block_reg'] = $_POST['block_reg'];
$_SESSION['building_reg'] = $_POST['building_reg'];
$_SESSION['estate_reg'] = $_POST['estate_reg'];
$_SESSION['street_reg'] = $_POST['street_reg'];
$_SESSION['district_reg'] = $_POST['district_reg'];
$_SESSION['region_reg'] = $_POST['region_reg'];
$regemail = $_POST["email_reg"];
$connect = mysql_connect("127.0.0.1","root","") or die("not connecting");
mysql_select_db("shop") or die("no db :'(");
$numrows = mysql_query("SELECT membermail FROM member WHERE memberemail='$regemail'");
if ($numrows!=0)
{
echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";
}
?>
</head>
<body>
<div align="center" class="style1"><span class="style2">Registeration Confirm</span>
<p class="style2"> </p>
<form action="reg_add.php" method="post" enctype="multipart/form-data" name="form1">
<table width="602" height="180" border="1">
<tr>
<td colspan="3">Login Information</td>
</tr>
<tr>
<td width="160" class="style6">Email address: </td>
<td colspan="2"><span class="style7"><?php echo $_SESSION['email']?></span></td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="3">User information </td>
</tr>
<tr>
<td><span class="style6">Name:</span></td>
<td colspan="2"><?php echo ($_SESSION['name_reg'])?></td>
</tr>
<tr>
<td><span class="style6">Month of birth :</span></td>
<td colspan="2"><?php echo ($_SESSION['month'])?>
</tr>
<tr>
<td><span class="style6">Contact telephone:</span></td>
<td colspan="2"><?php echo ($_SESSION['telephone_reg'])?></td>
</tr>
<tr>
<td rowspan="8"><span class="style6">Contact address:</span></td>
<td width="153"><p class="style6">Room/ Flat no.: </p> </td>
<td width="267"><p class="style6"><?php echo ($_SESSION['room_reg'])?></p> </td>
</tr>
<tr>
<td><span class="style6">Floor: </span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['floor_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Block/ Tower:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['block_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Building:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['building_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Estate: </span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['estate_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Street:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['street_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">District:</span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['district_reg'])?></span></td>
</tr>
<tr>
<td><span class="style6">Region: </span></td>
<td width="267"><span class="style6"><?php echo ($_SESSION['region_reg'])?></span></td>
</tr>
<tr>
<td colspan="3" class="style6"> </td>
</tr>
</table>
<p>
<input name="confirm" type="submit" id="confirm" value="Confirm">
</p>
</form>
<p>
<input name="modifty" type="submit" id="modifty" value="Modify" onClick="history.go(-1)">
</p>
</div>
</body>
</html>
Your problem is how you are retrieving the number of rows from the database.
mysql_query() does not retrieve the number of rows. It retrieves a result set.
Instead of:
$numrows = mysql_query("SELECT membermail FROM member WHERE memberemail='$regemail'");
if ($numrows!=0)
{
echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";
}
Use:
$email = mysql_real_escape_string($_POST["email_reg"]);
$result = mysql_query("SELECT COUNT(memberemail) AS emailCount FROM member WHERE memberemail='{$email}'");
$row = mysql_fetch_row($result);
if($row[0]>0){
echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";
}
ALWAYS make sure you escape your data before using it in a database query.
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>