i have a form that extract data from mysql table into a form, each row has a menu to choose a value from and i want to update mysql with each value choosen for each row when the 'Apply To All' button is clicked but doesnt work at all.,here is my code.
<td><form id="main" name="main" method="post" action="setProjectStatus.php" onsubmit="return validateMain();">
<table width="100%" cellspacing="1" cellpadding="1">
<tr>
<td width="35%" rowspan="3"><img src="../img/project.jpg" alt="Comp Sci Stud" width="325" height="199" border="2" /></td>
<td width="65%" height="42" colspan="2"><table width="94%" cellpadding="1" cellspacing="1" class="main_table">
<tr class="table_title">
<td width="100%" class="table_title">Set Project Status. </td>
</tr>
<tr>
<td height="26"> </td>
</tr>
<tr>
<td height="26"><table width="100%" cellspacing="1" cellpadding="1">
<tr class="table_head">
<td width="2%" height="35"><div align="center"></div></td>
<td width="26%" height="35"><div align="center">Student Name</div></td>
<td colspan="2"><div align="center">Project</div></td>
<td width="19%"><div align="center">Status</div></td>
</tr>
<?php
session_start();
$username = $_SESSION['username'];
require_once("mysqlConnect.php");
//
$sql="SELECT * FROM spms_Student";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
echo "There are $count projects to be undertaken.";
while($rows=mysql_fetch_array($result)){
//
$query = "SELECT name FROM spms_systemUser WHERE userId = '".$rows[0]."'";
$result1 = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result1);
$name = $row[0];
?>
<tr>
<td height="25" align="center"> </td>
<td align="center"><?php echo $name; ?></td>
<td colspan="2" align="center"><?php echo $rows[1]; ?></td>
<td align="center"><label>
<select name="select" class="form_field_100px_select">
<option value="Pending" selected="selected">Pending</option>
<option value="Approved">Approved</option>
<option value="Disapproved">Disapproved</option>
</select>
</label></td>
</tr>
<?php
}
?>
<tr class="pager_bg">
<td height="35"> </td>
<td> </td>
<td width="37%" align="right"><input name="done" type="button" id="done" value="Done" onclick="window.location='../coordinatorMenu.html'" /></td>
<td width="16%"><label>
<input name="approveAll" type="submit" id="approveAll" value="Approve All" />
</label></td>
<td><input name="apply" type="submit" id="apply" value="Apply To All" /></td>
</tr>
<?php
mysql_close();
?>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><label></label> <label></label></td>
</tr>
</table>
</form></td>
You're trying to reuse your MySQL connection while still holding on to the resultset from the first query. You need to create a second connection for the inner loop queries. Even better would probably be to rewrite your query using a join, but I can't say for sure without knowing your schema.
Related
Project code when changed , it will get the current selected pcode(Project code) id value and list the corresponding acode(Activity code) list in another select box(#acode) using ajax.
but when i try to list the value of particular value from mysql, pcode is listing and make if condition check with mysql record if match that pcode is select, but once change the pcode mysql acode instead of selecting acode it will list all acodes.
please help, what i wanna to do.
function check(t){
var id = t.id;
var val = t.options[t.selectedIndex].value;
$.ajax({
type: 'post',
url: 'code_verify.php',
data: {
project_code:val
},
success: function (response) {
document.getElementById("acode").innerHTML=response;
}
});
}
<p>My Database Name : timesheet</p>
<p>Table: projectcode</p>
<table width="250" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align="center">id</td>
<td align="center">project</td>
<td align="center">pcode</td>Pcode
</tr>
<tr>
<td align="center">1</td>
<td>Library Time</td>
<td align="center">LB</td>
</tr>
<tr>
<td align="center">2</td>
<td>Leave</td>
<td align="center">L</td>
</tr>
</table>
<p>Table: activitycode</p>
<table width="250" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align="center">id</td>
<td align="center">pcode</td>
<td align="center">activity</td>
<td align="center">acode</td>
Pcode </tr>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">Bench</td>
<td align="center">B</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">2</td>
<td align="center">Sick Leave</td>
<td align="center">Sl</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">2</td>
<td align="center">Causal Leave</td>
<td align="center">CL</td>
</tr>
<tr>
<td align="center">4</td>
<td align="center">2</td>
<td align="center">Loss of Pay</td>
<td align="center">LP</td>
</tr>
</table>
<p>Table: user_timesheet</p>
<table width="250" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align="center">id</td>
<td align="center">userid</td>
<td align="center">pcode</td>
<td align="center">acode</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">2</td>
</tr>
<tr>
<td align="center" bgcolor="#666666">3</td>
<td align="center" bgcolor="#666666">1</td>
<td align="center" bgcolor="#666666">2</td>
<td align="center" bgcolor="#666666">3</td>
</tr>
<tr>
<td align="center">4</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">4</td>
</tr>
</table>
<p></p>
<p> </p>
<p> </p>
<table width="250" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>
<select name="pcode_1" id="1" class="pcode" onChange="check(this);">
<?php
$sql=mysql_query("select * from user_timesheet where id=3");
while($row=mysql_fetch_array($sql)){
$leave=mysql_query("SELECT * FROM projectcode"); while($leave1=mysql_fetch_array($leave)) { ?>
<option value="<?=$leave1['id']?>" <?php if($leave1['id']==$row['pcode']){ echo "selected";}?>> <?=$leave1['pcode']?> </option>
<?php } } ?>
</select></td>
<td><select name="acode" id="acode"></select></td>
</tr>
</table>
<?php
$project_code = $_POST['project_code'];
$find=mysql_query("select * from activitycode where pcode=$project_code");
while($row=mysql_fetch_array($find))
{
echo "<option value='$row[id]'>".$row['acode']."</option>";
}
?>
<p> </p>
<p>i am trying to list the record as below query <br/><br/>
" select * from user_timesheet where id=3 " </p>
<p> </p>
<strong><u> Output: (currently coming)</u></strong><br/><br/>
//While change Project code , ajax(using project code ID) return all activity code corresponding to pcode from activitycode table,
<br/><br/>
Then list record with user_timesheet where id=3, need to select automatic corrponding ID, pcode and acode wanna to select.
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Project Code :
<select name="pcode_1" id="1" class="pcode" onChange="check(this);">
<option value="1">Library Time </option>
<option value="2" selected="selected">Leave</option>
</select></td>
<td>Activity Code:
<select name="acode" id="acode">
<option value="1">Sick Leave</option>
<option value="2">Causal Leave</option>
<option value="3">Loss of Pay</option>
</select></td>
</tr>
</table>
<br/><br/>
<strong><u> Expecting Output: </u></strong><br/><br/>
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Project Code :
<select name="pcode_1" id="1" onChange="check(this);">
<option value="1">Library Time </option>
<option value="2" selected="selected">Leave</option>
</select></td>
<td>
Activity Code:
<select name="acode" id="acode">
<option value="1">Sick Leave</option>
<option value="2" selected="selected">Causal Leave</option>
<option value="3">Loss of Pay</option>
</select></td>
</tr>
</table>
You must use value property
document.getElementById("acode").value = response;
Try this code:
$('acode').val(response);
currently im doing my final year project which is advising system for student. My problem is that admin cannot update a certain data of student. At my first try, it says that, admin done update student profile but when i check at the database it does not update at all. After that i change my code, it turns that the data is undefined variable and mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given.
(AdminUpdateStd.php)
<?php
include("db.php");
$StdId = $_GET['id'];
$sql="SELECT * from member where id='$StdId'";
$result=mysqli_query($db,$sql);
while($rows=mysqli_fetch_array($result)){
$student_id=$rows[0];
$student_name=$rows[3];
$student_email=$rows[5];
$student_address=$rows[4];
$student_tel=$rows[6];
$intake=$rows[7];
$total_cred=$rows[8];
$advisor=$rows[9];
}
?>
<form action ="AdminUpdateProcess.php" method="POST">
<div id="reg-head" class="headrg" align="center"><strong>Profile Student <?php echo "$StdId"; ?></strong></div>
<table width="350" height="200" border="1" align="center" cellpadding="2" cellspacing="0" bgcolor="#FFF">
<input type="hidden" name="student_id" value=" <?php echo "$student_id"; ?>">
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Full Name:</div></td>
<td class="tl-4"><?php echo "$student_name"; ?></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Email:</div></td>
<td class="tl-4"><?php echo "$student_email"; ?></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Adress:</div></td>
<td class="tl-4"><?php echo "$student_address"; ?></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Tel Number:</div></td>
<td class="tl-4"><?php echo "$student_tel"; ?></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Intake:</div></td>
<td class="tl-4"><input type="text" name="intake" <?php echo "$intake"; ?>></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Total Credit Hour:</div></td>
<td class="tl-4"><input type="text" name="total_credit" <?php echo "$total_cred"; ?>></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name">Advisor:</div></td>
<td class="tl-4"><input type="text" name="advisor_name" <?php echo "$advisor"; ?>></td>
</tr>
<tr id="lg-1">
<td class="tl-1"><div align="left" id="tb-name"> </div></td>
<td class="tl-4"><input type="submit" name="Update" <?php echo "value='UPDATE'"; ?>></a>
<button type="button">View Profile</button></td>
</tr>
</table>
</form>
(AdminUpdateProcess.php)
<?php
include("db.php");
$intake=$_POST['intake'];
$total_cred=$_POST['total_credit'];
$advisor=$_POST['advisor_name'];
$StdId = $_POST['student_id'];
if (isset ($_POST['Update'])) {
$UpdateQuery ="UPDATE member SET intake = '$intake', total_credit = '$total_cred', advisor_name = '$advisor' WHERE student_id ='$StdId'";
$res = mysqli_query ($UpdateQuery) or die ("Could not update".mysqli_error());
}
?>
I know there are questions similar, but I am unable to determine my issue with my PHP code. I am trying to remove a student from an intermediary table between Student table and Class table, called Student_has_Class. The SQL code works, just not the page. It lists the students in the table successfully, but when I check the box by a student to remove them and click submit, it redirects to same page (basically a refresh) like it is supposed to (even though it doesn't reload the table for some reason), and the student is still in the Student_has_Class table. Please help, as posting online is a last resort for me.
Please take a look a the code:
Note: I removed some login and web address info for privacy. Indicated with { }.
<?php
// Connects to your Database
session_start();
$x = $_SESSION['user'];
$y = $_GET['id'];
mysql_connect("{removed site for privacy}", "{username removed}", "{password removed}") or die(mysql_error
());
mysql_select_db("test") or die(mysql_error());
if (isset($_POST['delete']))
{
if (isset($_POST['checkbox']))
{
$checkbox = $_POST['checkbox'];
if (is_array($checkbox)) {
foreach ($checkbox as $key => $x)
{
$mysql->query("DELETE FROM Student_has_Class WHERE User_idUser='$x'");
}
}
}
}
?>
<?php
$sql = "SELECT User.idUser, User.UserFirstName, User.UserLastName
FROM Student_has_Class
INNER JOIN User ON User.idUser = Student_has_Class.User_idUser AND User.Role = 'Student'
INNER JOIN Class ON Class.idClass = Student_has_Class.Class_idClass
WHERE Student_has_Class.Class_idClass = 2 AND Class.User_idUser = ".$x."
ORDER BY User.UserLastName";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
?>
<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>Class Roster</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">Drop</td>
<td align="center" bgcolor="#FFFFFF"><strong>ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Last Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>First Name</strong></td>
</tr>
<?php
while ($rows = mysql_fetch_array($result))
{
?>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['idUser'];?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['idUser'];?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['UserLastName'];?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['UserFirstName'];?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Submit"></td>
</tr>
<?php
// Check if delete button active, start this
if ($_POST['delete'])
{
for ($i = 0; $i < $count; $i++)
{
$del_id = $checkbox[$i];
$sql = "DELETE FROM Student_has_Class WHERE User_idUser=".$del_id."";
$result = mysql_query($sql);
}
// if successful redirect to same page
if ($result)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL={address}/{page}.php\">";
}
}
mysql_close();
?>
Update:
I used Internet Explorer debugger to get some info that Chrome debugger doesn't provide. Here is the page, notice the values in the checkboxes. I'm not sure if that is correct.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>*HIDDEN*</title>
<style type="text/css">
body {
background-color: #D9D7D7;
}
h1 {
color: #FBF8F8;
}
</style>
<style>
table,th,td
{
border:1px solid black;
}
</style>
</head>
<body bgcolor="#D7D3D3">
<a href="main_login.php" >
<img src="banner2.jpg" width="1340" height="90">
</a></img>
<div id="shHeader">
<center>
<div class="div">
Welcome to *HIDDEN*!</div></center>
<table width ="1345" height="30" align="top" border=1">
<tr align= top>
<tr>
<td width="40"> Category </td>
<td width="40"> Homework Graph </td>
<td width="40"> Test Graph </td>
<td width="40"> Overview Graph </td>
<td width="40"> Progress Bar </td>
<td width="40"> Timeline </td>
</tr>
<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>Class Roster</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">Drop</td>
<td align="center" bgcolor="#FFFFFF"><strong>ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Last Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>First Name</strong></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name='checkbox[0]' type='checkbox' id='checkbox[]' value=''></td>
<td bgcolor="#FFFFFF">5</td>
<td bgcolor="#FFFFFF">*HIDDEN*</td>
<td bgcolor="#FFFFFF">*HIDDEN*</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name='checkbox[1]' type='checkbox' id='checkbox[]' value=''></td>
<td bgcolor="#FFFFFF">3</td>
<td bgcolor="#FFFFFF">*HIDDEN*</td>
<td bgcolor="#FFFFFF">*HIDDEN*</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name='checkbox[2]' type='checkbox' id='checkbox[]' value=''></td>
<td bgcolor="#FFFFFF">12</td>
<td bgcolor="#FFFFFF">*HIDDEN*</td>
<td bgcolor="#FFFFFF">*HIDDEN*</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name='checkbox[3]' type='checkbox' id='checkbox[]' value=''></td>
<td bgcolor="#FFFFFF">4</td>
<td bgcolor="#FFFFFF">*HIDDEN*</td>
<td bgcolor="#FFFFFF">*HIDDEN*</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name='checkbox[4]' type='checkbox' id='checkbox[]' value=''></td>
<td bgcolor="#FFFFFF">6</td>
<td bgcolor="#FFFFFF">*HIDDEN*</td>
<td bgcolor="#FFFFFF">*HIDDEN*</td>
</tr>
<input type='hidden' name='hiddencounter' value='5'>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Update:
The POST parameters are as follows when I try to delete the third person in the table by checking the checkbox to the left of their name, and clicking the Delete button (previously called Submit button). The person to delete has a User ID of 12.
Array ( [checkbox] => Array ( [2] => ) [hiddencounter] => 5 [delete] => Delete )
You can try this. But I will change your code from MySQL to MySQLi.
<?php
// Connects to your Database
session_start();
$x = $_SESSION['user'];
$y = $_GET['id'];
/* ESTABLISH CONNECTION */
$connect=mysqli_connect("YourHost","YourUsername","YourPassword","YourDatabaseName"); /* REPLACE THE NECESSARY HOST, USERNAME, PASSWORD, AND DATABASE */
if(mysqli_connect_errno()){
echo "Error".mysqli_connect_error();
}
if (isset($_POST['delete'])){ /* IF DELETE IS SET/CLICKED */
$counter=mysqli_real_escape_string($connect,$_POST['hiddencounter']);
$checkbox=$_POST['checkbox'];
for($x=0;$x<=$counter;$x++){
if(!empty($checkbox[$x])){ /* IF SELECTED ITEM */
$checked=mysqli_real_escape_string($connect,$checkbox[$x]);
mysqli_query($connect,"DELETE FROM Student_has_Class WHERE User_idUser='$checked'");
} /* END OF IF NOT EMPTY CHECKBOX SELECTED */
} /* END OF FOR LOOP */
} /* END OF ISSET DELETE */
?>
<?php
$sql = "SELECT User.idUser, User.UserFirstName, User.UserLastName
FROM Student_has_Class
INNER JOIN User ON User.idUser = Student_has_Class.User_idUser AND User.Role = 'Student'
INNER JOIN Class ON Class.idClass = Student_has_Class.Class_idClass
WHERE Student_has_Class.Class_idClass = 2 AND Class.User_idUser = ".$x."
ORDER BY User.UserLastName";
$result = mysqli_query($connect,$sql);
$count = mysqli_num_rows($result);
?>
<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>Class Roster</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">Drop</td>
<td align="center" bgcolor="#FFFFFF"><strong>ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Last Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>First Name</strong></td>
</tr>
<?php
$counter=0; /* FOR COUNTING PURPOSES */
while ($rows = mysqli_fetch_array($result))
{
?>
<tr>
<td align="center" bgcolor="#FFFFFF">
<?php
$iduser=$rows['idUser'];
echo "<input name='checkbox[$counter]' type='checkbox' id='checkbox[]' value='$iduser'></td>";
/* I HAVE ASSIGNED THE COUNTER INSIDE THE CHECKBOX ARRAY ABOVE. AND DO YOU REALLY NEED [] IN YOUR ID? */ ?>
<td bgcolor="#FFFFFF"><?php echo $rows['idUser'];?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['UserLastName'];?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['UserFirstName'];?></td>
</tr>
<?php
$counter=$counter+1; /* INCREMENT COUNTER EVERY LOOP */
} /* END OF WHILE LOOP */
echo "<input type='hidden' name='hiddencounter' value='$counter'>"; /* SUBMIT A HIDDEN INPUT CONTAINING THE OVERALL COUNTER */
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Submit"></td>
</tr>
</table>
</form>
I am trying to create a html table showing results from php sql query. it is a result page of students php code is as under
$r1=$_GET["r"];
$con=mysqli_connect(localhost,chumspai_tlss,Tls121,chumspai_tlsResult);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM nursery_blue_ WHERE sr_='$r1'");
while($row = mysqli_fetch_array($result))
{
html code is
<pre>
<form name="frmResult" id="frmResult" action="" method="post" onsubmit="return checkEmpty();">
<table width="80%" cellpadding="5" cellspacing="5" border="0">
<tr>
<td class="heading noborder">Enter Your Roll Number:</td>
<td class="noborder"><input type="text" id="r" name="r" value="" /></td>
</tr>
<tr>
<!--
<td class="heading noborder">Enter Your Name:</td>
<td class="noborder"><input type="text" id="name" name="name" value="" /></td>
</tr>
<tr>
<td class="heading noborder">Search by</td>
<td class="noborder"><input type="radio" id="option" name="option" value="rno" checked="checked" />
Roll No
<input type="radio" id="option" name="option" value="name" />
Name </td>
</tr>
-->
<tr>
<td class="noborder"> </td>
<td class="noborder"><input type="submit" name="submit" value="Search" />
<input type="reset" name="reset" value="Clear" />
</td>
</tr>
<!--<tr>
<td colspan="2"> <embed src="images/wait.swf"></embed></td>
</tr> -->
</table>
</form>
<div style="border:1px solid #000000;">
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr>
<td class="heading grey" width="30%">RNO</td>
<td><?php
Print $row['sr_'];
?>
</td>
</tr>
<tr>
<td class="heading grey">NAME</td>
<td class="shade"></td>
</tr>
<tr>
<td class="heading grey">FATHER</td>
<td></td>
</tr>
<tr>
<td class="heading grey">regno</td>
<td></td>
</tr>
</table>
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr class="grey">
<td rowspan="2" class="heading">Sr.no </td>
<td rowspan="2" class="heading">Name of subject </td>
<td rowspan="2" class="heading">Maximum Marks</td>
<td colspan="7" class="heading">detail of marks Obtained</td>
<tr class="grey">
<td class="heading">PART ONE</td>
<td class="heading">Total</td>
</tr>
<tr>
<td>1</td>
<td>Urdu</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>2</td>
<td>English</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>Islamyat</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>4</td>
<td>pakstudies</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>6</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr>
<td>7</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="shade">
<td>8</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="shade">
<td>9</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="grey">
<td colspan="2" class="heading">TOTAL</td>
<td class="heading">1100</td>
<td colspan="4" class="heading"></td>
</tr>
<tr class="grey">
<td colspan="3" class="heading">NOTIFICATION</td>
<td class="heading"></td>
<td class="heading"></td>
<td colspan="2" class="heading"></td>
</tr>
<tr>
<td colspan="7">(i) This provisional result intimation is issued as a notice only. Errors and omissions are excepted.</td>
</tr>
</table>
</pre>
please help me how to embed this php query with this html table and html form also.
you are not so far.
The variable $row is an array containing your data. Try this to see it's structure in your while call:
print_r($row);
Using this command you will see the name of each item of your array. Note it somewhere. Then you can do something like this:
...<td><?php echo $row['desired_column_name']; ?></td>...
If you receive data from your mysql query, this should do the trick.
Hope it helps,
Paul
Try This :
$result = mysql_query("select * from emp");
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td id=SrNo$cnt >".$row['eno']."</td>";
echo "<td id=ItemId$cnt >".$row['eId']."</td>";
echo "<td>". "<button name='Update' id='update' onclick='show(".$cnt.")'>UPDATE</button>"."</td>";
echo "<td>". "<button name='Report' id='show' onclick='Report(".$row['SrNo'].")'>REPORT</button>"."</td>";
echo "</tr>";
echo "<div id=show$cnt>";
echo "</div>";
$cnt++;
}
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.