I can't really see what's exactly wrong with your code, it might happen that some of the columns on the parta
table are not supposed to be null. With the code you provided, it's hard to tell, as there's no error handling at all. You might want to use transactions, then use proper error handling and also use prepared statements.
Try with this code that I have prepared for you.
<?php
$con = new mysqli("..."); // you should know this part already
$success = false;
try {
$con->autocommit(FALSE);
$con->begin_transaction();
if ($sql = $con->prepare("INSERT INTO socio (name, age, dob, gender, year, stgroup, stadd) VALUES (?,?,?,?,?,?,?)")) {
$sql->bind_param('sissss', $stnam, $stage, $stdob, $stgen, $styer, $stGr, $stadd);
if (!$sql->execute()) {
throw new Exception($sql->error);
}
if ($sql_two = $con->prepare("INSERT INTO parta (name, stgroup, year) VALUES (?,?,?)")) {
$sql_two->bind_param('sss', $stnam, $stGr, $styer);
if (!$sql_two->execute()) {
throw new Exception($sql_two->error);
}
}
}
if ($con->commit()) {
$success = true;
} else {
throw new Exception('Transaction commit failed...');
}
}catch (Exception $ex) {
try {
// something went wrong,rollback and display message
$con->rollback();
echo $ex->getMessage();
}
catch (Exception $e) {
echo $e->getMessage();
}
}
$con->autocommit(TRUE);
if ($success) {
echo "data successfully inserted";
}
?>