Jump to content
Sign in to follow this  
khan.sikki

Inserting fetched multiple rows into table

Recommended Posts

Hello I am Sikandar 

need assistance in inserting multiple data  which was fetched from a recordset in a table


$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add_trips")) {
  $insertSQL = sprintf("INSERT INTO trips (trip_date, trip_no, hab_id) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['trip_date'], "date"),
                       GetSQLValueString($_POST['trip_no'], "int"),
                       GetSQLValueString($_POST['hab_id'], "int"));

  mysql_select_db($database_conn_db, $conn_db);
  $Result1 = mysql_query($insertSQL, $conn_db) or die(mysql_error());

  $insertGoTo = "u_home.php?trip=t";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

 

Edited by khan.sikki

Share this post


Link to post
Share on other sites

What happens when you run that?  What exactly are you having problems with?

Share this post


Link to post
Share on other sites

what i am asking is a inserting multiple values of looped table,

above is is just inserting the last value of looped table 

Share this post


Link to post
Share on other sites

There's not enough code there to suggest much.  What does the form look like?  What data is sent in $_POST?

Share this post


Link to post
Share on other sites

i solved it bro thank you here is the code 

<?php
			if(isset($_POST['submit'])){
				// insert attendence to database
				$q= "INSERT INTO attendence(date,school_id,class,period,teacher,student_id,status) VALUES";
				//creating arrary to receview multiple rows values
				for ($a=1;$a<=$totalRows_students;$a++){
					//assigning multiple values to inset into values
					$q .="('".$_GET['date']."','".$_GET['school']."','".$_GET['class']."','".$_POST['period']."','".$_POST['teacher']."','".$_POST['student_id'][$a]."','".$_POST['status'][$a]."'),";
				}
				//removing "," from statement 
				$q=rtrim($q,",");
				mysql_select_db($database_localhost, $localhost);
				mysql_query($q, $localhost) or die(mysql_error());
				// displaying result
				echo '<p align ="center"class="alert">'.strtoupper($row_teachers['name']).' గారు మీరు వేసిన హాజరు జతచేతయబడినది ఫోటో జియోట్యగ్ ప్రక్రియను పూర్తి చేయండి</p>';
			}
			?>

 

Share this post


Link to post
Share on other sites

There's not enough information to help you.  You have a for loop there where you keep inserting the same thing, but I don't know what data is being submitted to the page.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...