1 Replies - 2801 Views - Last Post: 15 July 2009 - 08:17 AM Rate Topic: -----

#1 vasanth1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-July 09

how to insert the data into database using php

Post icon  Posted 15 July 2009 - 01:10 AM

<?php

	include('config.inc');
	
	if (isset($_GET['message'])) {
		$message = $_GET['message'];
	}
	
	// Get the list of students from database

	$sel_student = "SELECT *,(subject1+subject2+subject3) total,((subject1+subject2+subject3)/300)*100  Aggrigate FROM student";
	
	$stu_rs = mysql_query($sel_student) or die(mysql_error());
	
	$no_of_rows = mysql_num_rows($stu_rs);

	$data = array();

	while ($row = mysql_fetch_array($stu_rs, MYSQL_ASSOC)) {
		$data[] = $row;
	}
 //  if(empty($_POST['name'])){

	   //$error_message1 = " please fill the name";


?>

 <head>
 <title>www.student.com</title>
</head>   
<body>

<?php
	if (isset($message)) {
		echo '<center>' . $message . '</center>';
	}
?>

	<h1>Student's Detais</h1>
	<hr color="#330066">

	<TABLE border="1" width="700">
		<TR bgcolor="#AEAEAE">
			<TH>Id</TH>
			<TH>Name</TH>
			<TH>subject1</TH>
			<TH>subject2</TH>
			<TH>subject3</TH>
			<TH>total</TH>
			<TH>Aggrigate</TH>
			<TH>Actions</TH>
		</TR>

<?php
	
	if (count($data) > 0) {
	
		foreach ($data as $eachstudent) {
?>
		<TR>
			<TD><?php echo $eachstudent['id'];?></TD>
			<TD><?php echo $eachstudent['name'];?></TD>
			<TD><?php echo $eachstudent['subject1'];?></TD>
			<TD><?php echo $eachstudent['subject2'];?></TD>
			<TD><?php echo $eachstudent['subject3'];?></TD>
			<TD><?php echo $eachstudent['total'];?></TD>
			<TD><?php echo $eachstudent['Aggrigate'];?></TD>
			<TD><a href="studentedit.php?id=<?php echo $eachemp['id'];?>">edit</a> | <a href="studentdelete.php?id=<?php echo $eachemp['id'];?>">Delete</a></TD>
		</TR>
<?php
		}
	}
	else {
?>
		<TR>
			<TD align="center" colspan="5"><font color=red>No Record Found</font></TD>
		</TR>
<?php
	}
?>
  <?php
   /*if(isset(Aggrigate)>70){
	  // $grade='A';
  // }
   else if(Aggrigate > 60 and Aggrigate < 70){
		$grade='B';
   }
   else{
	   $grade='C';
   }*/

  ?>
	</TABLE>

	<a href="studentinsert.php">add new student</a>

</body>
</html>



in this code i can insert the data if i can possible to insert the data into total,aggrigate feilds please give reply to me

** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: how to insert the data into database using php

#2 KuroTsuto   User is offline

  • D.I.C Head
  • member icon

Reputation: 42
  • View blog
  • Posts: 182
  • Joined: 13-February 09

Re: how to insert the data into database using php

Posted 15 July 2009 - 08:17 AM

Not trying to be rude.... But I don't quite understand what your question is. If you're asking how you would go about inserting a new student into the database, you should get all of the required information from a form, then insert into the database with the mysql_query() function, like so:

$sql = "INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3)";
mysql_query($sql);



where table_name is replaced with the name of the table that you would like to insert he data into, the column1, column2, etc represent the columns that the corresponding value1, value2 etc will fill for the new row. An example might be

$name = $_POST['name'];
$subject1 = $_POST['subject1'];
$subject2 = $_POST['subject2'];
$subject3 = $_POST['subject3'];
$total = $_POST['total'];
$aggregate = $_POST['aggregate'];

$sql = "INSERT INTO students VALUES ($name, $subject1, $subject2, $subject3, $total, $aggregate)";
mysql_query($sql);



This example assumes a few things. The first is that the table is structured so that the 'ID' column is an auto-incremented integer. It also assumes that the table is structured with the columns in the order of name, subject1, subject2, subject3, total, aggregate; allowing us to omit the column definitions in the query (see here for more information). I'm also assuming that the 'total' and 'aggregate' variables were user-defined in a field.

All that aside, I think you get the idea.
Was This Post Helpful? 1

Page 1 of 1