Saving more than one record entry with confirmation & saving data on a multiple table
The purpose of this code is to save record on studentinfo and studentlist table in your MySql database in one click of your add entry.
code to paste:
<?php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sample", $con);
$search=$_POST['studentno'];
$result = mysql_query("SELECT * FROM studentinfo where studentno='$search'");
$count=mysql_num_rows($result);
if ($count==1)
{
echo "student number already exist";
}
else
{
$sql="INSERT INTO studentinfo (studentno, lastname, firstname, mi, age, sex, status, address, schoolyear, semmester)
VALUES
('$_POST[studentno]','$_POST[lastname]','$_POST[firstname]','$_POST[mi]','$_POST[age]','$_POST[sex]','$_POST[status]','$_POST[address]','
$_POST[schoolyear]','$_POST[semmester]')";
$result = mysql_query( $sql,$con );
$sql="INSERT INTO studentlist (studentno, lastname, firstname, address)
VALUES
('$_POST[studentno]','$_POST[lastname]','$_POST[firstname]','$_POST[address]')";
$result = mysql_query( $sql,$con );
//Note: you can use = $result = mysql_query( $sql,$con ); see above
////////////////////////////////////////////
//Note: //Note: This can be omitted for your saving confirmation standard
////////////////////////////////////////////
//if (!mysql_query($sql,$con))
//{
//die('Error: ' . mysql_error());
//}
echo "1 record added";
}
mysql_close($con)
?>
No comments:
Post a Comment