Webmaster Malaysia Forum  


Go Back   Webmaster Malaysia Forum > Website Design & Development > Website Programming

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Tolong saya!!(Cam ne nak insert multiple record in sql)
Old
  (#1 (permalink))
New kid on the block
emnieysh is on a distinguished road
 
Status: Offline
Posts: 6
Join Date: Mar 2008
Location: P.jaya
Rep Power: 0
Tolong saya!!(Cam ne nak insert multiple record in sql) - 08-03-2008, 04:32 AM

saya bt pasal coursework system..
then cam lecturer nak add maks sekali byk ye..
saya dah try tapi data just insert yg last row je..
plz tolong..saya guna oop pakai language php...
saya pastekan skali coding ye..

quiz1table.php (yg ni saya retrievekan bape ramai student dr db)
Code:
<?php


///////////////////////////   DRAWTABLE FUNCTION START      ////////////////////////////

function drawquiz1table() {
	$db = new MySQL (HOST, USER, PASS, DATABASE);
	/*  $sqlview = $db->query('select * from studydetails where lecturerID="'.$_COOKIE['user'].'" order by studentID');     */
	 /*   $sqlview = $db->query('select attendance.name,studydetails.id,studydetails.studentName,studydetails.studentID,studydetails.courseID 
							from attendance, studydetails
							where attendance.courseID ="'.$_GET['courseID'].'"
							and studydetails.courseID ="'.$_GET['courseID'].'" 
							and studydetails.lecturerID="'.$_COOKIE['user'].'" order by studentID');   */
	 $sqlview = $db->query ('select attendance.name,attendance.att_id,attendance.percentage,studydetails.studentName,studydetails.studentID,studydetails.courseID,
	                         studydetails.id
							from attendance, studydetails
							where attendance.att_id =  "'.$_GET['att_id'].'"
							and studydetails.courseID ="'.$_GET['courseID'].'" 
							and studydetails.lecturerID="'.$_COOKIE['user'].'" order by studentID'); 
							
	
	$i=1;
?>
	<table border="3" cellspacing="0" cellpadding="5">
	<tr>
	<td class="header" bgcolor="#999999"><font color="#333333"><strong>Current Assesment : <?php echo $_GET["attname"]; ?></strong></font></td>
	</tr>
	</table>
	<?php	
	if($sqlview->size() != 0) {
	
		?>
		
		<table width="" border="0">
				<tr>
					<td class="filetitle" width="41"><center>No</center></td>
					<td class="filetitle" width="113"><center>StudentID</center></td>
					<td class="filetitle" width="200"><center>Name</center></td>
					<td class="filetitle" width="200"><center>courseID</center></td>
					<td class="filetitle" width="200"><center>Marks</center></td>
					
				</tr>
				
		<?php
		while($view = $sqlview->fetch()) {
		
			?>
			
			<form name="insert_marks" action="addmarks2.php?attname=<?php echo $_GET["attname"]; ?>&att_id=<?php echo $_GET['att_id']; ?>&percentage=<?php echo $_GET['percentage']; ?>" method="post">
			<tr>
			<td class="filelist" valign="middle">
			<center><input name="noid" type="text" value="<?php echo $i;  ?>" size="2"></center>
				<center><?php /* echo $i; */ ?></center>
				
			</td>
			<td class="filelist" valign="middle">
			<center><input name="studentID" type="text" value="<?php echo $view['studentID']; ?>" size="5"></center>
				
			</td>
			<td class="filelist" valign="middle">
			<center><input name="studentName" type="text" value="<?php echo $view['studentName']; ?>" size="20"></center>
				<center><?php /* echo $view['studentName'];  */?></center>
			</td>
			<td class="filelist" valign="middle">
			<center><input name="courseID" type="text" value="<?php echo $view['courseID']; ?>" size="5"></center>
				<center><?php /* echo $view['courseID'];  */?></center>
			</td>
			
			<td class="filelist" valign="middle">
			
			<center>
			<input name="txt_marks" type="text" value="" size="3" maxlength="3">
			<input name="id" type="hidden"  value="<?php echo $view['id']; ?>"/>
			 <input name="att_id" type="hidden"  value="<?php echo $_GET["att_id"]; ?>"/>
	  
            </center>
			</td>
			</tr>
           <?php
			 $i++; 
		} 
		?>
		<tr>
            
			 <input name="att_id" type="hidden"  value="<?php echo $_GET["att_id"]; ?>"/>
	    <td class="filelist" colspan="5"  align="right"> <input type="submit" name="btn_addmarks" value="addmarks">
		   </td>
	</tr>
	  </form>
</table>
      
         
		<?php	
}
	else { 
		echo "No student found<br><br>";
		?>
		
		<?php	
	}
}
	

?>


yang bawah ni page dmana insert mark d process..

addmarks2.php

<?php	
if(isset($_COOKIE['user'])) {
	include('core/config.php');
	include('lib/MySQL.php');
	
	include('cu.php');
	include('drawquiz1table.php');
	
	$db = new MySQL (HOST, USER, PASS, DATABASE);
?>
<?php include('template/header.html'); ?>
<link href="style/css_table.css" rel="stylesheet" type="text/css" />


  <div id="nav">
  	<center>
			<?php include('menu_sign.php'); ?>
		</center>
	  </div>
	  <div id="body">
	  <?php
			echo '<b>Welcome';
			if (isset($_COOKIE['firstname'])) {
			echo " : {$_COOKIE['firstname']}!";
			}
			echo '</b>';
			?>
		<div id="bodysign-left">
		<br>
		<?php
			
			 include('ass_menu.php'); 
			?>
		</div>
		<div id="bodysign-center">
		<br>
		
		
	
		<?php 
		
		  
				if(!isset($_POST['btn_addmarks'])) {
				$db = new MySQL('localhost','root','','scms1');
                  $duplicate=0;
				  
               
					 drawquiz1table(); 
				}
				elseif(isset($_POST['btn_addmarks']) and $_POST['att_id'] != "") {
				
			    /* $select_file = $db->query('select * from marks where courseID="'.$_POST['courseID'].'" and att_id="'.$_POST['att_id'].'"'); */
				$select_file = $db->query('select * from marks where studentID="'.$_POST['studentID'].'" and att_id="'.$_POST['att_id'].'"');
			    $salted='unable';
				while($list_file = $select_file->fetch()) {
					/* if($list_file['att_id']['courseID'] == addslashes($_POST['att_id']['courseID']  )) { */
					if($list_file['att_id']['studentID'] == addslashes($_POST['att_id']['studentID']  )) {
					$duplicate = 1;
					print_r($size_array);
					
					?>
					<meta HTTP-EQUIV="Refresh" CONTENT="1; URL=view_marks.php?courseID=<?php echo  $_POST['courseID']; ?>">
					<?php
					
					}			
					
					echo  "<center><font color=\"#CC0000\">Assesment already exist<br></font></center>";
					
				}
				if ($duplicate != 1) { 
				/* $select_file2 = $db->query('select * from studydetails where id="'.$_POST['id'].'"');
			  
				while($list_file2 = $select_file2->fetch()) { */
				 
					$insertcat = $db->query('insert into marks set
											    att_id="'.$_POST['att_id'].'",
												id="'.$_POST['noid'].'",
												lecturerID="'.$_COOKIE['user'].'",
												studentID="'.$_POST['studentID'].'",
												studentName="'.$_POST['studentName'].'",
												courseID="'.$_POST['courseID'].'",
												marks="'.$_POST['txt_marks'].'",
												name="'.$_GET['attname'].'"');
												print_r($list_file);
												 } 
												
					?>
					
					<meta HTTP-EQUIV="Refresh" CONTENT="1; URL=list5.php?attname=<?php echo $_GET['attname']; ?>&courseID=<?php echo $_POST['courseID']; ?>&percentage=<?php echo $_GET['percentage']; ?>">
					
					<center>
					Marks Added.
					</center>
					
					<?php	
					/* 
				} */
					
				?>
			</center>
		
		
			
			<br>
		</div>
		<div id="bodysign-right">
		
		</div>
		<div class="clear"></div>
	  </div>
	  <?php include('template/footer.html'); ?>
	   
	</body>
	</html>
	<?php

}

else {
	?>
	<font size="+1">Page expired. Please <a href="index.php">sign in</a> again.</font>
	<?php
 }
}


	?>
hope ada yg bole tolong saya..

Last edited by wingwp : 28-03-2008 at 02:42 AM.
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#2 (permalink))
Novice Webmaster
Monie is on a distinguished road
 
Status: Offline
Posts: 46
Join Date: Mar 2008
Location: Sabah
Rep Power: 0
22-03-2008, 03:49 AM

So did you solved them? I'll take a look later what seems to be the problem
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
nope..
Old
  (#3 (permalink))
New kid on the block
emnieysh is on a distinguished road
 
Status: Offline
Posts: 6
Join Date: Mar 2008
Location: P.jaya
Rep Power: 0
Unhappy nope.. - 23-03-2008, 12:08 AM

i couldn't fine the solution..
i need to confirm 4 my presentation next week..
act this is 4 my final project in UNITEN.
hope sumbody will help me..plz!!!
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#4 (permalink))
Novice Webmaster
Monie is on a distinguished road
 
Status: Offline
Posts: 46
Join Date: Mar 2008
Location: Sabah
Rep Power: 0
23-03-2008, 03:53 PM

UNITEN??? Wow it's all comming back to me now LOL
I was in UNITEN as well taking my BIT course Graduated in 2005!
What course did you took? I really missed all my lecturer back there, Siva Kumar, Alicia, does Zaliman still there??? How's the new IT building?

Ok back on track!
I can help you but I need some more detail information on your problem!
I mean be specific..


So much to learn.. So little time!
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#5 (permalink))
New kid on the block
emnieysh is on a distinguished road
 
Status: Offline
Posts: 6
Join Date: Mar 2008
Location: P.jaya
Rep Power: 0
24-03-2008, 03:44 AM

really..me taking BIT also but major in IS.
yup all those lecturers are still there..hehe
the new building was ok n superb..It kind like winter in there..hehe really cold..

the system dat i've create is about coursework management system..
it's all about lecturer key in marks for ur coursework..
wut i've done, once lecture login, the system will list out the subject dat user teached..
when user click on the courseID listed,system will linked user to the coursework list page..here user will add any coursework provide by the system and store in databse..
then, system will retrieved list of student dat took dat subject..so here i add all the marks..but then if the system list out couple numbers of student and i add marks 4 both,later only the last(row) student marks was inserted in db..how can i insert marks 4 both student?? i duno weather my query error or array problem..i'm lost..huhu

erm,am i answer ur quest??
i'm not really good in explanation =)
really need sum help here..huhu
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#6 (permalink))
New kid on the block
orgbaru is on a distinguished road
 
Status: Offline
Posts: 1
Join Date: Apr 2008
Location: kl
Rep Power: 0
04-04-2008, 11:44 AM

maybe u can use foreach...
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#7 (permalink))
Novice Webmaster
Monie is on a distinguished road
 
Status: Offline
Posts: 46
Join Date: Mar 2008
Location: Sabah
Rep Power: 0
05-04-2008, 04:37 PM

I need some more explaination with this:
Quote:
later only the last(row) student marks was inserted in db


So much to learn.. So little time!
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#8 (permalink))
New kid on the block
emnieysh is on a distinguished road
 
Status: Offline
Posts: 6
Join Date: Mar 2008
Location: P.jaya
Rep Power: 0
06-04-2008, 12:36 AM

for example :

i have 2 student

Hasanah TT074921 5(marks)
Syakirah TT074318 4(marks)

*marks was a textbox fill..went i insert mark n submit it,
only Syakirah TT074318 4 was insert into db..so how should i do to insert HASANAH n SYAKIRAH record in db..
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#9 (permalink))
Novice Webmaster
Monie is on a distinguished road
 
Status: Offline
Posts: 46
Join Date: Mar 2008
Location: Sabah
Rep Power: 0
07-04-2008, 12:49 PM

Can I see your SQL statement on this as well as your database table?
Shouldn't you enter them (mark) one at a time?

I think I know what is the problem here..
Cheers..


So much to learn.. So little time!
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#10 (permalink))
New kid on the block
emnieysh is on a distinguished road
 
Status: Offline
Posts: 6
Join Date: Mar 2008
Location: P.jaya
Rep Power: 0
08-04-2008, 01:47 AM

if i enter them(mark) one by one, my system will be inefficient..
can u imagine if i have 30 student n i need to enter one at time..
hehe .

the thing is when the system display records of student (mean i have an array value here) then i post this value to another page n here where the sql statement involve..

here is the sql statement :

$insert = $db->query('insert into marks set
att_id="'.$_POST ['att_id'].'",
lecturerID="'.$_COOKIE['user'].'",
studentID="'.$_POST['studentID'].'",
studentName="'.$_POST['studentName'].'",
courseID="'.$_POST['courseID'].'",
marks="'.$_POST['txt_marks'].'",
name="'.$_GET['attname'].'"');

erm my presentation was on 17 april and panel Aliza(chief),zailani n siva..
huhu..
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#11 (permalink))
Inspired Webmaster
alfirus is on a distinguished road
 
Status: Offline
Posts: 152
Join Date: Oct 2005
Location: Malaysia
Rep Power: 36
08-04-2008, 01:09 PM

Masa makin suntuk. Nak saye selesaikan? YM saya di alfirus3000 atau admin a myetribes.com
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old
  (#12 (permalink))
Novice Webmaster
afroman is on a distinguished road
 
Status: Offline
Posts: 89
Join Date: Oct 2005
Location: KLC
Rep Power: 35