Results 1 to 12 of 12

Thread: Tolong saya!!(Cam ne nak insert multiple record in sql)

  1. #1
    Join Date
    Mar 2008
    Location
    P.jaya
    Posts
    6
    Rep Power
    0

    Tolong saya!!(Cam ne nak insert multiple record in sql)

    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.

  2. #2
    Join Date
    Mar 2008
    Location
    Sabah
    Posts
    51
    Rep Power
    136
    So did you solved them? I'll take a look later what seems to be the problem

  3. #3
    Join Date
    Mar 2008
    Location
    P.jaya
    Posts
    6
    Rep Power
    0

    Unhappy nope..

    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!!!

  4. #4
    Join Date
    Mar 2008
    Location
    Sabah
    Posts
    51
    Rep Power
    136
    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!

  5. #5
    Join Date
    Mar 2008
    Location
    P.jaya
    Posts
    6
    Rep Power
    0
    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

  6. #6
    Join Date
    Apr 2008
    Location
    kl
    Posts
    1
    Rep Power
    0
    maybe u can use foreach...

  7. #7
    Join Date
    Mar 2008
    Location
    Sabah
    Posts
    51
    Rep Power
    136
    I need some more explaination with this:
    later only the last(row) student marks was inserted in db
    So much to learn.. So little time!

  8. #8
    Join Date
    Mar 2008
    Location
    P.jaya
    Posts
    6
    Rep Power
    0
    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..

  9. #9
    Join Date
    Mar 2008
    Location
    Sabah
    Posts
    51
    Rep Power
    136
    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!

  10. #10
    Join Date
    Mar 2008
    Location
    P.jaya
    Posts
    6
    Rep Power
    0
    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..

  11. #11
    Join Date
    Oct 2005
    Location
    Malaysia
    Posts
    158
    Rep Power
    167
    Masa makin suntuk. Nak saye selesaikan? YM saya di alfirus3000 atau admin a myetribes.com

  12. #12
    Join Date
    Oct 2005
    Location
    KLC
    Posts
    91
    Rep Power
    165
    Quote Originally Posted by emnieysh View Post
    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..
    a few methods can be used. but easiest is to use array.
    Code:
    <input type="text" name="student[1]"...
    <input type="text" name="mark[1]"...
    
    <input type="text" name="student[2]"...
    <input type="text" name="mark[2]"...
    in the action script..

    Code:
    $student = $_POST['student'];
    
    foreach ($_POST['mark'] AS $i => $v) {
    
        mysql_query("INSERT INTO table VALUES ('%s', %d)", $student[$i],  $v);
    }
    btw, fine=elok/baik, find=jumpa/cari...
    klaatu barada nikto

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Y tak bole access my thread previously...(insert multiple row)
    By emnieysh in forum Website Programming
    Replies: 1
    Last Post: 10-04-2008, 10:30 AM
  2. insert data into multiple table
    By azmaliya in forum Website Programming
    Replies: 18
    Last Post: 06-08-2005, 11:02 AM
  3. XML : macam mana nak insert new record?
    By therion in forum Website Design
    Replies: 21
    Last Post: 23-04-2005, 09:20 AM
  4. insert multiple data
    By vash in forum Website Programming
    Replies: 4
    Last Post: 28-04-2004, 02:48 PM
  5. Tolong saya leh...
    By nisha in forum Website Design
    Replies: 1
    Last Post: 16-09-2003, 12:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37